]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - check-unused-files.py
- sort patches
[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 7
861e13b1
ER
8if len(sys.argv) == 2:
9 spec = sys.argv[1]
10else:
11 # try autodetecting
12 spec = "%s.spec" % os.path.basename(os.getcwd())
7b2ce93a
AM
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
b668f2cd 40# files to exclude
6c3972e0 41exclude = ['log.*', '.#*', '*~', '*.orig', '*.sw?', '.bigfiles', 'sources']
b668f2cd 42
b8f9713d
ER
43# read .gitignore, distfiles files are filled there
44if os.path.isfile('%s/.gitignore' % dir):
45 f = open('%s/.gitignore' % dir , 'r')
b668f2cd
ER
46 for l in f.readlines():
47 exclude.append(l.rstrip())
48
b8f9713d
ER
49def git_entries(file):
50 p = subprocess.Popen(['git', 'ls-files'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
51 (out, err) = p.communicate(None)
52 p.wait()
53 if err:
54 print >> sys.stderr, "%s: %s" % (sys.argv[0], err)
55 sys.exit(1)
56 return out.split('\n')
57gitfiles = git_entries(dir)
4f1efb15 58
8445e70f 59def blacklisted(file):
84e1e6d0
ER
60 if file == os.path.basename(spec):
61 return True
62
b8f9713d 63 if file in [ '.', '..', '.git', 'CVS', 'TODO']:
8445e70f
ER
64 return True
65
1e0688bb
AM
66 if os.path.isdir(file):
67 return True
68
b668f2cd 69 for pat in exclude:
8445e70f
ER
70 if fnmatch.fnmatch(file, pat):
71 return True
72
73 return False
74
75for file in os.listdir(dir):
76 file = os.path.basename(file)
77 if blacklisted(file):
82a3c8b3 78 continue
8445e70f 79
b8f9713d
ER
80 if not file in gitfiles:
81 print "Not in repo: %s" % file
4f1efb15
ER
82 continue
83
7b2ce93a
AM
84 if file not in files:
85 print "Obsolete file: %s" % file
86 obsolete.append(file)
87
c7c88163
AM
88if obsolete:
89 print
b8f9713d
ER
90 print "git rm %s" % " ".join(obsolete)
91 print "git commit -m '- drop obsolete files' %s" % " ".join(obsolete)
This page took 0.035231 seconds and 4 git commands to generate.