[projects/pld-ftp-admin] Use library calls for removing files in clean-dups
baggins
baggins at pld-linux.org
Sat Feb 7 13:56:45 CET 2026
commit 39b6ac0d9eac05942ac6eaf20d474a704de7a448
Author: Jan Rękorajski <baggins at pld-linux.org>
Date: Sat Feb 7 13:54:51 2026 +0100
Use library calls for removing files in clean-dups
Also make the code more pythonic.
Coverting dict keys to index and using that to iterate over the same dict? Really...
wwwbin/clean-dups.py | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/wwwbin/clean-dups.py b/wwwbin/clean-dups.py
index d7f3c82..9398d22 100755
--- a/wwwbin/clean-dups.py
+++ b/wwwbin/clean-dups.py
@@ -11,6 +11,11 @@ import time
import rpm
import sys
+sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
+import ftptree
+from common import checkdir
+import ftpio
+
re_rpm = re.compile(r'.*\.rpm$')
re_nvr = re.compile(r'^(.*)-([^-]*)-([^-]*)\.rpm$')
dir = '/home/pld/admins/th/ftp/test/SRPMS/RPMS'
@@ -96,7 +101,7 @@ def compare(f1, f2):
def find_old(files):
- return sorted(files, key=functools.cmp_to_key(compare))
+ return sorted(files, key=functools.cmp_to_key(compare))[1:]
files = {}
dupes = {}
@@ -130,7 +135,23 @@ for file in os.listdir(dir):
else:
files[name] = file
-for i in iter(dupes.keys()):
- for old in find_old(dupes[i])[1:]:
- print("removing: %s" % old)
- os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py test %s" % old)
+ftp_tree = "test"
+ftpio.connect('clean-dups')
+
+if not ftpio.lock(ftp_tree, True):
+ print("ERR: %s tree already locked" % ftp_tree)
+ sys.exit(1)
+
+try:
+ tree=ftptree.FtpTree(ftp_tree)
+ #tree.do_checkbuild=False
+ list(find_old(old) for old in dupes.values())
+ tree.mark4removal(pkgs)
+ print(f"removing: {pkg}") for pkg in pkgs
+ tree.removepkgs()
+except ftptree.SomeError:
+ # In case of problems we need to unlock the tree before exiting
+ ftpio.unlock(ftp_tree)
+ sys.exit(1)
+
+ftpio.unlock(ftp_tree)
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/39b6ac0d9eac05942ac6eaf20d474a704de7a448
More information about the pld-cvs-commit
mailing list