]>
Commit | Line | Data |
---|---|---|
ed1ec331 ER |
1 | #!/usr/bin/python |
2 | # arekm, 2008 | |
3 | # remove | |
4 | ||
5 | import os | |
6 | import re | |
7 | import time | |
8 | import rpm | |
9 | import sys | |
10 | ||
11 | re_info = re.compile(r'.*\.info$') | |
12 | re_nvr = re.compile('^(.*)-([^-]*)-([^-]*)\.info$') | |
13 | dir = '/home/pld/admins/th/ftp/test/SRPMS/.metadata' | |
14 | ||
15 | def compare(f1, f2): | |
16 | m1 = re_nvr.match(f1) | |
17 | n1 = m1.group(1) | |
18 | v1 = m1.group(2) | |
19 | r1 = m1.group(3) | |
20 | ||
21 | m2 = re_nvr.match(f2) | |
22 | n2 = m2.group(1) | |
23 | v2 = m2.group(2) | |
24 | r2 = m2.group(3) | |
25 | ||
26 | l1 = rpm.labelCompare((n1, v1, r1), (n2, v2, r2)) | |
27 | l2 = rpm.labelCompare((n2, v2, r2), (n1, v1, r1)) | |
28 | ||
29 | if l1 > 0 and l2 > 0: | |
30 | return 0 | |
31 | ||
32 | return -l1 | |
33 | ||
34 | ||
35 | def find_old(files): | |
36 | return sorted(files, compare) | |
37 | ||
38 | files = {} | |
39 | dupes = {} | |
40 | ||
41 | for file in os.listdir(dir): | |
42 | if not re_info.match(file): | |
43 | continue | |
44 | ||
45 | m = re_nvr.match(file) | |
46 | if not m: | |
47 | print "problem with: %s" % file | |
48 | sys.exit(1) | |
49 | ||
50 | if len(sys.argv) == 0: | |
51 | p = os.path.join(dir, file) | |
52 | mtime = os.stat(p).st_mtime | |
53 | if mtime > time.time() - 3*86400: | |
54 | continue | |
55 | ||
56 | name = m.group(1) | |
57 | ||
58 | if files.has_key(name): | |
59 | if dupes.has_key(name): | |
60 | dupes[name].append(file) | |
61 | else: | |
62 | dupes[name] = [ files[name] ] | |
63 | dupes[name].append(file) | |
64 | else: | |
65 | files[name] = file | |
66 | ||
67 | for i in dupes.iterkeys(): | |
68 | for old in find_old(dupes[i])[1:]: | |
69 | os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py test %s" % old) |