chiark / gitweb /
lint: error on unused files
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 5 May 2016 11:40:16 +0000 (12:40 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Thu, 5 May 2016 11:40:16 +0000 (12:40 +0100)
For now, this is just patch files.

fdroidserver/lint.py

index 0572156720e10f31d4e0c89b8ed7f2946e888136..06f3998b7091d9c81902f857ff6cb8c41ff7f2e9 100644 (file)
@@ -17,6 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from argparse import ArgumentParser
+import os
 import re
 import sys
 
@@ -309,6 +310,30 @@ def check_builds(app):
                     yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
 
 
+def check_files_dir(app):
+    dir_path = os.path.join('metadata', app.id)
+    if not os.path.isdir(dir_path):
+        return
+    files = set()
+    for name in os.listdir(dir_path):
+        path = os.path.join(dir_path, name)
+        if not os.path.isfile(path):
+            yield "Found non-file at %s" % path
+            continue
+        files.add(name)
+
+    used = set()
+    for build in app.builds:
+        for fname in build.patch:
+            if fname not in files:
+                yield "Unknown file %s in build '%s'" % (fname, build.version)
+            else:
+                used.add(fname)
+
+    for name in files.difference(used):
+        yield "Unused file at %s" % os.path.join(dir_path, name)
+
+
 def main():
 
     global config, options
@@ -348,6 +373,7 @@ def main():
                 check_mediawiki_links,
                 check_bulleted_lists,
                 check_builds,
+                check_files_dir,
                 ]:
             warns += check_func(app)