diff options
author | Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> | 2017-07-22 02:44:48 +0200 |
---|---|---|
committer | Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> | 2017-07-22 02:44:48 +0200 |
commit | 9fdfda2191e4425dd48581cc73574c0c97470a9f (patch) | |
tree | b46869ed4e4fa4e5d2d09e149acd91bf46517cfb | |
parent | f8e68cb1249a9b5c09298f3ab622e7658d5fefcf (diff) |
Changed matching logic: if is in a directory that matches, matches.
-rwxr-xr-x | tools/Internals/copyright.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/tools/Internals/copyright.py b/tools/Internals/copyright.py index 91a03c7..f724dc7 100755 --- a/tools/Internals/copyright.py +++ b/tools/Internals/copyright.py @@ -45,7 +45,6 @@ def get_copyright_rules(root): for base in bases: rules[base] = '===IGNORED===' - rules[os.path.join(base, '*')] = '===IGNORED===' except FileNotFoundError: pass @@ -82,6 +81,24 @@ def get_copyright_rules(root): return rules +def __match(rule, path): + """ Check if a path matches a rule. """ + + # Check if the full path is matched. + if fnmatch.fnmatch(path, rule): + return True + + # Check if one of the parent directories is matched. + while True: + dirname, filename = os.path.split(path) + if not dirname: break + if fnmatch.fnmatch(dirname, rule): + return True + path = dirname + + # Nothing is matched. Exit! + return False + def get_copyright(rules, path): """ Get a path's copyright using a set of rules. """ @@ -91,8 +108,11 @@ def get_copyright(rules, path): match = None for rule in rules: - if not fnmatch.fnmatch(path, rule): + # Check if the rule matches the path. + if not __match(rule, path): continue + + # Check if it is the first thing. if not match: match = rule continue |