Skip to content

Commit 1ebb4e6

Browse files
committed
Make pyright mostly happy
1 parent d7313b7 commit 1ebb4e6

6 files changed

Lines changed: 232 additions & 233 deletions

File tree

codexctl/__init__.py

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
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+
14+
from .updates import UpdateManager
1515

1616
try:
1717
from loguru import logger
@@ -23,8 +23,6 @@
2323
"Requests is required for accessing remote files. Please install it."
2424
)
2525

26-
from .updates import UpdateManager
27-
2826

2927
class Manager:
3028
"""
@@ -38,11 +36,11 @@ def __init__(self, device: str, logger: logging.Logger) -> None:
3836
device (str): Type of device that is running the script
3937
logger (logger): Logger object
4038
"""
41-
self.device = device
42-
self.logger = logger
43-
self.updater = UpdateManager(logger)
39+
self.device: str = device
40+
self.logger: logging.Logger = logger
41+
self.updater: UpdateManager = UpdateManager(logger)
4442

45-
def call_func(self, function: str, args: dict) -> None:
43+
def call_func(self, function: str, args: dict[str, Any]) -> None:
4644
"""Runs a command based on the function name and arguments provided
4745
4846
Args:
@@ -51,11 +49,11 @@ def call_func(self, function: str, args: dict) -> None:
5149
"""
5250

5351
if "reMarkable" not in self.device:
54-
remarkable_version = args.get("hardware")
52+
remarkable_version = cast(str, args.get("hardware"))
5553
else:
5654
remarkable_version = self.device
5755

58-
version = cast(str | None, args.get("version", None))
56+
version = cast(Callable[[str, None], str | None], args.get)("version", None)
5957

6058
if remarkable_version:
6159
if version == "latest":
@@ -171,11 +169,13 @@ def call_func(self, function: str, args: dict) -> None:
171169

172170
### Transfer & Download functionalities
173171
elif function in ("transfer", "download"):
172+
from .device import DeviceManager
173+
174174
remarkable = DeviceManager(
175-
remote=remote,
176-
address=args["address"],
175+
remote="reMarkable" not in self.device,
176+
address=cast(str, args["address"]),
177177
logger=self.logger,
178-
authentication=args["password"],
178+
authentication=cast(str, args["password"]),
179179
)
180180

181181
### Update & Version functionalities
@@ -198,9 +198,9 @@ def call_func(self, function: str, args: dict) -> None:
198198

199199
remarkable = DeviceManager(
200200
remote=remote,
201-
address=args["address"],
201+
address=cast(str, args["address"]),
202202
logger=self.logger,
203-
authentication=args["password"],
203+
authentication=cast(str, args["password"]),
204204
)
205205

206206
if version == "latest":
@@ -285,7 +285,7 @@ def version_lookup(version: str | None) -> re.Match[str] | None:
285285
) != os.path.abspath("updates"):
286286
if not os.path.exists("updates"):
287287
os.mkdir("updates")
288-
shutil.move(update_file, "updates")
288+
_ = shutil.move(update_file, "updates")
289289
update_file = get_available_version(version)
290290
made_update_folder = True # Delete at end
291291

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

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

329329
os.chdir(orig_cwd)
@@ -337,23 +337,23 @@ def main() -> None:
337337

338338
### Setting up the argument parser
339339
parser = argparse.ArgumentParser("Codexctl")
340-
parser.add_argument(
340+
_ = parser.add_argument(
341341
"--verbose",
342342
"-v",
343343
required=False,
344344
help="Enable verbose logging",
345345
action="store_true",
346346
dest="verbose",
347347
)
348-
parser.add_argument(
348+
_ = parser.add_argument(
349349
"--address",
350350
"-a",
351351
required=False,
352352
help="Specify the address of the device",
353353
default=None,
354354
dest="address",
355355
)
356-
parser.add_argument(
356+
_ = parser.add_argument(
357357
"--password",
358358
"-p",
359359
required=False,
@@ -374,9 +374,9 @@ def main() -> None:
374374
download = subparsers.add_parser(
375375
"download", help="Download the specified version firmware file"
376376
)
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(
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(
380380
"--hardware",
381381
"--device",
382382
"-d",
@@ -389,35 +389,35 @@ def main() -> None:
389389
backup = subparsers.add_parser(
390390
"backup", help="Download remote files to local directory"
391391
)
392-
backup.add_argument(
392+
_ = backup.add_argument(
393393
"-r",
394394
"--remote",
395395
help="Remote directory to backup. Defaults to download folder",
396396
default="",
397397
dest="remote",
398398
)
399-
backup.add_argument(
399+
_ = backup.add_argument(
400400
"-l",
401401
"--local",
402402
help="Local directory to backup to. Defaults to download folder",
403403
default="./",
404404
dest="local",
405405
)
406-
backup.add_argument(
406+
_ = backup.add_argument(
407407
"-R",
408408
"--no-recursion",
409409
help="Disables recursively backup remote directory",
410410
action="store_true",
411411
dest="no_recursion",
412412
)
413-
backup.add_argument(
413+
_ = backup.add_argument(
414414
"-O",
415415
"--no-overwrite",
416416
help="Disables overwrite",
417417
action="store_true",
418418
dest="no_overwrite",
419419
)
420-
backup.add_argument(
420+
_ = backup.add_argument(
421421
"-i",
422422
"--incremental",
423423
help="Overwrite out-of-date files only",
@@ -428,40 +428,48 @@ def main() -> None:
428428
cat = subparsers.add_parser(
429429
"cat", help="Cat the contents of a file inside a firmwareimage"
430430
)
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)
431+
_ = cat.add_argument("file", help="Path to update file to cat", default=None)
432+
_ = cat.add_argument(
433+
"target_path", help="Path inside the image to list", default=None
434+
)
433435

434436
### Ls subcommand
435437
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)
438+
_ = ls.add_argument("file", help="Path to update file to extract", default=None)
439+
_ = ls.add_argument(
440+
"target_path", help="Path inside the image to list", default=None
441+
)
438442

439443
### Extract subcommand
440444
extract = subparsers.add_parser(
441445
"extract", help="Extract the specified version update file"
442446
)
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")
447+
_ = extract.add_argument(
448+
"file", help="Path to update file to extract", default=None
449+
)
450+
_ = extract.add_argument(
451+
"--out", help="Folder to extract to", default=None, dest="out"
452+
)
445453

446454
### Mount subcommand
447455
mount = subparsers.add_parser(
448456
"mount", help="Mount the specified version firmware filesystem"
449457
)
450-
mount.add_argument(
458+
_ = mount.add_argument(
451459
"filesystem",
452460
help="Path to version firmware filesystem to extract",
453461
default=None,
454462
)
455-
mount.add_argument("--out", help="Folder to mount to", default=None)
463+
_ = mount.add_argument("--out", help="Folder to mount to", default=None)
456464

457465
### Upload subcommand
458466
upload = subparsers.add_parser(
459467
"upload", help="Upload folder/files to device (pdf only)"
460468
)
461-
upload.add_argument(
469+
_ = upload.add_argument(
462470
"paths", help="Path to file(s)/folder to upload", default=None, nargs="+"
463471
)
464-
upload.add_argument(
472+
_ = upload.add_argument(
465473
"-r",
466474
"--remote",
467475
help="Remote directory to upload to. Defaults to root folder",
@@ -470,17 +478,17 @@ def main() -> None:
470478
)
471479

472480
### Status subcommand
473-
subparsers.add_parser(
481+
_ = subparsers.add_parser(
474482
"status", help="Get the current version of the device and other information"
475483
)
476484

477485
### Restore subcommand
478-
subparsers.add_parser(
486+
_ = subparsers.add_parser(
479487
"restore", help="Restores to previous version installed on device"
480488
)
481489

482490
### List subcommand
483-
subparsers.add_parser("list", help="List all available versions")
491+
_ = subparsers.add_parser("list", help="List all available versions")
484492

485493
### Setting logging level
486494
args = parser.parse_args()

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)