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