From acd46062fd2edf4b45ab646cbacaf865b169ec30 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Fri, 10 Feb 2012 16:45:18 -0500
Subject: [PATCH] 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.

---
 indra/lib/python/indra/util/llmanifest.py | 33 +++++++++++++++--------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/indra/lib/python/indra/util/llmanifest.py b/indra/lib/python/indra/util/llmanifest.py
index 237153b7561..a4fb77357c6 100644
--- a/indra/lib/python/indra/util/llmanifest.py
+++ b/indra/lib/python/indra/util/llmanifest.py
@@ -42,6 +42,11 @@
 import subprocess
 
 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
 
 def path_ancestors(path):
@@ -604,16 +609,12 @@ def wildcard_regex(self, src_glob, dst_glob):
 
     def check_file_exists(self, 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'\*')
     def expand_globs(self, src, dst):
         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('\\', '/'),
                                                  dst.replace('\\', '/'))
         for s in src_list:
@@ -646,13 +647,23 @@ def try_path(src):
                 else:
                     count += self.process_file(src, dst)
             return count
-        try:
-            count = try_path(os.path.join(self.get_src_prefix(), src))
-        except ManifestError:
+
+        for pfx in self.get_src_prefix(), self.get_artwork_prefix(), self.get_build_prefix():
             try:
-                count = try_path(os.path.join(self.get_artwork_prefix(), src))
-            except ManifestError:
-                count = try_path(os.path.join(self.get_build_prefix(), src))
+                count = try_path(os.path.join(pfx, src))
+            except MissingError:
+                # 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
 
     def do(self, *actions):
-- 
GitLab