Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
92 changes: 50 additions & 42 deletions codexctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import importlib.util
import tempfile
import shutil
import json
import re

from typing import cast
from os import listdir
from typing import Any, Callable, cast

from .updates import UpdateManager

try:
from loguru import logger
Expand All @@ -23,8 +23,6 @@
"Requests is required for accessing remote files. Please install it."
)

from .updates import UpdateManager


class Manager:
"""
Expand All @@ -38,11 +36,11 @@ def __init__(self, device: str, logger: logging.Logger) -> None:
device (str): Type of device that is running the script
logger (logger): Logger object
"""
self.device = device
self.logger = logger
self.updater = UpdateManager(logger)
self.device: str = device
self.logger: logging.Logger = logger
self.updater: UpdateManager = UpdateManager(logger)

def call_func(self, function: str, args: dict) -> None:
def call_func(self, function: str, args: dict[str, Any]) -> None:
"""Runs a command based on the function name and arguments provided

Args:
Expand All @@ -51,11 +49,11 @@ def call_func(self, function: str, args: dict) -> None:
"""

if "reMarkable" not in self.device:
remarkable_version = args.get("hardware")
remarkable_version = cast(str, args.get("hardware"))
else:
remarkable_version = self.device

version = cast(str | None, args.get("version", None))
version = cast(Callable[[str, None], str | None], args.get)("version", None)
Comment thread
Eeems marked this conversation as resolved.

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

### Transfer & Download functionalities
elif function in ("transfer", "download"):
from .device import DeviceManager

remarkable = DeviceManager(
remote=remote,
address=args["address"],
remote="reMarkable" not in self.device,
address=cast(str, args["address"]),
logger=self.logger,
authentication=args["password"],
authentication=cast(str, args["password"]),
)

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

remarkable = DeviceManager(
remote=remote,
address=args["address"],
address=cast(str, args["address"]),
logger=self.logger,
authentication=args["password"],
authentication=cast(str, args["password"]),
)

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

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

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

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

### Setting up the argument parser
parser = argparse.ArgumentParser("Codexctl")
parser.add_argument(
_ = parser.add_argument(
"--verbose",
"-v",
required=False,
help="Enable verbose logging",
action="store_true",
dest="verbose",
)
parser.add_argument(
_ = parser.add_argument(
"--address",
"-a",
required=False,
help="Specify the address of the device",
default=None,
dest="address",
)
parser.add_argument(
_ = parser.add_argument(
"--password",
"-p",
required=False,
Expand All @@ -374,9 +374,9 @@ def main() -> None:
download = subparsers.add_parser(
"download", help="Download the specified version firmware file"
)
download.add_argument("version", help="Version to download")
download.add_argument("--out", "-o", help="Folder to download to", default=None)
download.add_argument(
_ = download.add_argument("version", help="Version to download")
_ = download.add_argument("--out", "-o", help="Folder to download to", default=None)
_ = download.add_argument(
"--hardware",
"--device",
"-d",
Expand All @@ -389,35 +389,35 @@ def main() -> None:
backup = subparsers.add_parser(
"backup", help="Download remote files to local directory"
)
backup.add_argument(
_ = backup.add_argument(
"-r",
"--remote",
help="Remote directory to backup. Defaults to download folder",
default="",
dest="remote",
)
backup.add_argument(
_ = backup.add_argument(
"-l",
"--local",
help="Local directory to backup to. Defaults to download folder",
default="./",
dest="local",
)
backup.add_argument(
_ = backup.add_argument(
"-R",
"--no-recursion",
help="Disables recursively backup remote directory",
action="store_true",
dest="no_recursion",
)
backup.add_argument(
_ = backup.add_argument(
"-O",
"--no-overwrite",
help="Disables overwrite",
action="store_true",
dest="no_overwrite",
)
backup.add_argument(
_ = backup.add_argument(
"-i",
"--incremental",
help="Overwrite out-of-date files only",
Expand All @@ -428,40 +428,48 @@ def main() -> None:
cat = subparsers.add_parser(
"cat", help="Cat the contents of a file inside a firmwareimage"
)
cat.add_argument("file", help="Path to update file to cat", default=None)
cat.add_argument("target_path", help="Path inside the image to list", default=None)
_ = cat.add_argument("file", help="Path to update file to cat", default=None)
_ = cat.add_argument(
"target_path", help="Path inside the image to list", default=None
)

### Ls subcommand
ls = subparsers.add_parser("ls", help="List files inside a firmware image")
ls.add_argument("file", help="Path to update file to extract", default=None)
ls.add_argument("target_path", help="Path inside the image to list", default=None)
_ = ls.add_argument("file", help="Path to update file to extract", default=None)
_ = ls.add_argument(
"target_path", help="Path inside the image to list", default=None
)

### Extract subcommand
extract = subparsers.add_parser(
"extract", help="Extract the specified version update file"
)
extract.add_argument("file", help="Path to update file to extract", default=None)
extract.add_argument("--out", help="Folder to extract to", default=None, dest="out")
_ = extract.add_argument(
"file", help="Path to update file to extract", default=None
)
_ = extract.add_argument(
"--out", help="Folder to extract to", default=None, dest="out"
)

### Mount subcommand
mount = subparsers.add_parser(
"mount", help="Mount the specified version firmware filesystem"
)
mount.add_argument(
_ = mount.add_argument(
"filesystem",
help="Path to version firmware filesystem to extract",
default=None,
)
mount.add_argument("--out", help="Folder to mount to", default=None)
_ = mount.add_argument("--out", help="Folder to mount to", default=None)

### Upload subcommand
upload = subparsers.add_parser(
"upload", help="Upload folder/files to device (pdf only)"
)
upload.add_argument(
_ = upload.add_argument(
"paths", help="Path to file(s)/folder to upload", default=None, nargs="+"
)
upload.add_argument(
_ = upload.add_argument(
"-r",
"--remote",
help="Remote directory to upload to. Defaults to root folder",
Expand All @@ -470,17 +478,17 @@ def main() -> None:
)

### Status subcommand
subparsers.add_parser(
_ = subparsers.add_parser(
"status", help="Get the current version of the device and other information"
)

### Restore subcommand
subparsers.add_parser(
_ = subparsers.add_parser(
"restore", help="Restores to previous version installed on device"
)

### List subcommand
subparsers.add_parser("list", help="List all available versions")
_ = subparsers.add_parser("list", help="List all available versions")

### Setting logging level
args = parser.parse_args()
Expand Down
4 changes: 2 additions & 2 deletions codexctl/analysis.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ext4
import warnings
import warnings
import errno

from remarkable_update_image import UpdateImage
from remarkable_update_image import UpdateImageSignatureException


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

image = UpdateImage(file)
Expand Down
Loading
Loading