Skip to content

Commit

Permalink
feat(cli): support ruyi self clean --news-read-status
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0n committed Oct 25, 2024
1 parent 563955e commit 549e58b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ruyi/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,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",
Expand Down
10 changes: 9 additions & 1 deletion ruyi/cli/self_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ def cli_self_clean(cfg: config.GlobalConfig, args: argparse.Namespace) -> int:
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 all:
distfiles = True
installed_pkgs = True
news_read_status = True
progcache = True
repo = True
telemetry = True

if not any([distfiles, installed_pkgs, progcache, repo, telemetry]):
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"
Expand All @@ -49,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,
Expand Down Expand Up @@ -103,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
Expand All @@ -123,6 +127,10 @@ 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
Expand Down
6 changes: 6 additions & 0 deletions ruyi/config/news.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os


class NewsReadStatusStore:
def __init__(self, path: str) -> None:
self._path = path
Expand Down Expand Up @@ -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)

0 comments on commit 549e58b

Please sign in to comment.