Add argsparse formatter
This commit is contained in:
parent
d12b3678b0
commit
4f7afad4e3
|
@ -14,6 +14,7 @@ import adbutils
|
|||
import adbutils.shell
|
||||
from rich.console import Console
|
||||
from rich.prompt import Prompt
|
||||
from rich_argparse import RichHelpFormatter
|
||||
|
||||
from . import Files
|
||||
from .utils import check_device, get_port, flash_boot, boot_ofox, clean_device, wait_for_bootloader, check_parts, \
|
||||
|
@ -43,46 +44,50 @@ def main() -> int:
|
|||
signal.signal(signal.SIGINT, handle_sigint)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Linux on Nabu deployer"
|
||||
description="Linux on Nabu deployer",
|
||||
formatter_class=lambda prog: RichHelpFormatter(
|
||||
prog,
|
||||
max_help_position=37
|
||||
)
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-v", "--version",
|
||||
help="show version and exit",
|
||||
action="store_true"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-d", "--device-serial",
|
||||
help="Device serial"
|
||||
help="device serial"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-u", "--username",
|
||||
help="User name"
|
||||
help="linux user name"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-p", "--password",
|
||||
help="User password"
|
||||
help="linux user password"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"RootFS",
|
||||
help="RootFS image"
|
||||
help="root fs image",
|
||||
default=None, nargs="?"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-S", "--part-size",
|
||||
help="linux partition size in percents"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--debug",
|
||||
help="enable debug output",
|
||||
action="store_true"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--version",
|
||||
help="show version and exit",
|
||||
action="store_true"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.version:
|
||||
|
@ -94,16 +99,19 @@ def main() -> int:
|
|||
else:
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
rootfs = op.abspath(args.RootFS)
|
||||
try:
|
||||
rootfs_magic = magic.Magic(mime=True).from_file(rootfs)
|
||||
logger.debug(f"RootFS magic: {rootfs_magic}")
|
||||
if rootfs_magic not in ["application/octet-stream", "inode/blockdevice"]:
|
||||
console.log("Invalid RootFS image")
|
||||
if args.RootFS:
|
||||
rootfs = op.abspath(args.RootFS)
|
||||
try:
|
||||
rootfs_magic = magic.Magic(mime=True).from_file(rootfs)
|
||||
logger.debug(f"RootFS magic: {rootfs_magic}")
|
||||
if rootfs_magic not in ["application/octet-stream", "inode/blockdevice"]:
|
||||
console.log("Invalid RootFS image")
|
||||
return 1
|
||||
except FileNotFoundError:
|
||||
console.log("RootFS image not found!")
|
||||
return 1
|
||||
except FileNotFoundError:
|
||||
console.log("RootFS image not found!")
|
||||
return 1
|
||||
else:
|
||||
console.log(parser.parse_args("-h".split()))
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
|
16
poetry.lock
generated
16
poetry.lock
generated
|
@ -642,6 +642,20 @@ pygments = ">=2.13.0,<3.0.0"
|
|||
[package.extras]
|
||||
jupyter = ["ipywidgets (>=7.5.1,<9)"]
|
||||
|
||||
[[package]]
|
||||
name = "rich-argparse"
|
||||
version = "1.4.0"
|
||||
description = "Rich help formatters for argparse and optparse"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "rich_argparse-1.4.0-py3-none-any.whl", hash = "sha256:68b263d3628d07b1d27cfe6ad896da2f5a5583ee2ba226aeeb24459840023b38"},
|
||||
{file = "rich_argparse-1.4.0.tar.gz", hash = "sha256:c275f34ea3afe36aec6342c2a2298893104b5650528941fb53c21067276dba19"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
rich = ">=11.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "setuptools"
|
||||
version = "69.5.1"
|
||||
|
@ -689,4 +703,4 @@ files = [
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "3.11.*"
|
||||
content-hash = "e2af14ef9b15c3b3cc9b0716da5276427808f431f8d5603541dfdf390656397b"
|
||||
content-hash = "f36325d69c03ac98f4b2bd0aed451b859ef95bc05b3c3a072da079770e683e0a"
|
||||
|
|
|
@ -15,6 +15,7 @@ pyinstaller = "^6.6.0"
|
|||
libusb = "^1.0.27"
|
||||
python-magic = { version = "^0.4.27", platform="linux" }
|
||||
python-magic-bin = { version = "0.4.14", platform="win32" }
|
||||
rich-argparse = "^1.4.0"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
lon-deployer = "lon_deployer.main:run"
|
||||
|
|
Reference in a new issue