diff --git a/ruyi/cli/__init__.py b/ruyi/cli/__init__.py index 3848347..7670312 100644 --- a/ruyi/cli/__init__.py +++ b/ruyi/cli/__init__.py @@ -317,6 +317,11 @@ def init_argparse() -> argparse.ArgumentParser: action="store_true", help="Do not print out the actions being performed", ) + self_clean.add_argument( + "--all", + action="store_true", + help="Remove all covered data", + ) self_clean.add_argument( "--distfiles", action="store_true", @@ -327,6 +332,11 @@ def init_argparse() -> argparse.ArgumentParser: action="store_true", help="Remove all installed packages if any", ) + self_clean.add_argument( + "--news-read-status", + action="store_true", + help="Mark all news items as unread", + ) self_clean.add_argument( "--progcache", action="store_true", diff --git a/ruyi/cli/self_cli.py b/ruyi/cli/self_cli.py index 732e29d..ab30c93 100644 --- a/ruyi/cli/self_cli.py +++ b/ruyi/cli/self_cli.py @@ -23,13 +23,23 @@ def cli_self_clean(cfg: config.GlobalConfig, args: argparse.Namespace) -> int: quiet: bool = args.quiet + all: bool = args.all distfiles: bool = args.distfiles installed_pkgs: bool = args.installed_pkgs + news_read_status: bool = args.news_read_status progcache: bool = args.progcache repo: bool = args.repo telemetry: bool = args.telemetry - if not any([distfiles, installed_pkgs, progcache, repo, telemetry]): + if all: + distfiles = True + installed_pkgs = True + news_read_status = True + progcache = True + repo = True + telemetry = True + + if not any([distfiles, installed_pkgs, news_read_status, progcache, repo, telemetry]): log.F("no data specified for cleaning") log.I( "please check [yellow]ruyi self clean --help[/] for a list of cleanable data" @@ -41,6 +51,7 @@ def cli_self_clean(cfg: config.GlobalConfig, args: argparse.Namespace) -> int: quiet=quiet, distfiles=distfiles, installed_pkgs=installed_pkgs, + news_read_status=news_read_status, progcache=progcache, repo=repo, telemetry=telemetry, @@ -75,10 +86,6 @@ def cli_self_uninstall(cfg: config.GlobalConfig, args: argparse.Namespace) -> in else: log.I("uninstallation consent given over CLI, proceeding") - if tm := cfg.telemetry: - # do not record any telemetry data if we're purging all data with us - tm.discard_events(purge) - _do_reset( cfg, quiet=False, @@ -99,6 +106,7 @@ def _do_reset( *, installed_pkgs: bool = False, all_state: bool = False, + news_read_status: bool = False, # ignored if all_state=True telemetry: bool = False, # ignored if all_state=True all_cache: bool = False, distfiles: bool = False, # ignored if all_cache=True @@ -119,7 +127,15 @@ def status(s: str) -> None: status("removing state data") shutil.rmtree(cfg.state_root, True) else: + if news_read_status: + status("removing read status of news items") + cfg.news_read_status.remove() + if telemetry: + if tm := cfg.telemetry: + # do not record any telemetry data if we're purging it + tm.discard_events(True) + status("removing all telemetry data") shutil.rmtree(cfg.telemetry_root, True) diff --git a/ruyi/config/news.py b/ruyi/config/news.py index 0ef9d38..e00d805 100644 --- a/ruyi/config/news.py +++ b/ruyi/config/news.py @@ -1,3 +1,6 @@ +import os + + class NewsReadStatusStore: def __init__(self, path: str) -> None: self._path = path @@ -27,3 +30,6 @@ def save(self) -> None: content = "".join(f"{id}\n" for id in self._status) with open(self._path, "w", encoding="utf-8") as fp: fp.write(content) + + def remove(self) -> None: + os.unlink(self._path)