From 3ed849593d31ba6209ea2c74091376ba9b3bddb6 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Sat, 2 Mar 2024 19:17:09 +0000 Subject: [PATCH] Add commandline option for timeout, sync existing REQUEST_TIMEOUT --- circup/__init__.py | 13 ++++++++++--- circup/backends.py | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/circup/__init__.py b/circup/__init__.py index 2ce9f67..d0a3745 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -4,7 +4,7 @@ """ CircUp -- a utility to manage and update libraries on a CircuitPython device. """ - +import pdb import ctypes import glob @@ -646,6 +646,7 @@ def find_modules(backend, bundles_list): bundle_version = bundle_metadata.get("__version__") mpy = device_metadata["mpy"] compatibility = device_metadata.get("compatibility", (None, None)) + pdb.set_trace() module_name = ( path.split(os.sep)[-1] if not path.endswith(os.sep) @@ -1032,6 +1033,11 @@ def libraries_from_code_py(code_py, mod_names): @click.option( "--password", help="Password to use for authentication when --host is used." ) +@click.option( + "--timeout", + default=30, + help="Specify the timeout in seconds for any network operations.", +) @click.option( "--board-id", default=None, @@ -1049,19 +1055,20 @@ def libraries_from_code_py(code_py, mod_names): message="%(prog)s, A CircuitPython module updater. Version %(version)s", ) @click.pass_context -def main(ctx, verbose, path, host, password, board_id, cpy_version): # pragma: no cover +def main(ctx, verbose, path, host, password, timeout, board_id, cpy_version): # pragma: no cover # pylint: disable=too-many-arguments, too-many-branches, too-many-statements """ A tool to manage and update libraries on a CircuitPython device. """ ctx.ensure_object(dict) + ctx.obj["TIMEOUT"] = REQUESTS_TIMEOUT = timeout device_path = get_device_path(host, password, path) using_webworkflow = "host" in ctx.params.keys() and ctx.params["host"] is not None if using_webworkflow: try: - ctx.obj["backend"] = WebBackend(host=host, password=password, logger=logger) + ctx.obj["backend"] = WebBackend(host=host, password=password, logger=logger, timeout=timeout) except ValueError as e: click.secho(e, fg="red") sys.exit(1) diff --git a/circup/backends.py b/circup/backends.py index ff3846e..c392c0f 100644 --- a/circup/backends.py +++ b/circup/backends.py @@ -190,7 +190,7 @@ class WebBackend(Backend): Backend for interacting with a device via Web Workflow """ - def __init__(self, host, password, logger): + def __init__(self, host, password, logger, timeout=10): super().__init__(logger) if password is None: raise ValueError("--host needs --password") @@ -214,7 +214,7 @@ class WebBackend(Backend): self.session = requests.Session() self.session.mount(self.device_location, HTTPAdapter(max_retries=5)) self.library_path = self.device_location + "/" + self.LIB_DIR_PATH - self.timeout = 10 + self.timeout = timeout def install_file_http(self, source): """