Skip to content

Commit 80e9d38

Browse files
committed
Merge branch 'beta' into copilot/fix-8e50e39a-66d9-45f7-8384-f542ffa460a1
2 parents 0565ded + 79e0102 commit 80e9d38

6 files changed

Lines changed: 253 additions & 244 deletions

File tree

codexctl/__init__.py

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import importlib.util
88
import tempfile
99
import shutil
10-
import json
1110
import re
1211

13-
from typing import cast
14-
from os import listdir
12+
from typing import Any, Callable, cast
13+
from .device import HardwareType
14+
15+
from .updates import UpdateManager
1516

1617
try:
1718
from loguru import logger
@@ -23,10 +24,6 @@
2324
"Requests is required for accessing remote files. Please install it."
2425
)
2526

26-
from .device import HardwareType
27-
from .updates import UpdateManager
28-
29-
3027
class Manager:
3128
"""
3229
Main class for codexctl
@@ -39,11 +36,11 @@ def __init__(self, device: str, logger: logging.Logger) -> None:
3936
device (str): Type of device that is running the script
4037
logger (logger): Logger object
4138
"""
42-
self.device = device
43-
self.logger = logger
44-
self.updater = UpdateManager(logger)
39+
self.device: str = device
40+
self.logger: logging.Logger = logger
41+
self.updater: UpdateManager = UpdateManager(logger)
4542

46-
def call_func(self, function: str, args: dict) -> None:
43+
def call_func(self, function: str, args: dict[str, Any]) -> None:
4744
"""Runs a command based on the function name and arguments provided
4845
4946
Args:
@@ -55,9 +52,9 @@ def call_func(self, function: str, args: dict) -> None:
5552
remarkable_version = HardwareType.parse(self.device)
5653
except ValueError:
5754
hw = args.get("hardware")
58-
remarkable_version = HardwareType.parse(hw) if hw else None
55+
remarkable_version = cast(str, HardwareType.parse(hw)) if hw else None
5956

60-
version = cast(str | None, args.get("version", None))
57+
version = cast(Callable[[str, None], str | None], args.get)("version", None)
6158

6259
if remarkable_version:
6360
if version == "latest":
@@ -177,7 +174,8 @@ def call_func(self, function: str, args: dict) -> None:
177174
)
178175
else:
179176
rmWeb.upload(input_paths=args["paths"], remoteFolder=args["remote"])
180-
177+
178+
181179
### Update & Version functionalities
182180
elif function in ("install", "status", "restore"):
183181
remote = False
@@ -198,9 +196,9 @@ def call_func(self, function: str, args: dict) -> None:
198196

199197
remarkable = DeviceManager(
200198
remote=remote,
201-
address=args["address"],
199+
address=cast(str, args["address"]),
202200
logger=self.logger,
203-
authentication=args["password"],
201+
authentication=cast(str, args["password"]),
204202
)
205203

206204
if version == "latest":
@@ -285,7 +283,7 @@ def version_lookup(version: str | None) -> re.Match[str] | None:
285283
) != os.path.abspath("updates"):
286284
if not os.path.exists("updates"):
287285
os.mkdir("updates")
288-
shutil.move(update_file, "updates")
286+
_ = shutil.move(update_file, "updates")
289287
update_file = get_available_version(version)
290288
made_update_folder = True # Delete at end
291289

@@ -323,7 +321,7 @@ def version_lookup(version: str | None) -> re.Match[str] | None:
323321
remarkable.install_ohma_update(update_file)
324322

325323
if made_update_folder: # Move update file back out
326-
shutil.move(os.listdir("updates")[0], "../")
324+
_ = shutil.move(os.listdir("updates")[0], "../")
327325
shutil.rmtree("updates")
328326

329327
os.chdir(orig_cwd)
@@ -337,23 +335,23 @@ def main() -> None:
337335

338336
### Setting up the argument parser
339337
parser = argparse.ArgumentParser("Codexctl")
340-
parser.add_argument(
338+
_ = parser.add_argument(
341339
"--verbose",
342340
"-v",
343341
required=False,
344342
help="Enable verbose logging",
345343
action="store_true",
346344
dest="verbose",
347345
)
348-
parser.add_argument(
346+
_ = parser.add_argument(
349347
"--address",
350348
"-a",
351349
required=False,
352350
help="Specify the address of the device",
353351
default=None,
354352
dest="address",
355353
)
356-
parser.add_argument(
354+
_ = parser.add_argument(
357355
"--password",
358356
"-p",
359357
required=False,
@@ -374,9 +372,9 @@ def main() -> None:
374372
download = subparsers.add_parser(
375373
"download", help="Download the specified version firmware file"
376374
)
377-
download.add_argument("version", help="Version to download")
378-
download.add_argument("--out", "-o", help="Folder to download to", default=None)
379-
download.add_argument(
375+
_ = download.add_argument("version", help="Version to download")
376+
_ = download.add_argument("--out", "-o", help="Folder to download to", default=None)
377+
_ = download.add_argument(
380378
"--hardware",
381379
"--device",
382380
"-d",
@@ -389,35 +387,35 @@ def main() -> None:
389387
backup = subparsers.add_parser(
390388
"backup", help="Download remote files to local directory"
391389
)
392-
backup.add_argument(
390+
_ = backup.add_argument(
393391
"-r",
394392
"--remote",
395393
help="Remote directory to backup. Defaults to download folder",
396394
default="",
397395
dest="remote",
398396
)
399-
backup.add_argument(
397+
_ = backup.add_argument(
400398
"-l",
401399
"--local",
402400
help="Local directory to backup to. Defaults to download folder",
403401
default="./",
404402
dest="local",
405403
)
406-
backup.add_argument(
404+
_ = backup.add_argument(
407405
"-R",
408406
"--no-recursion",
409407
help="Disables recursively backup remote directory",
410408
action="store_true",
411409
dest="no_recursion",
412410
)
413-
backup.add_argument(
411+
_ = backup.add_argument(
414412
"-O",
415413
"--no-overwrite",
416414
help="Disables overwrite",
417415
action="store_true",
418416
dest="no_overwrite",
419417
)
420-
backup.add_argument(
418+
_ = backup.add_argument(
421419
"-i",
422420
"--incremental",
423421
help="Overwrite out-of-date files only",
@@ -428,40 +426,48 @@ def main() -> None:
428426
cat = subparsers.add_parser(
429427
"cat", help="Cat the contents of a file inside a firmwareimage"
430428
)
431-
cat.add_argument("file", help="Path to update file to cat", default=None)
432-
cat.add_argument("target_path", help="Path inside the image to list", default=None)
429+
_ = cat.add_argument("file", help="Path to update file to cat", default=None)
430+
_ = cat.add_argument(
431+
"target_path", help="Path inside the image to list", default=None
432+
)
433433

434434
### Ls subcommand
435435
ls = subparsers.add_parser("ls", help="List files inside a firmware image")
436-
ls.add_argument("file", help="Path to update file to extract", default=None)
437-
ls.add_argument("target_path", help="Path inside the image to list", default=None)
436+
_ = ls.add_argument("file", help="Path to update file to extract", default=None)
437+
_ = ls.add_argument(
438+
"target_path", help="Path inside the image to list", default=None
439+
)
438440

439441
### Extract subcommand
440442
extract = subparsers.add_parser(
441443
"extract", help="Extract the specified version update file"
442444
)
443-
extract.add_argument("file", help="Path to update file to extract", default=None)
444-
extract.add_argument("--out", help="Folder to extract to", default=None, dest="out")
445+
_ = extract.add_argument(
446+
"file", help="Path to update file to extract", default=None
447+
)
448+
_ = extract.add_argument(
449+
"--out", help="Folder to extract to", default=None, dest="out"
450+
)
445451

446452
### Mount subcommand
447453
mount = subparsers.add_parser(
448454
"mount", help="Mount the specified version firmware filesystem"
449455
)
450-
mount.add_argument(
456+
_ = mount.add_argument(
451457
"filesystem",
452458
help="Path to version firmware filesystem to extract",
453459
default=None,
454460
)
455-
mount.add_argument("--out", help="Folder to mount to", default=None)
461+
_ = mount.add_argument("--out", help="Folder to mount to", default=None)
456462

457463
### Upload subcommand
458464
upload = subparsers.add_parser(
459465
"upload", help="Upload folder/files to device (pdf only)"
460466
)
461-
upload.add_argument(
467+
_ = upload.add_argument(
462468
"paths", help="Path to file(s)/folder to upload", default=None, nargs="+"
463469
)
464-
upload.add_argument(
470+
_ = upload.add_argument(
465471
"-r",
466472
"--remote",
467473
help="Remote directory to upload to. Defaults to root folder",
@@ -470,12 +476,12 @@ def main() -> None:
470476
)
471477

472478
### Status subcommand
473-
subparsers.add_parser(
479+
_ = subparsers.add_parser(
474480
"status", help="Get the current version of the device and other information"
475481
)
476482

477483
### Restore subcommand
478-
subparsers.add_parser(
484+
_ = subparsers.add_parser(
479485
"restore", help="Restores to previous version installed on device"
480486
)
481487

codexctl/analysis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import ext4
2-
import warnings
2+
import warnings
33
import errno
44

55
from remarkable_update_image import UpdateImage
66
from remarkable_update_image import UpdateImageSignatureException
77

88

9-
def get_update_image(file: str):
9+
def get_update_image(file: str) -> tuple[UpdateImage, ext4.Volume]:
1010
"""Extracts files from an update image (<3.11 currently)"""
1111

1212
image = UpdateImage(file)

0 commit comments

Comments
 (0)