Skip to content

Commit

Permalink
Merge pull request #219 from FoamyGuy/fix_local_dir_nondevice
Browse files Browse the repository at this point in the history
fix version overriding arg
  • Loading branch information
tannewt authored May 20, 2024
2 parents c1e1b4b + f12efa3 commit 74b07be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 15 additions & 3 deletions circup/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class Backend:
implementations
"""

def __init__(self, logger):
def __init__(self, logger, version_override=None):
self.device_location = None
self.LIB_DIR_PATH = None
self.version_override = version_override
self.logger = logger

def get_circuitpython_version(self):
Expand Down Expand Up @@ -275,7 +276,9 @@ class WebBackend(Backend):
Backend for interacting with a device via Web Workflow
"""

def __init__(self, host, password, logger, timeout=10):
def __init__( # pylint: disable=too-many-arguments
self, host, password, logger, timeout=10, version_override=None
):
super().__init__(logger)
if password is None:
raise ValueError("--host needs --password")
Expand All @@ -301,6 +304,7 @@ def __init__(self, host, password, logger, timeout=10):
self.session.mount(self.device_location, HTTPAdapter(max_retries=5))
self.library_path = self.device_location + "/" + self.LIB_DIR_PATH
self.timeout = timeout
self.version_override = version_override

def install_file_http(self, source, location=None):
"""
Expand Down Expand Up @@ -401,6 +405,9 @@ def get_circuitpython_version(self):
:return: A tuple with the version string for CircuitPython and the board ID string.
"""
if self.version_override is not None:
return self.version_override

# pylint: disable=arguments-renamed
with self.session.get(
self.device_location + "/cp/version.json", timeout=self.timeout
Expand Down Expand Up @@ -741,9 +748,10 @@ class DiskBackend(Backend):
:param logger: logger to use for outputting messages
:param String boot_out: Optional mock contents of a boot_out.txt file
to use for version information.
:param String version_override: Optional mock version to use.
"""

def __init__(self, device_location, logger, boot_out=None):
def __init__(self, device_location, logger, boot_out=None, version_override=None):
if device_location is None:
raise ValueError(
"Auto locating USB Disk based device failed. "
Expand All @@ -757,6 +765,7 @@ def __init__(self, device_location, logger, boot_out=None):
self.version_info = None
if boot_out is not None:
self.version_info = self.parse_boot_out_file(boot_out)
self.version_override = version_override

def get_circuitpython_version(self):
"""
Expand All @@ -773,6 +782,9 @@ def get_circuitpython_version(self):
:return: A tuple with the version string for CircuitPython and the board ID string.
"""
if self.version_override is not None:
return self.version_override

if not self.version_info:
try:
with open(
Expand Down
12 changes: 10 additions & 2 deletions circup/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ def main( # pylint: disable=too-many-locals
device_path = device_path.replace("circuitpython.local", host)
try:
ctx.obj["backend"] = WebBackend(
host=host, password=password, logger=logger, timeout=timeout
host=host,
password=password,
logger=logger,
timeout=timeout,
version_override=cpy_version,
)
except ValueError as e:
click.secho(e, fg="red")
Expand All @@ -123,7 +127,11 @@ def main( # pylint: disable=too-many-locals
sys.exit(1)
else:
try:
ctx.obj["backend"] = DiskBackend(device_path, logger)
ctx.obj["backend"] = DiskBackend(
device_path,
logger,
version_override=cpy_version,
)
except ValueError as e:
print(e)

Expand Down

0 comments on commit 74b07be

Please sign in to comment.