5 from __future__ import print_function
13 re_rpm = re.compile(r'.*\.rpm$')
14 re_nvr = re.compile('^(.*)-([^-]*)-([^-]*)\.rpm$')
15 dir = '/home/pld/admins/th/ftp/.archive/PLD/SRPMS/RPMS'
17 ts = rpm.TransactionSet("", (rpm.RPMVSF_NOHDRCHK or rpm.RPMVSF_NEEDPAYLOAD))
21 fd1 = os.open(os.path.join(dir, f1), os.O_RDONLY)
22 except Exception as e:
27 fd2 = os.open(os.path.join(dir, f2), os.O_RDONLY)
28 except Exception as e:
32 h1 = ts.hdrFromFdno(fd1)
33 h2 = ts.hdrFromFdno(fd2)
37 l1 = rpm.versionCompare(h1, h2)
38 l2 = rpm.versionCompare(h2, h1)
47 return sorted(files, compare)
52 for file in os.listdir(dir):
53 if not re_rpm.match(file):
56 m = re_nvr.match(file)
58 print("problem with: %s" % file)
61 if len(sys.argv) == 0:
62 p = os.path.join(dir, file)
63 mtime = os.stat(p).st_mtime
64 if mtime > time.time() - 3*86400:
69 if files.has_key(name):
70 if dupes.has_key(name):
71 dupes[name].append(file)
73 dupes[name] = [ files[name] ]
74 dupes[name].append(file)
78 for i in iter(dupes.keys()):
79 for old in find_old(dupes[i])[1:]:
80 os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py .archive/PLD %s" % old)