]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - check-unused-files.py
- rel may contain other macros, strip and readd them for increment
[packages/rpm-build-tools.git] / check-unused-files.py
CommitLineData
7b2ce93a
AM
1#!/usr/bin/python
2
3import subprocess
4import sys
5import os
8445e70f 6import fnmatch
7b2ce93a
AM
7
8if len(sys.argv) != 2:
9 print >> sys.stderr, "Usage: %s <spec>" % sys.argv[0]
10 sys.exit(1)
11
12spec = sys.argv[1]
13
14if not os.path.isfile(spec):
15 print >> sys.stderr, "%s: %s doesn't exist!" % (sys.argv[0], spec)
16 sys.exit(1)
17
18dir = os.path.dirname(spec)
19if dir == '':
20 dir = '.'
21
22p = subprocess.Popen(['rpm-specdump', spec], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
23(out, err) = p.communicate(None)
24p.wait()
e77c91c6
AM
25if err:
26 print >> sys.stderr, "%s: %s" % (sys.argv[0], err)
27 sys.exit(1)
7b2ce93a
AM
28
29files = []
30
31for 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
38obsolete = []
39
8445e70f 40def blacklisted(file):
84e1e6d0
ER
41 if file == os.path.basename(spec):
42 return True
43
dd05fc46 44 if file in [ '.', '..', 'CVS', '.cvsignore', 'dropin', 'md5', 'adapter', 'builder',
84e1e6d0 45 'relup.sh', 'compile.sh', 'repackage.sh', 'pearize.sh', 'rsync.sh', 'TODO']:
8445e70f
ER
46 return True
47
48 for pat in ['log.*', '.#*', '*~', '*.orig', '*.sw?']:
49 if fnmatch.fnmatch(file, pat):
50 return True
51
52 return False
53
54for file in os.listdir(dir):
55 file = os.path.basename(file)
56 if blacklisted(file):
82a3c8b3 57 continue
8445e70f 58
7b2ce93a
AM
59 if file not in files:
60 print "Obsolete file: %s" % file
61 obsolete.append(file)
62
c7c88163
AM
63if obsolete:
64 print
65 print "cvs rm -f %s" % " ".join(obsolete)
7998a6ff 66 print "cvs commit -m '- drop obsolete files' %s" % " ".join(obsolete)
This page took 0.101836 seconds and 4 git commands to generate.