Remove unused clan history update subcommand
This commit is contained in:
@@ -3,7 +3,6 @@ import argparse
|
||||
|
||||
from .add import register_add_parser
|
||||
from .list import register_list_parser
|
||||
from .update import register_update_parser
|
||||
|
||||
|
||||
# takes a (sub)parser and configures it
|
||||
@@ -18,5 +17,3 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
|
||||
register_add_parser(add_parser)
|
||||
list_parser = subparser.add_parser("list", help="List recently used flakes")
|
||||
register_list_parser(list_parser)
|
||||
update_parser = subparser.add_parser("update", help="Update a clan flake")
|
||||
register_update_parser(update_parser)
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
# !/usr/bin/env python3
|
||||
import argparse
|
||||
import datetime
|
||||
|
||||
from clan_cli.clan.inspect import inspect_flake
|
||||
from clan_cli.clan_uri import ClanURI
|
||||
from clan_cli.errors import ClanCmdError
|
||||
from clan_cli.locked_open import write_history_file
|
||||
from clan_cli.nix import nix_metadata
|
||||
|
||||
from .add import HistoryEntry, list_history
|
||||
|
||||
|
||||
def update_history() -> list[HistoryEntry]:
|
||||
logs = list_history()
|
||||
|
||||
for entry in logs:
|
||||
try:
|
||||
meta = nix_metadata(str(entry.flake.flake_url))
|
||||
except ClanCmdError as e:
|
||||
print(f"Failed to update {entry.flake.flake_url}: {e}")
|
||||
continue
|
||||
|
||||
new_hash = meta["locked"]["narHash"]
|
||||
if new_hash != entry.flake.nar_hash:
|
||||
print(
|
||||
f"Updating {entry.flake.flake_url} from {entry.flake.nar_hash} to {new_hash}"
|
||||
)
|
||||
uri = ClanURI.from_str(
|
||||
url=str(entry.flake.flake_url),
|
||||
machine_name=entry.flake.flake_attr,
|
||||
)
|
||||
flake = inspect_flake(uri.get_url(), uri.machine_name)
|
||||
flake.flake_url = flake.flake_url
|
||||
entry = HistoryEntry(
|
||||
flake=flake,
|
||||
last_used=datetime.datetime.now(tz=datetime.UTC).isoformat(),
|
||||
)
|
||||
|
||||
write_history_file(logs)
|
||||
return logs
|
||||
|
||||
|
||||
def add_update_command(args: argparse.Namespace) -> None:
|
||||
update_history()
|
||||
|
||||
|
||||
# takes a (sub)parser and configures it
|
||||
def register_update_parser(parser: argparse.ArgumentParser) -> None:
|
||||
parser.set_defaults(func=add_update_command)
|
||||
Reference in New Issue
Block a user