Skip to content

Commit

Permalink
Merge pull request #12 from BrianPugh/cli
Browse files Browse the repository at this point in the history
AuthenticationError, fix folder creation in sync
  • Loading branch information
BrianPugh authored Aug 16, 2022
2 parents a0d69e1 + bf9580e commit 7b663c1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions belay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
__version__ = "0.0.0"

__all__ = [
"AuthenticationError",
"minify",
"Device",
"SpecialFunctionNameError",
"PyboardException",
]
from ._minify import minify
from .device import Device, SpecialFunctionNameError
from .exceptions import AuthenticationError
from .pyboard import PyboardException
1 change: 1 addition & 0 deletions belay/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ def sync(
src_files.append(src_object)
dst_files = [f"/{src.relative_to(folder)}" for src in src_files]
dst_dirs = [f"/{src.relative_to(folder)}" for src in src_dirs]
dst_dirs.sort()
keep = [x for x in keep if x not in dst_files]
if dst_files + keep:
self(f"for x in {repr(dst_files + keep)}:\n all_files.discard(x)")
Expand Down
2 changes: 2 additions & 0 deletions belay/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class AuthenticationError(Exception):
"""Invalid password or similar."""
2 changes: 1 addition & 1 deletion belay/snippets/sync_begin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __belay_hfs(fns):
def __belay_mkdirs(fns):
for fn in fns:
try:
os.mkdir('%s')
os.mkdir(fn)
except OSError as e:
if e.errno != errno.EEXIST:
raise
Expand Down
10 changes: 7 additions & 3 deletions belay/webrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
THE SOFTWARE.
"""
import errno
import os
import socket
import struct
import sys
from collections import deque
from pathlib import Path

from .exceptions import AuthenticationError

# Treat this remote directory as a root for file transfers
SANDBOX = ""
# SANDBOX = "/tmp/webrepl/"
Expand Down Expand Up @@ -293,8 +294,11 @@ def __init__(self, uri, password, read_timeout=None):
self.ws = Websocket(self.s)

login(self.ws, password)
if self.read(1024) != b"\r\nWebREPL connected\r\n>>> ":
raise WebreplError
response = self.read(1024)
if response == b"\r\nAccess denied\r\n":
raise AuthenticationError(f"Incorrect password: {repr(password)}")
elif response != b"\r\nWebREPL connected\r\n>>> ":
raise WebreplError(f"Unknown login response: {response}")

def close(self):
if self.s is not None:
Expand Down

0 comments on commit 7b663c1

Please sign in to comment.