]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - check-unused-files.py
- skip dirs
[packages/rpm-build-tools.git] / check-unused-files.py
1 #!/usr/bin/python
2
3 import subprocess
4 import sys
5 import os
6 import fnmatch
7
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())
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()
25 if err:
26     print >> sys.stderr, "%s: %s" % (sys.argv[0], err)
27     sys.exit(1)
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
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
49 def blacklisted(file):
50     if file == os.path.basename(spec):
51         return True
52
53     if file in [ '.', '..', 'CVS', 'TODO']:
54         return True
55
56     if os.path.isdir(file):
57         return True
58
59     for pat in exclude:
60         if fnmatch.fnmatch(file, pat):
61             return True
62
63     return False
64
65
66 for file in os.listdir(dir):
67     file = os.path.basename(file)
68     if blacklisted(file):
69         continue
70
71     if file not in files:
72         print "Obsolete file: %s" % file
73         obsolete.append(file)
74
75 if obsolete:
76     print
77     print "cvs rm -f %s" % " ".join(obsolete)
78     print "cvs commit -m '- drop obsolete files' %s" % " ".join(obsolete)
This page took 0.034538 seconds and 4 git commands to generate.