]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - wwwbin/clean-dups-old.py
- import from ~pldth/bin
[projects/pld-ftp-admin.git] / wwwbin / clean-dups-old.py
CommitLineData
ed1ec331
ER
1#!/usr/bin/python
2# arekm, 2008
3# remove
4
5import os
6import re
7import time
8import rpm
9import sys
10
11re_info = re.compile(r'.*\.info$')
12re_nvr = re.compile('^(.*)-([^-]*)-([^-]*)\.info$')
13dir = '/home/pld/admins/th/ftp/test/SRPMS/.metadata'
14
15def 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
35def find_old(files):
36 return sorted(files, compare)
37
38files = {}
39dupes = {}
40
41for 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
67for 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)
This page took 0.410161 seconds and 4 git commands to generate.