[projects/pld-ftp-admin] clean-dups.py: indent with spaces, drop the commented-out ignore list
arekm
arekm at pld-linux.org
Sat Nov 21 10:42:57 CET 2026
commit 42e11619bd4f3c9677de59f90df630924aa8d214
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sat Nov 21 01:36:53 2026 +0100
clean-dups.py: indent with spaces, drop the commented-out ignore list
No change in what it does: the parsed code is the same.
wwwbin/clean-dups.py | 170 +++++++++++++++++++++------------------------------
1 file changed, 71 insertions(+), 99 deletions(-)
---
diff --git a/wwwbin/clean-dups.py b/wwwbin/clean-dups.py
index 4982bc4..7d3eaa5 100755
--- a/wwwbin/clean-dups.py
+++ b/wwwbin/clean-dups.py
@@ -1,6 +1,7 @@
#!/usr/bin/python3
+# vi: ts=8 sts=4 sw=4 et
# arekm, 2008
-# remove
+# remove the older versions of packages from the test tree
import argparse
import functools
@@ -28,81 +29,52 @@ re_nvr = re.compile(r'^(.*)-([^-]*)-([^-]*)\.rpm$')
dir = '/home/pld/admins/th/ftp/test/SRPMS/RPMS'
ignore = re.compile(r'^(kernel-.*)$')
-#|\
-#crash-.*|\
-#dahdi-linux-.*|\
-#e1000e-.*|\
-#igb-.*|\
-#ipset-.*|\
-#iscsitarget-.*|\
-#ixgbe-.*|\
-#kernel-net-wl-.*|\
-#lin_tape-.*|\
-#linux-fusion-.*|\
-#linuxrdac-.*|\
-#lirc-.*|\
-#lttng-modules-.*|\
-#madwifi-ng-.*|\
-#nvidiabl-.*|\
-#open-vm-tools-.*|\
-#openvswitch-.*|\
-#r8168-.*|\
-#spl-.*|\
-#tpm_emulator-.*|\
-#VirtualBox-.*|\
-#vpb-driver-.*|\
-#xorg-driver-video-fglrx-.*|\
-#xorg-driver-video-fglrx-legacy-.*|\
-#xorg-driver-video-nvidia-.*|\
-#xorg-driver-video-nvidia-legacy3-.*|\
-#xorg-driver-video-nvidia-legacy-304xx-.*|\
-#xtables-addons-.*)$')
ts = rpm.TransactionSet("", (rpm.RPMVSF_NOHDRCHK | rpm.RPMVSF_NEEDPAYLOAD | rpm.RPMVSF_MASK_NODIGESTS | rpm.RPMVSF_MASK_NOSIGNATURES))
class CompareError(Exception):
- pass
+ pass
def compare(f1, f2):
- try:
- fd1 = os.open(os.path.join(dir, f1), os.O_RDONLY)
- except OSError as e:
- raise CompareError(e)
- try:
- fd2 = os.open(os.path.join(dir, f2), os.O_RDONLY)
- except OSError as e:
- os.close(fd1)
- raise CompareError(e)
- try:
- h1 = ts.hdrFromFdno(fd1)
- except (rpm.error, OSError) as e:
- os.close(fd1)
- os.close(fd2)
- raise CompareError(f"hdrFromFdno for {f1} failed: {e}")
-
- try:
- h2 = ts.hdrFromFdno(fd2)
- except (rpm.error, OSError) as e:
- os.close(fd1)
- os.close(fd2)
- raise CompareError(f"hdrFromFdno for {f2} failed: {e}")
-
- os.close(fd1)
- os.close(fd2)
-
- try:
- l1 = rpm.versionCompare(h1, h2)
- except ValueError:
- l1 = -1
- try:
- l2 = rpm.versionCompare(h2, h1)
- except ValueError:
- l2 = -1
-
- if l1 > 0 and l2 > 0:
- return 0
-
- return -l1
+ try:
+ fd1 = os.open(os.path.join(dir, f1), os.O_RDONLY)
+ except OSError as e:
+ raise CompareError(e)
+ try:
+ fd2 = os.open(os.path.join(dir, f2), os.O_RDONLY)
+ except OSError as e:
+ os.close(fd1)
+ raise CompareError(e)
+ try:
+ h1 = ts.hdrFromFdno(fd1)
+ except (rpm.error, OSError) as e:
+ os.close(fd1)
+ os.close(fd2)
+ raise CompareError(f"hdrFromFdno for {f1} failed: {e}")
+
+ try:
+ h2 = ts.hdrFromFdno(fd2)
+ except (rpm.error, OSError) as e:
+ os.close(fd1)
+ os.close(fd2)
+ raise CompareError(f"hdrFromFdno for {f2} failed: {e}")
+
+ os.close(fd1)
+ os.close(fd2)
+
+ try:
+ l1 = rpm.versionCompare(h1, h2)
+ except ValueError:
+ l1 = -1
+ try:
+ l2 = rpm.versionCompare(h2, h1)
+ except ValueError:
+ l2 = -1
+
+ if l1 > 0 and l2 > 0:
+ return 0
+
+ return -l1
def find_old(files):
@@ -122,35 +94,35 @@ files = {}
dupes = {}
for file in os.listdir(dir):
- if not re_rpm.match(file):
- continue
-
- if ignore.match(file):
- continue
-
- m = re_nvr.match(file)
- if not m:
- print(f"problem with: {file}")
- sys.exit(1)
-
- 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)
-
- if name in files:
- if name in dupes:
- dupes[name].append(file)
- else:
- dupes[name] = [ files[name] ]
- dupes[name].append(file)
- else:
- files[name] = file
+ if not re_rpm.match(file):
+ continue
+
+ if ignore.match(file):
+ continue
+
+ m = re_nvr.match(file)
+ if not m:
+ print(f"problem with: {file}")
+ sys.exit(1)
+
+ 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)
+
+ if name in files:
+ if name in dupes:
+ dupes[name].append(file)
+ else:
+ dupes[name] = [ files[name] ]
+ dupes[name].append(file)
+ else:
+ files[name] = file
ftp_tree = "test"
ftpio.connect('clean-dups')
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/a049a512859eaede288d71649a2320e16c959476
More information about the pld-cvs-commit
mailing list