diff --git a/conductor/lib/file_utils.py b/conductor/lib/file_utils.py index c3f9941c..b99a7ebb 100644 --- a/conductor/lib/file_utils.py +++ b/conductor/lib/file_utils.py @@ -487,3 +487,32 @@ def strip_drive_letter(filepath): ''' rx_drive = r'^[a-z]:' return re.sub(rx_drive, "", filepath, flags=re.I) + +def expand_paths(paths): + ''' + Expand a list of paths using glob + ''' + + expanded_paths = [] + + for path in paths: + + expanded = [ os.path.normpath(p) for p in glob.glob(path.strip()) ] + logger.debug("'{}' expanded to {}".format(path, expanded)) + expanded_paths.extend(expanded) + + return expanded_paths + +def expand_paths_from_file(path): + ''' + Opens a file that contains glob-style patterns and returns a list of all + matching files. The file must contain one glob-style pattern per-line. + + path: A string. The path to the file that contains glob patterns + ''' + + with open(path) as fh: + glob_patterns = fh.readlines() + + return expand_paths(glob_patterns) + diff --git a/conductor/lib/maya_utils.py b/conductor/lib/maya_utils.py index 9da05ba0..a190591e 100644 --- a/conductor/lib/maya_utils.py +++ b/conductor/lib/maya_utils.py @@ -472,21 +472,33 @@ def get_render_layers_info(): return render_layers -def collect_dependencies(node_attrs): +def collect_dependencies(node_attrs, leaf_paths=None, exclude_paths=None): ''' Return a list of filepaths that the current maya scene has dependencies on. This is achieved by inspecting maya's nodes. Use the node_attrs argument to pass in a dictionary - ''' + + leaf_paths: A list of strings. A list of paths to skip for nested dependencies. + Ex: A maya file that itself will be included but not textures, or + other nested references will be. + exclude_paths: A list of strings. A list of paths to exclude from the + dependency scanner. + ''' + assert isinstance(node_attrs, dict), "node_attrs arg must be a dict. Got %s" % type(node_attrs) + + leaf_paths = leaf_paths or [] + exclude_paths = exclude_paths or [] # TODO: Temporary hack to work around renderman 23.3 bug. # Record the active renderer so that we can restore it after making this cmds.file call active_renderer = get_active_renderer() # Note that this command will often times return filepaths with an ending "/" on it for some reason. Strip this out at the end of the function dependencies = cmds.file(query=True, list=True, withoutCopyNumber=True) or [] + # Strip errant dependences (another part of the renderman bug above). - dependencies = [path for path in dependencies if not path.endswith('_