aboutsummaryrefslogtreecommitdiff
path: root/license_protected_downloads/buildinfo.py
diff options
context:
space:
mode:
authorJames Tunnicliffe <james.tunnicliffe@linaro.org>2013-05-29 14:41:12 +0100
committerJames Tunnicliffe <james.tunnicliffe@linaro.org>2013-05-29 14:41:12 +0100
commit6ff77122348c464936ac5ea3267114098f4eebf9 (patch)
tree007b3ee92c945ae4ff0c5422e483e91517ac279d /license_protected_downloads/buildinfo.py
parente1bf3ae44c5a410feb3a82036fa214c58ab9842e (diff)
Updated buildinfo logic to be much faster at maching a long list of file names in a large directory of files. Used to take (n^m)/2 calls to fnmatch (n = number of files in a directory, m = number of files listed in BUILD-INFO.txt), which is a bit slow due to the use of regular expressions. Worst case is still the same, but this shortcuts a lot of checks when there is a simple non-glob match.
Diffstat (limited to 'license_protected_downloads/buildinfo.py')
-rw-r--r--license_protected_downloads/buildinfo.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/license_protected_downloads/buildinfo.py b/license_protected_downloads/buildinfo.py
index 46f7b2e..dfc06a8 100644
--- a/license_protected_downloads/buildinfo.py
+++ b/license_protected_downloads/buildinfo.py
@@ -57,11 +57,22 @@ class BuildInfo:
def getInfoForFile(self):
for block in self.build_info_array:
+
+ if self.fname in block:
+ # File name matches a key directly - don't need to iterate
+ # through each using fnmatch to implement globs.
+ return block[self.fname]
+
+ if self.full_file_name == self.search_path:
+ # Searching for directory match. This will only match the "*"
+ # glob.
+ if "*" in block:
+ return block["*"]
+ else:
+ return [{}]
+
for key in block:
if key != "format-version":
- # Special handling of entire-directory access specifier
- if key == "*" and os.path.isdir(self.full_file_name):
- return block[key]
if fnmatch.fnmatch(self.full_file_name,
os.path.join(self.search_path, key)):
return block[key]