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/test/SRPMS/RPMS'
17 ignore = re.compile('^(kernel-.*)$')
41 #xorg-driver-video-fglrx-.*|\
42 #xorg-driver-video-fglrx-legacy-.*|\
43 #xorg-driver-video-nvidia-.*|\
44 #xorg-driver-video-nvidia-legacy3-.*|\
45 #xorg-driver-video-nvidia-legacy-304xx-.*|\
46 #xtables-addons-.*)$')
48 ts = rpm.TransactionSet("", (rpm.RPMVSF_NOHDRCHK or rpm.RPMVSF_NEEDPAYLOAD))
52 fd1 = os.open(os.path.join(dir, f1), os.O_RDONLY)
53 except Exception as e:
58 fd2 = os.open(os.path.join(dir, f2), os.O_RDONLY)
59 except Exception as e:
64 h1 = ts.hdrFromFdno(fd1)
65 except Exception as e:
66 print("hdrFromFdno for %s failed: %s" % (f1, e))
72 h2 = ts.hdrFromFdno(fd2)
73 except Exception as e:
74 print("hdrFromFdno for %s failed: %s" % (f2, e))
82 l1 = rpm.versionCompare(h1, h2)
83 l2 = rpm.versionCompare(h2, h1)
92 return sorted(files, compare)
97 for file in os.listdir(dir):
98 if not re_rpm.match(file):
101 if ignore.match(file):
104 m = re_nvr.match(file)
106 print("problem with: %s" % file)
109 if len(sys.argv) == 0:
110 p = os.path.join(dir, file)
111 mtime = os.stat(p).st_mtime
112 if mtime > time.time() - 3*86400:
117 if files.has_key(name):
118 if dupes.has_key(name):
119 dupes[name].append(file)
121 dupes[name] = [ files[name] ]
122 dupes[name].append(file)
126 for i in iter(dupes.keys()):
127 for old in find_old(dupes[i])[1:]:
128 print("removing: %s" % old)
129 os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py test %s" % old)