]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - check-unused-files.py
- mention relup was used in release bump
[packages/rpm-build-tools.git] / check-unused-files.py
index f38e826299df442b337adb78a729558bf0693b06..6e26ea3b5cc31c74c11d75c5765c097d07d93651 100644 (file)
@@ -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,11 +37,37 @@ for l in out.split('\n'):
 
 obsolete = []
 
+# files to exclude
+exclude = ['log.*', '.#*', '*~', '*.orig', '*.sw?']
+
+# read .cvsignore, distfiles files are filled there
+if os.path.isfile('%s/.cvsignore' % dir):
+    f = open('%s/.cvsignore' % dir , 'r')
+    for l in f.readlines():
+        exclude.append(l.rstrip())
+
+def blacklisted(file):
+    if file == os.path.basename(spec):
+        return True
+
+    if file in [ '.', '..', '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 file not in files:
         print "Obsolete file: %s" % file
         obsolete.append(file)
@@ -46,6 +76,3 @@ if obsolete:
     print
     print "cvs rm -f %s" % " ".join(obsolete)
     print "cvs commit -m '- drop obsolete files' %s" % " ".join(obsolete)
-
-
-
This page took 0.0354 seconds and 4 git commands to generate.