]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - check-unused-files.py
unset GIT_EDITOR together with other GIT_* vars
[packages/rpm-build-tools.git] / check-unused-files.py
old mode 100644 (file)
new mode 100755 (executable)
index f38e826..4ecc6a9
@@ -3,12 +3,13 @@
 import subprocess
 import sys
 import os
+import fnmatch
 
-if len(sys.argv) != 2:
-    print >> sys.stderr, "Usage: %s <spec>" % sys.argv[0]
-    sys.exit(1)
-
-spec = sys.argv[1]
+if len(sys.argv) == 2:
+    spec = sys.argv[1]
+else:
+    # try autodetecting
+    spec = "%s.spec" % os.path.basename(os.getcwd())
 
 if not os.path.isfile(spec):
     print >> sys.stderr, "%s: %s doesn't exist!" % (sys.argv[0], spec)
@@ -21,6 +22,9 @@ if dir == '':
 p = subprocess.Popen(['rpm-specdump', spec], 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)
 
 files = []
 
@@ -33,19 +37,55 @@ for l in out.split('\n'):
 
 obsolete = []
 
+# files to exclude
+exclude = ['log.*', '.#*', '*~', '*.orig', '*.sw?', '.bigfiles', 'sources']
+
+# 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 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 [ '.', '..', '.git', 'CVS', 'TODO']:
+        return True
+
+    if os.path.isdir(file):
+        return True
+
+    for pat in exclude:
+        if fnmatch.fnmatch(file, pat):
+            return True
+
+    return False
+
 for file in os.listdir(dir):
     file = os.path.basename(file)
-    if file in [ '.', '..', 'CVS', '.cvsignore', 'dropin', 'md5', 'adapter', 'builder',
-            'relup.sh', 'compile.sh', 'repackage.sh', 'TODO', os.path.basename(spec) ]:
+    if blacklisted(file):
+        continue
+
+    if not file in gitfiles:
+        print "Not in repo: %s" % file
         continue
+
     if file not in files:
         print "Obsolete file: %s" % file
         obsolete.append(file)
 
 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.105104 seconds and 4 git commands to generate.