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:
33 h1 = ts.hdrFromFdno(fd1)
34 except Exception as e:
35 print("hdrFromFdno for %s failed: %s" % (f1, e))
40 h2 = ts.hdrFromFdno(fd2)
41 except Exception as e:
42 print("hdrFromFdno for %s failed: %s" % (f1, e))
50 l1 = rpm.versionCompare(h1, h2)
54 l2 = rpm.versionCompare(h2, h1)
65 return sorted(files, compare)
70 for file in os.listdir(dir):
71 if not re_rpm.match(file):
74 m = re_nvr.match(file)
76 print("problem with: %s" % file)
79 if len(sys.argv) == 0:
80 p = os.path.join(dir, file)
81 mtime = os.stat(p).st_mtime
82 if mtime > time.time() - 3*86400:
87 if files.has_key(name):
88 if dupes.has_key(name):
89 dupes[name].append(file)
91 dupes[name] = [ files[name] ]
92 dupes[name].append(file)
96 for i in iter(dupes.keys()):
97 for old in find_old(dupes[i])[1:]:
98 os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py .archive/PLD %s" % old)