]>
Commit | Line | Data |
---|---|---|
7b2ce93a AM |
1 | #!/usr/bin/python |
2 | ||
3 | import subprocess | |
4 | import sys | |
5 | import os | |
8445e70f | 6 | import fnmatch |
7b2ce93a | 7 | |
861e13b1 ER |
8 | if len(sys.argv) == 2: |
9 | spec = sys.argv[1] | |
10 | else: | |
11 | # try autodetecting | |
12 | spec = "%s.spec" % os.path.basename(os.getcwd()) | |
7b2ce93a AM |
13 | |
14 | if not os.path.isfile(spec): | |
15 | print >> sys.stderr, "%s: %s doesn't exist!" % (sys.argv[0], spec) | |
16 | sys.exit(1) | |
17 | ||
18 | dir = os.path.dirname(spec) | |
19 | if dir == '': | |
20 | dir = '.' | |
21 | ||
22 | p = subprocess.Popen(['rpm-specdump', spec], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
23 | (out, err) = p.communicate(None) | |
24 | p.wait() | |
e77c91c6 AM |
25 | if err: |
26 | print >> sys.stderr, "%s: %s" % (sys.argv[0], err) | |
27 | sys.exit(1) | |
7b2ce93a AM |
28 | |
29 | files = [] | |
30 | ||
31 | for l in out.split('\n'): | |
32 | data = l.split() | |
33 | if len(data) != 3 or data[0] != 's': | |
34 | continue | |
35 | file = os.path.basename(data[2]) | |
36 | files.append(file) | |
37 | ||
38 | obsolete = [] | |
39 | ||
b668f2cd ER |
40 | # files to exclude |
41 | exclude = ['log.*', '.#*', '*~', '*.orig', '*.sw?'] | |
42 | ||
43 | # read .cvsignore, distfiles files are filled there | |
44 | if os.path.isfile('%s/.cvsignore' % dir): | |
45 | f = open('%s/.cvsignore' % dir , 'r') | |
46 | for l in f.readlines(): | |
47 | exclude.append(l.rstrip()) | |
48 | ||
4f1efb15 ER |
49 | def cvs_entries(file): |
50 | f = open('%s/CVS/Entries' % dir , 'r') | |
51 | files = [] | |
52 | for l in f.readlines(): | |
53 | if l[0] != '/': | |
54 | continue | |
55 | parts = l.split('/') | |
56 | files.append(parts[1]) | |
57 | return files | |
58 | cvsfiles = cvs_entries(dir) | |
59 | ||
8445e70f | 60 | def blacklisted(file): |
84e1e6d0 ER |
61 | if file == os.path.basename(spec): |
62 | return True | |
63 | ||
b668f2cd | 64 | if file in [ '.', '..', 'CVS', 'TODO']: |
8445e70f ER |
65 | return True |
66 | ||
1e0688bb AM |
67 | if os.path.isdir(file): |
68 | return True | |
69 | ||
b668f2cd | 70 | for pat in exclude: |
8445e70f ER |
71 | if fnmatch.fnmatch(file, pat): |
72 | return True | |
73 | ||
74 | return False | |
75 | ||
76 | for file in os.listdir(dir): | |
77 | file = os.path.basename(file) | |
78 | if blacklisted(file): | |
82a3c8b3 | 79 | continue |
8445e70f | 80 | |
4f1efb15 ER |
81 | if not file in cvsfiles: |
82 | print "Not in cvs: %s" % file | |
83 | continue | |
84 | ||
7b2ce93a AM |
85 | if file not in files: |
86 | print "Obsolete file: %s" % file | |
87 | obsolete.append(file) | |
88 | ||
c7c88163 AM |
89 | if obsolete: |
90 | ||
91 | print "cvs rm -f %s" % " ".join(obsolete) | |
7998a6ff | 92 | print "cvs commit -m '- drop obsolete files' %s" % " ".join(obsolete) |