Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix version overriding arg #219

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading