# HG changeset patch # User Ludovic Chabant # Date 1703636795 28800 # Node ID 412ff72ba091fef315d094b26f119c11bdde9d88 # Parent d76063c61c6dbd9d9eb8ebba3df292b0a45ec34e Add utility command to forget parts of the cache. diff -r d76063c61c6d -r 412ff72ba091 silorider/commands/utils.py --- a/silorider/commands/utils.py Tue Dec 26 16:25:51 2023 -0800 +++ b/silorider/commands/utils.py Tue Dec 26 16:26:35 2023 -0800 @@ -87,3 +87,19 @@ ctx.cache.addPost(silo.name, entry_url) else: logger.debug("Would add entry to '%s' cache: %s" % (silo.name, entry_url)) + + +def forget_cache(ctx): + named_urls = get_named_urls(ctx.config, ctx.args.url) + + since_dt = None + until_dt = None + if ctx.args.since: + since_dt = dateutil.parser.parse(ctx.args.since) + logger.debug("Forgetting cached entries since: %s" % since_dt) + since_dt = since_dt.timestamp() + if ctx.args.until: + until_dt = dateutil.parser.parse(ctx.args.until) + logger.debug("Forgetting cached entries until: %s" % until_dt) + until_dt = until_dt.timestamp() + diff -r d76063c61c6d -r 412ff72ba091 silorider/main.py --- a/silorider/main.py Tue Dec 26 16:25:51 2023 -0800 +++ b/silorider/main.py Tue Dec 26 16:26:35 2023 -0800 @@ -93,6 +93,28 @@ parser.set_defaults(func=_run) +def _setup_forget(parser): + def _run(ctx): + from .commands.utils import forget_cache + forget_cache(ctx) + + parser.add_argument( + '-s', '--silo', + action='append', + help="Only froget entries from the given silo(s).") + parser.add_argument( + '--since', + help="The date after which to forget entries from the cache (excluded).") + parser.add_argument( + '--until', + help="The date until which to forget entries from the cache (excluded).") + parser.add_argument( + '--dry-run', + action='store_true', + help="Only report what would be forgotten, but don't forget anything.") + parser.set_defaults(func=_run) + + commands = { 'auth': { 'help': "Authenticate with a silo service.", @@ -105,6 +127,10 @@ 'populate': { 'help': "Populates the cache with the latest entries from a feed.", 'setup': _setup_populate, + }, + 'forget': { + 'help': "Forget entries from the cache, so they can be reposted.", + 'setup': _setup_forget, } }