8 def filterout_warnings(err, separator="\n"):
10 for line in err.split(separator):
11 if line.startswith("warning: "):
15 return separator.join(list(filter()))
18 p = subprocess.Popen(['rpm-specdump', spec], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
19 (out, err) = p.communicate(None)
22 err = filterout_warnings(err)
26 if len(sys.argv) == 2:
30 spec = "%s.spec" % os.path.basename(os.getcwd())
32 if not os.path.isfile(spec):
33 print >> sys.stderr, "%s: %s doesn't exist!" % (sys.argv[0], spec)
36 dir = os.path.dirname(spec)
40 (out, err) = specdump(spec)
42 print >> sys.stderr, "%s: %s" % (sys.argv[0], err)
47 for l in out.split('\n'):
49 if len(data) != 3 or data[0] != 's':
51 file = os.path.basename(data[2])
57 exclude = ['log.*', '.#*', '*~', '*.orig', '*.sw?', '.bigfiles', 'sources']
59 # read .gitignore, distfiles files are filled there
60 if os.path.isfile('%s/.gitignore' % dir):
61 f = open('%s/.gitignore' % dir , 'r')
62 for l in f.readlines():
63 exclude.append(l.rstrip())
65 def git_entries(file):
66 p = subprocess.Popen(['git', 'ls-files'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
67 (out, err) = p.communicate(None)
70 print >> sys.stderr, "%s: %s" % (sys.argv[0], err)
72 return out.split('\n')
73 gitfiles = git_entries(dir)
75 def blacklisted(file):
76 if file == os.path.basename(spec):
79 if file in [ '.', '..', '.git', 'CVS', 'TODO']:
82 if os.path.isdir(file):
86 if fnmatch.fnmatch(file, pat):
91 for file in os.listdir(dir):
92 file = os.path.basename(file)
96 if not file in gitfiles:
97 print "Not in repo: %s" % file
100 if file not in files:
101 print "Obsolete file: %s" % file
102 obsolete.append(file)
106 print "git rm %s" % " ".join(obsolete)
107 print "git commit -m '- drop obsolete files' %s" % " ".join(obsolete)