[projects/pld-ftp-admin] clean-dups.py: add --min-age to keep recent packages

arekm arekm at pld-linux.org
Sat Oct 24 11:47:31 CEST 2026


commit 353f8701133a450fdb98c2e500567837104c4814
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Tue Oct 20 17:35:51 2026 +0200

    clean-dups.py: add --min-age to keep recent packages
    
    The old 3-day filter never ran; it is now opt-in.

 wwwbin/clean-dups.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/wwwbin/clean-dups.py b/wwwbin/clean-dups.py
index 0e17c58..3a832f1 100755
--- a/wwwbin/clean-dups.py
+++ b/wwwbin/clean-dups.py
@@ -2,6 +2,7 @@
 # arekm, 2008
 # remove 
 
+import argparse
 import functools
 import os
 import re
@@ -10,6 +11,14 @@ import time
 
 import rpm
 
+parser = argparse.ArgumentParser(description='Remove older versions of packages from the test tree.')
+parser.add_argument('--min-age', type=int, default=0, metavar='DAYS',
+    help='ignore src.rpms younger than DAYS days, so the previous version stays until the new one is that old '
+         '(default: 0, remove at once)')
+args = parser.parse_args()
+cutoff = time.time() - args.min_age * 86400
+
+# config reads ~/.ftpadmrc on import; parse options first so --help works without it
 sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
 import ftpio
 import ftptree
@@ -124,10 +133,12 @@ for file in os.listdir(dir):
 		print(f"problem with: {file}")
 		sys.exit(1)
 
-	if len(sys.argv) == 0:
-		p = os.path.join(dir, file)
-		mtime = os.stat(p).st_mtime
-		if mtime > time.time() - 3*86400:
+	if args.min_age:
+		try:
+			if os.stat(os.path.join(dir, file)).st_mtime > cutoff:
+				continue
+		except FileNotFoundError:
+			# moved or removed since listdir(); the tree is locked only later
 			continue
 
 	name = m.group(1)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/e14cb7d4d74f8bdd9368d9645ecaf49593cf6335



More information about the pld-cvs-commit mailing list