chiark / gitweb /
Rework path glob expansion
authorDaniel Martí <mvdan@mvdan.cc>
Sat, 3 Oct 2015 23:52:23 +0000 (16:52 -0700)
committerDaniel Martí <mvdan@mvdan.cc>
Sat, 3 Oct 2015 23:52:23 +0000 (16:52 -0700)
Slightly simplifies the whole thing and lets us map what each resulting path
comes from. This will be useful to fix #110 later on.

fdroidserver/common.py
fdroidserver/scanner.py

index a79a4fe4bf78939a287da3fc43107d1674081630..1e3e7639059efb3c76acf22fed051935059fe448 100644 (file)
@@ -1383,7 +1383,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
     # Delete unwanted files
     if build['rm']:
         logging.info("Removing specified files")
-        for part in getpaths(build_dir, build, 'rm'):
+        for part in getpaths(build_dir, build['rm']):
             dest = os.path.join(build_dir, part)
             logging.info("Removing {0}".format(part))
             if os.path.lexists(dest):
@@ -1462,14 +1462,25 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
     return (root_dir, srclibpaths)
 
 
-# Split and extend via globbing the paths from a field
-def getpaths(build_dir, build, field):
-    paths = []
-    for p in build[field]:
+# Extend via globbing the paths from a field and return them as a map from
+# original path to resulting paths
+def getpaths_map(build_dir, globpaths):
+    paths = dict()
+    for p in globpaths:
         p = p.strip()
         full_path = os.path.join(build_dir, p)
         full_path = os.path.normpath(full_path)
-        paths += [r[len(build_dir) + 1:] for r in glob.glob(full_path)]
+        paths[p] = [r[len(build_dir) + 1:] for r in glob.glob(full_path)]
+    return paths
+
+
+# Extend via globbing the paths from a field and return them as a set
+def getpaths(build_dir, globpaths):
+    paths_map = getpaths_map(build_dir, globpaths)
+    paths = set()
+    for k, v in paths_map.iteritems():
+        for p in v:
+            paths.add(p)
     return paths
 
 
index 7f6d7d91d36b1b123a1f6be4ed980e763b45f07e..f71120e35c379b4d671e9fe31ee33f7be8d02407 100644 (file)
@@ -72,8 +72,8 @@ def scan_source(build_dir, root_dir, thisbuild):
             if r.match(s):
                 yield n
 
-    scanignore = common.getpaths(build_dir, thisbuild, 'scanignore')
-    scandelete = common.getpaths(build_dir, thisbuild, 'scandelete')
+    scanignore = common.getpaths(build_dir, thisbuild['scanignore'])
+    scandelete = common.getpaths(build_dir, thisbuild['scandelete'])
 
     scanignore_worked = set()
     scandelete_worked = set()