changeset 65:412ff72ba091

Add utility command to forget parts of the cache.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 26 Dec 2023 16:26:35 -0800
parents d76063c61c6d
children 4caf6720d1dd
files silorider/commands/utils.py silorider/main.py
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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()
+
--- 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,
     }
 }