]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - wwwbin/clean-dups-old.py
Add filter-out feature to rpmqa query page (adamg?)
[projects/pld-ftp-admin.git] / wwwbin / clean-dups-old.py
CommitLineData
ed1ec331
ER
1#!/usr/bin/python
2# arekm, 2008
3# remove
4
94960bbc
JR
5from __future__ import print_function
6
ed1ec331
ER
7import os
8import re
9import time
10import rpm
11import sys
12
13re_info = re.compile(r'.*\.info$')
14re_nvr = re.compile('^(.*)-([^-]*)-([^-]*)\.info$')
15dir = '/home/pld/admins/th/ftp/test/SRPMS/.metadata'
16
17def 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
37def find_old(files):
38 return sorted(files, compare)
39
40files = {}
41dupes = {}
42
43for 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:
94960bbc 49 print("problem with: %s" % file)
ed1ec331
ER
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
94960bbc 69for i in iter(dupes.keys()):
ed1ec331
ER
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.14694 seconds and 4 git commands to generate.