-
Notifications
You must be signed in to change notification settings - Fork 7
/
dated-packages
executable file
·77 lines (55 loc) · 1.61 KB
/
dated-packages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
import os
import os.path
import sys
import time
from pisi.specfile import SpecFile
SUCCESS, FAIL = xrange(2)
def isExpired(date, days):
diff = time.time() - time.mktime(time.strptime(date, '%Y-%m-%d'))
secs = 60 * 60 * 24 * days
return diff > secs
def getSpecs(folder):
specs = []
for root, dirs, files in os.walk(folder):
if 'pspec.xml' in files:
specs.append(root)
if '.svn' in dirs:
dirs.remove('.svn')
return specs
def main():
if len(sys.argv) != 3:
print 'Usage: %s repo-path [-]days' % sys.argv[0]
return FAIL
if not os.path.isdir(sys.argv[1]):
print 'Repo path is not valid.'
return FAIL
days = sys.argv[2]
revert = days[0] == '-'
if revert:
days = days[1:]
if not days.isdigit():
print 'Days must be integer.'
return FAIL
repopath = sys.argv[1]
days = int(days)
errors = []
for packagedir in getSpecs(repopath):
shortpath = '%s/pspec.xml' % packagedir[len(repopath):]
specfile = SpecFile(os.path.join(packagedir, 'pspec.xml'))
date = specfile.history[0].date
try:
expired = isExpired(date, days)
except ValueError:
errors.append('Invalid date: %s (%s)' % (shortpath, date))
continue
if (not revert and expired) or (revert and not expired):
print '%s %s' % (date, shortpath)
if len(errors):
print
print 'Errors:'
for e in errors:
print ' ', e
return SUCCESS
if __name__ == '__main__':
sys.exit(main())