Skip to content
Snippets Groups Projects
Commit acd46062 authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

Eliminate ManifestError for wildcards matching 0 files.

Turns out that some (many?) wildcard LLManifest.path(wildcard) calls are "just
in case": sweep up any (e.g.) "*.tga" files there may be, but no problem if
there are none.
Change path() logic so it tries the next tree (source, artwork, build) if
either a specific (non-wildcard) filename doesn't exist, as now, OR if a
wildcard matches 0 files in the current tree. This continues to support "just
in case" wildcards, while permitting wildcards to work in the artwork and
build trees as well as the source tree.
Use a more specific exception than ManifestError for missing file. Only in
that case should we try the next tree. Any other ManifestError should
propagate.
parent 9011b044
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,11 @@ ...@@ -42,6 +42,11 @@
import subprocess import subprocess
class ManifestError(RuntimeError): class ManifestError(RuntimeError):
"""Use an exception more specific than generic Python RuntimeError"""
pass
class MissingError(ManifestError):
"""You specified a file that doesn't exist"""
pass pass
def path_ancestors(path): def path_ancestors(path):
...@@ -604,16 +609,12 @@ def wildcard_regex(self, src_glob, dst_glob): ...@@ -604,16 +609,12 @@ def wildcard_regex(self, src_glob, dst_glob):
def check_file_exists(self, path): def check_file_exists(self, path):
if not os.path.exists(path) and not os.path.islink(path): if not os.path.exists(path) and not os.path.islink(path):
raise ManifestError("Path %s doesn't exist" % (os.path.abspath(path),)) raise MissingError("Path %s doesn't exist" % (os.path.abspath(path),))
wildcard_pattern = re.compile(r'\*') wildcard_pattern = re.compile(r'\*')
def expand_globs(self, src, dst): def expand_globs(self, src, dst):
src_list = glob.glob(src) src_list = glob.glob(src)
# Assume that if caller specifies a wildcard, s/he wants it to match
# at least one file...
if not src_list:
raise ManifestError("Path %s doesn't exist" % (os.path.abspath(src),))
src_re, d_template = self.wildcard_regex(src.replace('\\', '/'), src_re, d_template = self.wildcard_regex(src.replace('\\', '/'),
dst.replace('\\', '/')) dst.replace('\\', '/'))
for s in src_list: for s in src_list:
...@@ -646,13 +647,23 @@ def try_path(src): ...@@ -646,13 +647,23 @@ def try_path(src):
else: else:
count += self.process_file(src, dst) count += self.process_file(src, dst)
return count return count
try:
count = try_path(os.path.join(self.get_src_prefix(), src)) for pfx in self.get_src_prefix(), self.get_artwork_prefix(), self.get_build_prefix():
except ManifestError:
try: try:
count = try_path(os.path.join(self.get_artwork_prefix(), src)) count = try_path(os.path.join(pfx, src))
except ManifestError: except MissingError:
count = try_path(os.path.join(self.get_build_prefix(), src)) # If src isn't a wildcard, and if that file doesn't exist in
# this pfx, try next pfx.
count = 0
continue
# Here try_path() didn't raise MissingError. Did it process any files?
if count:
break
# Even though try_path() didn't raise MissingError, it returned 0
# files. src is probably a wildcard meant for some other pfx. Loop
# back to try the next.
print "%d files" % count print "%d files" % count
def do(self, *actions): def do(self, *actions):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment