fix typo, change name to DiskBackend, remove wrapper _get_circuitpython_version
This commit is contained in:
parent
467740088c
commit
d3eda67ddb
2 changed files with 22 additions and 24 deletions
|
|
@ -49,7 +49,7 @@ BUNDLE_DATA = os.path.join(DATA_DIR, "circup.json")
|
|||
LOG_DIR = appdirs.user_log_dir(appname="circup", appauthor="adafruit")
|
||||
#: The location of the log file for the utility.
|
||||
LOGFILE = os.path.join(LOG_DIR, "circup.log")
|
||||
#: The localtion to store a local copy of code.py for use with --auto and
|
||||
#: The location to store a local copy of code.py for use with --auto and
|
||||
# web workflow
|
||||
LOCAL_CODE_PY_COPY = os.path.join(DATA_DIR, "code.tmp.py")
|
||||
#: The libraries (and blank lines) which don't go on devices
|
||||
|
|
@ -419,21 +419,17 @@ class Backend:
|
|||
def __init__(self):
|
||||
self.LIB_DIR_PATH = None
|
||||
|
||||
def _get_circuitpython_version(self, device_location):
|
||||
"""
|
||||
To be overridden by subclass
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_circuitpython_version(self, device_location):
|
||||
"""
|
||||
Must be overridden by subclass for implementation!
|
||||
|
||||
Returns the version number of CircuitPython running on the board connected
|
||||
via ``device_url``, along with the board ID.
|
||||
|
||||
:param str device_location: http based device URL or local file path.
|
||||
:return: A tuple with the version string for CircuitPython and the board ID string.
|
||||
"""
|
||||
return self._get_circuitpython_version(device_location)
|
||||
raise NotImplementedError
|
||||
|
||||
def _get_modules(self, device_lib_path):
|
||||
"""
|
||||
|
|
@ -578,6 +574,7 @@ class WebBackend(Backend):
|
|||
"""
|
||||
url = urlparse(target)
|
||||
auth = HTTPBasicAuth("", url.password)
|
||||
print(f"target: {target}")
|
||||
|
||||
with open(source, "rb") as fp:
|
||||
r = requests.put(target, fp.read(), auth=auth)
|
||||
|
|
@ -591,6 +588,7 @@ class WebBackend(Backend):
|
|||
"""
|
||||
url = urlparse(target)
|
||||
auth = HTTPBasicAuth("", url.password)
|
||||
print(f"target: {target}")
|
||||
|
||||
# Create the top level directory.
|
||||
r = requests.put(target + ("/" if not target.endswith("/") else ""), auth=auth)
|
||||
|
|
@ -611,7 +609,7 @@ class WebBackend(Backend):
|
|||
r = requests.put(target + rel_path + "/" + name, auth=auth)
|
||||
r.raise_for_status()
|
||||
|
||||
def _get_circuitpython_version(self, url):
|
||||
def get_circuitpython_version(self, url):
|
||||
"""
|
||||
Returns the version number of CircuitPython running on the board connected
|
||||
via ``device_path``, along with the board ID. This is obtained using
|
||||
|
|
@ -868,7 +866,7 @@ def _get_modules_file(path):
|
|||
return result
|
||||
|
||||
|
||||
class USBBackend(Backend):
|
||||
class DiskBackend(Backend):
|
||||
"""
|
||||
Backend for interacting with a device via USB Workflow
|
||||
"""
|
||||
|
|
@ -877,7 +875,7 @@ class USBBackend(Backend):
|
|||
super().__init__()
|
||||
self.LIB_DIR_PATH = "lib"
|
||||
|
||||
def _get_circuitpython_version(self, device_location):
|
||||
def get_circuitpython_version(self, device_location):
|
||||
"""
|
||||
Returns the version number of CircuitPython running on the board connected
|
||||
via ``device_path``, along with the board ID. This is obtained from the
|
||||
|
|
@ -1663,7 +1661,7 @@ def main(ctx, verbose, path, host, password, board_id, cpy_version): # pragma:
|
|||
if using_webworkflow:
|
||||
ctx.obj["backend"] = WebBackend(host=host, password=password)
|
||||
else:
|
||||
ctx.obj["backend"] = USBBackend()
|
||||
ctx.obj["backend"] = DiskBackend()
|
||||
|
||||
if verbose:
|
||||
# Configure additional logging to stdout.
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@ def test_Module_update_dir():
|
|||
m = circup.Module(
|
||||
path, repo, device_version, bundle_version, False, bundle, (None, None)
|
||||
)
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
with mock.patch("circup.shutil") as mock_shutil, mock.patch(
|
||||
"circup.os.path.isdir", return_value=True
|
||||
):
|
||||
|
|
@ -411,7 +411,7 @@ def test_Module_update_file():
|
|||
m = circup.Module(
|
||||
path, repo, device_version, bundle_version, False, bundle, (None, None)
|
||||
)
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
with mock.patch("circup.shutil") as mock_shutil, mock.patch(
|
||||
"circup.os.remove"
|
||||
) as mock_remove, mock.patch("circup.os.path.isdir", return_value=False):
|
||||
|
|
@ -614,7 +614,7 @@ def test_find_modules():
|
|||
), mock.patch(
|
||||
"circup.os.path.isfile", return_value=True
|
||||
):
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
bundle = circup.Bundle(TEST_BUNDLE_NAME)
|
||||
bundles_list = [bundle]
|
||||
for module in bundle_modules:
|
||||
|
|
@ -641,7 +641,7 @@ def test_find_modules_goes_bang():
|
|||
) as mock_exit:
|
||||
bundle = circup.Bundle(TEST_BUNDLE_NAME)
|
||||
bundles_list = [bundle]
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
circup.find_modules(backend, "", bundles_list)
|
||||
assert mock_click.echo.call_count == 1
|
||||
mock_exit.assert_called_once_with(1)
|
||||
|
|
@ -705,7 +705,7 @@ def test_get_circuitpython_version():
|
|||
"Adafruit CircuitPlayground Express with samd21g18"
|
||||
)
|
||||
with mock.patch("builtins.open", mock.mock_open(read_data=data_no_id)) as mock_open:
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
assert backend.get_circuitpython_version(device_path) == ("4.1.0", "")
|
||||
mock_open.assert_called_once_with(
|
||||
os.path.join(device_path, "boot_out.txt"), "r", encoding="utf-8"
|
||||
|
|
@ -714,7 +714,7 @@ def test_get_circuitpython_version():
|
|||
with mock.patch(
|
||||
"builtins.open", mock.mock_open(read_data=data_with_id)
|
||||
) as mock_open:
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
assert backend.get_circuitpython_version(device_path) == (
|
||||
"4.1.0",
|
||||
"this_is_a_board",
|
||||
|
|
@ -729,7 +729,7 @@ def test_get_device_versions():
|
|||
Ensure get_modules is called with the path for the attached device.
|
||||
"""
|
||||
with mock.patch("circup.USBBackend.get_modules", return_value="ok") as mock_gm:
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
assert backend.get_device_versions("TESTDIR") == "ok"
|
||||
mock_gm.assert_called_once_with(os.path.join("TESTDIR", "lib"))
|
||||
|
||||
|
|
@ -739,7 +739,7 @@ def test_get_modules_empty_path():
|
|||
Sometimes a path to a device or bundle may be empty. Ensure, if this is the
|
||||
case, an empty dictionary is returned.
|
||||
"""
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
assert backend.get_modules("") == {}
|
||||
|
||||
|
||||
|
|
@ -754,7 +754,7 @@ def test_get_modules_that_are_files():
|
|||
os.path.join("tests", ".hidden_module.py"),
|
||||
]
|
||||
with mock.patch("circup.glob.glob", side_effect=[mods, [], []]):
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
result = backend.get_modules(path)
|
||||
assert len(result) == 1 # Hidden files are ignored.
|
||||
assert "local_module" in result
|
||||
|
|
@ -778,7 +778,7 @@ def test_get_modules_that_are_directories():
|
|||
]
|
||||
mod_files = ["tests/dir_module/my_module.py", "tests/dir_module/__init__.py"]
|
||||
with mock.patch("circup.glob.glob", side_effect=[[], [], mods, mod_files, []]):
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
result = backend.get_modules(path)
|
||||
assert len(result) == 1
|
||||
assert "dir_module" in result
|
||||
|
|
@ -797,7 +797,7 @@ def test_get_modules_that_are_directories_with_no_metadata():
|
|||
mods = [os.path.join("tests", "bad_module", "")]
|
||||
mod_files = ["tests/bad_module/my_module.py", "tests/bad_module/__init__.py"]
|
||||
with mock.patch("circup.glob.glob", side_effect=[[], [], mods, mod_files, []]):
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
result = backend.get_modules(path)
|
||||
assert len(result) == 1
|
||||
assert "bad_module" in result
|
||||
|
|
@ -1032,7 +1032,7 @@ def test_libraries_from_imports():
|
|||
"adafruit_touchscreen",
|
||||
]
|
||||
test_file = str(pathlib.Path(__file__).parent / "import_styles.py")
|
||||
backend = circup.USBBackend()
|
||||
backend = circup.DiskBackend()
|
||||
result = backend.libraries_from_imports(test_file, mod_names)
|
||||
print(result)
|
||||
assert result == [
|
||||
|
|
|
|||
Loading…
Reference in a new issue