]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - check-unused-files.py
initial generic script for rust crates tarball creation
[packages/rpm-build-tools.git] / check-unused-files.py
old mode 100644 (file)
new mode 100755 (executable)
index ef7dc5a..83aab41
@@ -5,6 +5,24 @@ import sys
 import os
 import fnmatch
 
+def filterout_warnings(err, separator="\n"):
+    def filter():
+        for line in err.split(separator):
+            if line.startswith("warning: "):
+                continue
+            yield line
+
+    return separator.join(list(filter()))
+
+def specdump(spec):
+    p = subprocess.Popen(['rpm-specdump', spec], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    (out, err) = p.communicate(None)
+    p.wait()
+
+    err = filterout_warnings(err)
+
+    return (out, err)
+
 if len(sys.argv) == 2:
     spec = sys.argv[1]
 else:
@@ -19,9 +37,7 @@ dir = os.path.dirname(spec)
 if dir == '':
     dir = '.'
 
-p = subprocess.Popen(['rpm-specdump', spec], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-(out, err) = p.communicate(None)
-p.wait()
+(out, err) = specdump(spec)
 if err:
     print >> sys.stderr, "%s: %s" % (sys.argv[0], err)
     sys.exit(1)
@@ -38,30 +54,29 @@ for l in out.split('\n'):
 obsolete = []
 
 # files to exclude
-exclude = ['log.*', '.#*', '*~', '*.orig', '*.sw?']
+exclude = ['log.*', '.#*', '*~', '*.orig', '*.sw?', '.bigfiles', 'sources']
 
-# read .cvsignore, distfiles files are filled there
-if os.path.isfile('%s/.cvsignore' % dir):
-    f = open('%s/.cvsignore' % dir , 'r')
+# read .gitignore, distfiles files are filled there
+if os.path.isfile('%s/.gitignore' % dir):
+    f = open('%s/.gitignore' % dir , 'r')
     for l in f.readlines():
         exclude.append(l.rstrip())
 
-def cvs_entries(file):
-    f = open('%s/CVS/Entries' % dir , 'r')
-    files = []
-    for l in f.readlines():
-        if l[0] != '/':
-            continue
-        parts = l.split('/')
-        files.append(parts[1])
-    return files
-cvsfiles = cvs_entries(dir)
+def git_entries(file):
+    p = subprocess.Popen(['git', 'ls-files'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    (out, err) = p.communicate(None)
+    p.wait()
+    if err:
+        print >> sys.stderr, "%s: %s" % (sys.argv[0], err)
+        sys.exit(1)
+    return out.split('\n')
+gitfiles = git_entries(dir)
 
 def blacklisted(file):
     if file == os.path.basename(spec):
         return True
 
-    if file in [ '.', '..', 'CVS', 'TODO']:
+    if file in [ '.', '..', '.git', 'CVS', 'TODO']:
         return True
 
     if os.path.isdir(file):
@@ -78,8 +93,8 @@ for file in os.listdir(dir):
     if blacklisted(file):
         continue
 
-    if not file in cvsfiles:
-        print "Not in cvs: %s" % file
+    if not file in gitfiles:
+        print "Not in repo: %s" % file
         continue
 
     if file not in files:
@@ -88,5 +103,5 @@ for file in os.listdir(dir):
 
 if obsolete:
     print
-    print "cvs rm -f %s" % " ".join(obsolete)
-    print "cvs commit -m '- drop obsolete files' %s" % " ".join(obsolete)
+    print "git rm %s" % " ".join(obsolete)
+    print "git commit -m '- drop obsolete files' %s" % " ".join(obsolete)
This page took 0.242933 seconds and 4 git commands to generate.