X-Git-Url: https://git.tld-linux.org/?p=tld-ftp-admin.git;a=blobdiff_plain;f=wwwbin%2Fclean-dups-archive.py;fp=wwwbin%2Fclean-dups-archive.py;h=0000000000000000000000000000000000000000;hp=4961c399c94ea84b817d0917bf20f50fa70079f8;hb=f7b22268ab563fa906be0653d037f1805e220e5c;hpb=b7b854ca43601a08077b7c4c4fa1313a198d936a diff --git a/wwwbin/clean-dups-archive.py b/wwwbin/clean-dups-archive.py deleted file mode 100755 index 4961c39..0000000 --- a/wwwbin/clean-dups-archive.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/python -# arekm, 2008 -# remove - -import os -import re -import time -import rpm -import sys - -re_rpm = re.compile(r'.*\.rpm$') -re_nvr = re.compile('^(.*)-([^-]*)-([^-]*)\.rpm$') -dir = '/home/pld/admins/th/ftp/.archive/PLD/SRPMS/RPMS' - -ts = rpm.TransactionSet("", (rpm.RPMVSF_NOHDRCHK or rpm.RPMVSF_NEEDPAYLOAD)) - -def compare(f1, f2): - try: - fd1 = os.open(os.path.join(dir, f1), os.O_RDONLY) - except Exception, e: - print e - # ignore non-files - return 0 - try: - fd2 = os.open(os.path.join(dir, f2), os.O_RDONLY) - except Exception, e: - print e - # ignore non-files - return 0 - h1 = ts.hdrFromFdno(fd1) - h2 = ts.hdrFromFdno(fd2) - os.close(fd1) - os.close(fd2) - - l1 = rpm.versionCompare(h1, h2) - l2 = rpm.versionCompare(h2, h1) - - if l1 > 0 and l2 > 0: - return 0 - - return -l1 - - -def find_old(files): - return sorted(files, compare) - -files = {} -dupes = {} - -for file in os.listdir(dir): - if not re_rpm.match(file): - continue - - m = re_nvr.match(file) - if not m: - print "problem with: %s" % 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: - continue - - name = m.group(1) - - if files.has_key(name): - if dupes.has_key(name): - dupes[name].append(file) - else: - dupes[name] = [ files[name] ] - dupes[name].append(file) - else: - files[name] = file - -for i in dupes.iterkeys(): - for old in find_old(dupes[i])[1:]: - os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py .archive/PLD %s" % old)