Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0n committed Jun 3, 2024
1 parent 3aec7d5 commit 7713b5c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 60 deletions.
113 changes: 66 additions & 47 deletions ruyi/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def init_argparse() -> argparse.ArgumentParser:

root = argparse.ArgumentParser(
prog=RUYI_ENTRYPOINT_NAME,
description=f"RuyiSDK Package Manager {RUYI_SEMVER}",
description=f"RuyiSDK Package Manager {RUYI_SEMVER}", # L10N: cli-root-desc
)
root.set_defaults(func=lambda _: root.print_help())

Expand All @@ -39,178 +39,197 @@ def init_argparse() -> argparse.ArgumentParser:
action="store_const",
dest="func",
const=cli_version,
help="Print version information",
help="Print version information", # L10N: cli-version-help
)

root.add_argument(
"--porcelain",
action="store_true",
help="Give the output in a machine-friendly format if applicable",
help="Give the output in a machine-friendly format if applicable", # L10N: cli-porcelain-help
)

sp = root.add_subparsers(
title="subcommands",
title="subcommands", # L10N: cli-subcommands
)

# Device management commands
device = sp.add_parser(
"device",
help="Manage devices",
help="Manage devices", # L10N: cli-device-help
)
device.set_defaults(func=lambda _: device.print_help())
devicesp = device.add_subparsers(
title="subcommands",
title="subcommands", # L10N: cli-subcommands
)

device_provision = devicesp.add_parser(
"provision",
help="Interactively initialize a device for development",
help="Interactively initialize a device for development", # L10N: cli-provision-help
)
device_provision.set_defaults(func=cli_device_provision)

extract = sp.add_parser(
"extract",
help="Fetch package(s) then extract to current directory",
help="Fetch package(s) then extract to current directory", # L10N: cli-extract-help
)
extract.add_argument(
"atom",
type=str,
nargs="+",
help="Specifier (atom) of the package(s) to extract",
help="Specifier (atom) of the package(s) to extract", # L10N: cli-extract-atom-help
)
extract.add_argument(
"--host",
type=str,
default=native_host_str,
help="Override the host architecture (normally not needed)",
help="Override the host architecture (normally not needed)", # L10N: cli-extract-host-help
)
extract.set_defaults(func=cli_extract)

install = sp.add_parser(
"install", aliases=["i"], help="Install package from configured repository"
"install",
aliases=["i"],
help="Install package from configured repository", # L10N: cli-install-help
)
install.add_argument(
"atom",
type=str,
nargs="+",
help="Specifier (atom) of the package to install",
help="Specifier (atom) of the package to install", # L10N: cli-install-atom-help
)
install.add_argument(
"-f",
"--fetch-only",
action="store_true",
help="Fetch distribution files only without installing",
help="Fetch distribution files only without installing", # L10N: cli-install-fetch-only-help
)
install.add_argument(
"--host",
type=str,
default=native_host_str,
help="Override the host architecture (normally not needed)",
help="Override the host architecture (normally not needed)", # L10N: cli-install-host-help
)
install.add_argument(
"--reinstall",
action="store_true",
help="Force re-installation of already installed packages",
help="Force re-installation of already installed packages", # L10N: cli-install-reinstall-help
)
install.set_defaults(func=cli_install)

list = sp.add_parser(
"list", help="List available packages in configured repository"
"list",
help="List available packages in configured repository", # L10N: cli-list-help
)
list.set_defaults(func=cli_list)
list.add_argument(
"--verbose",
"-v",
action="store_true",
help="Also show details for every package",
help="Also show details for every package", # L10N: cli-list-verbose-help
)

listsp = list.add_subparsers(required=False)
list_profiles = listsp.add_parser("profiles", help="List all available profiles")
list_profiles = listsp.add_parser(
"profiles",
help="List all available profiles", # L10N: cli-list-profiles-help
)
list_profiles.set_defaults(func=cli_list_profiles)

news = sp.add_parser(
"news",
help="List and read news items from configured repository",
help="List and read news items from configured repository", # L10N: cli-news-help
)
news.set_defaults(func=lambda _: news.print_help())
newssp = news.add_subparsers(title="subcommands")
newssp = news.add_subparsers(
title="subcommands", # L10N: cli-subcommands
)

news_list = newssp.add_parser(
"list",
help="List news items",
help="List news items", # L10N: cli-news-list-help
)
news_list.add_argument(
"--new",
action="store_true",
help="List unread news items only",
help="List unread news items only", # L10N: cli-news-list-new-help
)
news_list.set_defaults(func=cli_news_list)

news_read = newssp.add_parser(
"read",
help="Read news items",
description="Outputs news item(s) to the console and mark as already read. Defaults to reading all unread items if no item is specified.",
description="Outputs news item(s) to the console and mark as already read. Defaults to reading all unread items if no item is specified.", # L10N: cli-news-read-help
)
news_read.add_argument(
"--quiet",
"-q",
action="store_true",
help="Do not output anything and only mark as read",
help="Do not output anything and only mark as read", # L10N: cli-news-read-quiet-help
)
news_read.add_argument(
"item",
type=str,
nargs="*",
help="Ordinal or ID of the news item(s) to read",
help="Ordinal or ID of the news item(s) to read", # L10N: cli-news-read-item-help
)
news_read.set_defaults(func=cli_news_read)

up = sp.add_parser("update", help="Update RuyiSDK repo and packages")
up = sp.add_parser(
"update",
help="Update RuyiSDK repo and packages", # L10N: cli-update-help
)
up.set_defaults(func=cli_update)

venv = sp.add_parser(
"venv",
help="Generate a virtual environment adapted to the chosen toolchain and profile",
help="Generate a virtual environment adapted to the chosen toolchain and profile", # L10N: cli-venv-help
)
venv.add_argument(
"profile",
type=str,
help="Profile to use for the environment", # L10N: cli-venv-profile-help
)
venv.add_argument(
"dest",
type=str,
help="Path to the new virtual environment", # L10N: cli-venv-dest-help
)
venv.add_argument("profile", type=str, help="Profile to use for the environment")
venv.add_argument("dest", type=str, help="Path to the new virtual environment")
venv.add_argument(
"--name",
"-n",
type=str,
default=None,
help="Override the venv's name",
help="Override the venv's name", # L10N: cli-venv-name-help
)
venv.add_argument(
"--toolchain",
"-t",
type=str,
help="Specifier (atom) of the toolchain package to use",
help="Specifier (atom) of the toolchain package to use", # L10N: cli-venv-toolchain-help
)
venv.add_argument(
"--emulator",
"-e",
type=str,
help="Specifier (atom) of the emulator package to use",
help="Specifier (atom) of the emulator package to use", # L10N: cli-venv-emulator-help
)
venv.add_argument(
"--with-sysroot",
action="store_true",
dest="with_sysroot",
default=True,
help="Provision a fresh sysroot inside the new virtual environment (default)",
help="Provision a fresh sysroot inside the new virtual environment (default)", # L10N: cli-venv-with-sysroot-help
)
venv.add_argument(
"--without-sysroot",
action="store_false",
dest="with_sysroot",
help="Do not include a sysroot inside the new virtual environment",
help="Do not include a sysroot inside the new virtual environment", # L10N: cli-venv-without-sysroot-help
)
venv.add_argument(
"--sysroot-from",
type=str,
help="Specifier (atom) of the sysroot package to use, in favor of the toolchain-included one if applicable",
help="Specifier (atom) of the sysroot package to use, in favor of the toolchain-included one if applicable", # L10N: cli-venv-sysroot-from-help
)
venv.set_defaults(func=cli_venv)

Expand All @@ -219,71 +238,71 @@ def init_argparse() -> argparse.ArgumentParser:
"admin",
# https://github.com/python/cpython/issues/67037
# help=argparse.SUPPRESS,
help="(NOT FOR REGULAR USERS) Subcommands for managing Ruyi repos",
help="(NOT FOR REGULAR USERS) Subcommands for managing Ruyi repos", # L10N: cli-admin-help
)
admin.set_defaults(func=lambda _: admin.print_help())
adminsp = admin.add_subparsers(
title="subcommands",
title="subcommands", # L10N: cli-subcommands
)

admin_manifest = adminsp.add_parser(
"manifest",
help="Generate manifest for the distfiles given",
help="Generate manifest for the distfiles given", # L10N: cli-admin-manifest-help
)
admin_manifest.add_argument(
"--format",
"-f",
type=str,
choices=["json", "toml"],
default="json",
help="Format of manifest to generate",
help="Format of manifest to generate", # L10N: cli-admin-manifest-format-help
)
admin_manifest.add_argument(
"--restrict",
type=str,
default="",
help="the 'restrict' field to use for all mentioned distfiles, separated with comma",
help="the 'restrict' field to use for all mentioned distfiles, separated with comma", # L10N: cli-admin-manifest-restrict-help
)
admin_manifest.add_argument(
"file",
type=str,
nargs="+",
help="Path to the distfile(s) to generate manifest for",
help="Path to the distfile(s) to generate manifest for", # L10N: cli-admin-manifest-file-help
)
admin_manifest.set_defaults(func=cli_admin_manifest)

# Self-management commands
self = sp.add_parser(
"self",
help="Manage this Ruyi installation",
help="Manage this Ruyi installation", # L10N: cli-self-help
)
self.set_defaults(func=lambda _: self.print_help())
selfsp = self.add_subparsers(
title="subcommands",
title="subcommands", # L10N: cli-subcommands
)

self_uninstall = selfsp.add_parser(
"uninstall",
help="Uninstall Ruyi",
help="Uninstall Ruyi", # L10N: cli-self-uninstall-help
)
self_uninstall.add_argument(
"--purge",
action="store_true",
help="Remove all installed packages and Ruyi-managed remote repo data",
help="Remove all installed packages and Ruyi-managed remote repo data", # L10N: cli-self-uninstall-purge-help
)
self_uninstall.add_argument(
"-y",
action="store_true",
dest="consent",
help="Give consent for uninstallation on CLI; do not ask for confirmation",
help="Give consent for uninstallation on CLI; do not ask for confirmation", # L10N: cli-self-uninstall-yes-help
)
self_uninstall.set_defaults(func=cli_self_uninstall)

# Version info
# Keep this at the bottom
version = sp.add_parser(
"version",
help="Print version information",
help="Print version information", # L10N: cli-version-help
)
version.set_defaults(func=cli_version)

Expand Down
20 changes: 10 additions & 10 deletions ruyi/cli/self_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Note that your [yellow]Ruyi[/yellow] virtual environments [bold]will become unusable[/bold] after
[yellow]Ruyi[/yellow] is uninstalled. You should take care of migrating or cleaning
them yourselves afterwards.
"""
""" # L10N: uninstall-notice


def cli_self_uninstall(args: argparse.Namespace) -> int:
Expand All @@ -27,38 +27,38 @@ def cli_self_uninstall(args: argparse.Namespace) -> int:

if not ruyi.IS_PACKAGED:
log.F(
"this [yellow]ruyi[/yellow] is not in standalone form, and cannot be uninstalled this way"
"this [yellow]ruyi[/yellow] is not in standalone form, and cannot be uninstalled this way" # L10N: uninstall-fatal-non-standalone-installation
)
return 1

if not consent:
log.stdout(UNINSTALL_NOTICE)
if not user_input.ask_for_yesno_confirmation("Continue?"):
log.I("aborting uninstallation")
if not user_input.ask_for_yesno_confirmation("Continue?"): # L10N: uninstall-prompt-continue
log.I("aborting uninstallation") # L10N: uninstall-aborting
return 0
else:
log.I("uninstallation consent given over CLI, proceeding")
log.I("uninstallation consent given over CLI, proceeding") # L10N: uninstall-cli-consent

if purge:
cfg = config.GlobalConfig.load_from_config()

log.I("removing installed packages")
log.I("removing installed packages") # L10N: uninstall-removing-packages
shutil.rmtree(cfg.data_root, True)

log.I("removing state data")
log.I("removing state data") # L10N: uninstall-removing-state
shutil.rmtree(cfg.state_root, True)

log.I("removing cached data")
log.I("removing cached data") # L10N: uninstall-removing-cache
shutil.rmtree(cfg.cache_root, True)

log.I("removing the ruyi binary")
log.I("removing the ruyi binary") # L10N: uninstall-removing-binary
try:
os.unlink(ruyi.self_exe())
except FileNotFoundError:
# we might have already removed ourselves during the purge; nothing to
# do now.
pass

log.I("[yellow]ruyi[/yellow] is uninstalled")
log.I("[yellow]ruyi[/yellow] is uninstalled") # L10N: uninstall-done

return 0
4 changes: 2 additions & 2 deletions ruyi/cli/user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def ask_for_yesno_confirmation(prompt: str, default: bool = False) -> bool:
user_input = input()
except EOFError:
yesno = "YES" if default else "NO"
log.W(f"EOF while reading user input, assuming the default choice {yesno}")
log.W(f"EOF while reading user input, assuming the default choice {yesno}") # L10N: yesno-prompt-eof
return default

if not user_input:
Expand All @@ -22,7 +22,7 @@ def ask_for_yesno_confirmation(prompt: str, default: bool = False) -> bool:
if user_input in {"N", "n", "no"}:
return False
else:
log.stdout(f"Unrecognized input [yellow]'{user_input}'[/yellow].")
log.stdout(f"Unrecognized input [yellow]'{user_input}'[/yellow].") # L10N: yesno-prompt-unrecognized-input
log.stdout("Accepted choices: Y/y/yes for YES, N/n/no for NO.")


Expand Down
Loading

0 comments on commit 7713b5c

Please sign in to comment.