5 from __future__ import print_function
14 re_rpm = re.compile(r'.*\.rpm$')
15 re_nvr = re.compile('^(.*)-([^-]*)-([^-]*)\.rpm$')
16 dir = '/home/pld/admins/th/ftp/test/SRPMS/RPMS'
18 ignore = re.compile('^(kernel-.*)$')
42 #xorg-driver-video-fglrx-.*|\
43 #xorg-driver-video-fglrx-legacy-.*|\
44 #xorg-driver-video-nvidia-.*|\
45 #xorg-driver-video-nvidia-legacy3-.*|\
46 #xorg-driver-video-nvidia-legacy-304xx-.*|\
47 #xtables-addons-.*)$')
49 ts = rpm.TransactionSet("", (rpm.RPMVSF_NOHDRCHK | rpm.RPMVSF_NEEDPAYLOAD | rpm.RPMVSF_MASK_NODIGESTS | rpm.RPMVSF_MASK_NOSIGNATURES))
53 fd1 = os.open(os.path.join(dir, f1), os.O_RDONLY)
54 except Exception as e:
59 fd2 = os.open(os.path.join(dir, f2), os.O_RDONLY)
60 except Exception as e:
65 h1 = ts.hdrFromFdno(fd1)
66 except Exception as e:
67 print("hdrFromFdno for %s failed: %s" % (f1, e))
73 h2 = ts.hdrFromFdno(fd2)
74 except Exception as e:
75 print("hdrFromFdno for %s failed: %s" % (f2, e))
84 l1 = rpm.versionCompare(h1, h2)
88 l2 = rpm.versionCompare(h2, h1)
99 return sorted(files, key=functools.cmp_to_key(compare))
104 for file in os.listdir(dir):
105 if not re_rpm.match(file):
108 if ignore.match(file):
111 m = re_nvr.match(file)
113 print("problem with: %s" % file)
116 if len(sys.argv) == 0:
117 p = os.path.join(dir, file)
118 mtime = os.stat(p).st_mtime
119 if mtime > time.time() - 3*86400:
126 dupes[name].append(file)
128 dupes[name] = [ files[name] ]
129 dupes[name].append(file)
133 for i in iter(dupes.keys()):
134 for old in find_old(dupes[i])[1:]:
135 print("removing: %s" % old)
136 os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py test %s" % old)