diff --git a/belay/__init__.py b/belay/__init__.py index 509eb2e..4b56d2a 100644 --- a/belay/__init__.py +++ b/belay/__init__.py @@ -2,6 +2,7 @@ __version__ = "0.0.0" __all__ = [ + "AuthenticationError", "minify", "Device", "SpecialFunctionNameError", @@ -9,4 +10,5 @@ ] from ._minify import minify from .device import Device, SpecialFunctionNameError +from .exceptions import AuthenticationError from .pyboard import PyboardException diff --git a/belay/device.py b/belay/device.py index 64ce470..ad6095a 100644 --- a/belay/device.py +++ b/belay/device.py @@ -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)") diff --git a/belay/exceptions.py b/belay/exceptions.py new file mode 100644 index 0000000..e75af73 --- /dev/null +++ b/belay/exceptions.py @@ -0,0 +1,2 @@ +class AuthenticationError(Exception): + """Invalid password or similar.""" diff --git a/belay/snippets/sync_begin.py b/belay/snippets/sync_begin.py index 93a64ff..44e4bcc 100644 --- a/belay/snippets/sync_begin.py +++ b/belay/snippets/sync_begin.py @@ -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 diff --git a/belay/webrepl.py b/belay/webrepl.py index 477b63f..64f9a34 100644 --- a/belay/webrepl.py +++ b/belay/webrepl.py @@ -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/" @@ -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: