distfile-cleaner: add --user argument
authorSofian Brabez <sbz@6dev.net>
Thu, 10 Jun 2021 12:55:30 +0000 (13:55 +0100)
committersbz <sbz@6dev.net>
Thu, 10 Jun 2021 12:55:30 +0000 (13:55 +0100)
If run as root, it will be possible to prune the old and non needed
anymore distfiles of others committers to reclaim space on freefall.

distfile-cleaner.py

index 605d6d700e39042db214617ff59098421900be5f..6551638c9b8bb8bcf36e1e0c7a6b0db16b030b18 100755 (executable)
@@ -117,21 +117,34 @@ def main() -> int:
     )
 
     parser.add_argument(
-        "-n", "--dryrun", action='store_true'
+        "-n", "--dryrun", action='store_true',
         help="Dry run mode. Do not execute remote command"
     )
+
     parser.add_argument(
         "-m", "--max-year", type=int,
         help="Maximum year to keep the files"
     )
 
+    parser.add_argument(
+        "-u", "--user", type=str,
+        help="Run as user"
+    )
+
     args = parser.parse_args()
     if args.max_year:
         MAX_KEEP_YEAR = args.max_year
 
-    checker = Checker()
+    kwargs = {}
+
+    if args.user:
+        kwargs.update(user=args.user)
+
     if args.dryrun:
-        checker = Checker(dryrun=True)
+        kwargs.update(user=args.user)
+        kwargs.update(dryrun=True)
+
+    checker = Checker(**kwargs)
 
     print(f"[+] Process files older than {MAX_KEEP_YEAR} year old")
     if not checker.clean_files():