def __init__(self, filepath, parent, batch, log=None): self.batch = batch if not os.path.isabs(filepath): filepath = os.path.join(utils.get_root_dir(), filepath) self.path = os.path.realpath(os.path.normpath(filepath)) self.label = " {0}".format(os.path.basename(self.path)) self.exists = os.path.exists(self.path) self.lastmodified = datetime.fromtimestamp(os.path.getmtime( self.path)) if self.exists else None self.note = self.path if self.exists else "Can't find {0}".format( self.path) self.parent_list = parent self.check_box = None self.size = float(os.path.getsize(self.path)) if self.exists else 0 self.display_text = None self.log = log if self.exists: self.pathmap = { os.path.dirname(self.path): utils.get_remote_file_path(self.path) } self.storage_path = utils.get_storage_file_path(self.path) else: self.pathmap = {} self.storage_path = None
def _get_bifrost_caches(self, assets): start = maya.start_frame() end = maya.end_frame() step = maya.frame_step() caches = [] cache_paths = [] containers = maya.get_list(type="bifrostContainer") for container in containers: for cache_type in [ 'Foam', 'Guide', 'Liquid', 'LiquidMesh', 'Solid' ]: try: enabled = maya.get_attr( container + ".enable{}Cache".format(cache_type)) except ValueError: continue if enabled: cache_name = maya.get_attr( container + ".{}CacheFileName".format(cache_type.lower())) cache_path = maya.get_attr( container + ".{}CachePath".format(cache_type.lower())) cache_paths.append(os.path.join(cache_path, cache_name)) self.pathmaps[cache_path] = utils.get_remote_file_path( cache_path) self.pathmaps[ cache_paths[-1]] = utils.get_remote_file_path( cache_paths[-1]) cache_paths = list(set(cache_paths)) for cache_path in cache_paths: for frame in range(start, end + step, step): frame_name = "*.{}.bif".format(str(frame).zfill(4)) caches.extend( glob.glob(os.path.join(cache_path, "**", frame_name))) caches = list(set(caches)) for cache in caches: asset = Asset(cache, assets, self.batch, self._log) if not asset.is_duplicate(assets): assets.append(asset)
def _search_path(self, ref_path): """Validate an asset path and if the file does not exist, attempt to resolve it against the system search paths (using the scene file and current project) and user specified search paths. If the asset paths contains a pattern - resolve this to all applicable files. """ ref_file = os.path.basename(ref_path) ref_dir = os.path.dirname(ref_path) pattern = ('*' in ref_path or '[0-9]' in ref_path) self._log.debug("Searching for asset path: {}".format(ref_path)) self._log.debug("Checking pattern asset: {}".format(pattern)) if pattern: path_matches = glob.glob(ref_path) if path_matches: self.pathmaps[ref_dir] = utils.get_remote_file_path(ref_path) self._log.debug("Mapping this path {} to {}".format( ref_path, self.pathmaps[ref_dir])) self._log.debug("Found matches: {}".format(path_matches)) return path_matches elif os.path.exists(ref_path): self.pathmaps[ref_dir] = utils.get_remote_file_path(ref_path) self._log.debug("Mapping this path {} to {}".format( ref_path, self.pathmaps[ref_dir])) return [ref_path] for searchpath in SYS_SEARCHPATHS: alt_path = os.path.join(searchpath, ref_file) if pattern: path_matches = glob.glob(alt_path) if path_matches: self.pathmaps[ref_dir] = utils.get_remote_file_path( alt_path) self._log.debug("Mapping this path {} to {}".format( ref_path, self.pathmaps[ref_dir])) self._log.debug("Found matches: {}".format(path_matches)) return path_matches elif os.path.exists(alt_path): self.pathmaps[ref_dir] = utils.get_remote_file_path(alt_path) self._log.debug("Mapping this path {} to {}".format( ref_path, self.pathmaps[ref_dir])) return [alt_path] for searchpath in USR_SEARCHPATHS: for _root, _dir, _file in os.walk(searchpath): alt_path = os.path.join(_root, ref_file) if pattern: path_matches = glob.glob(alt_path) self._log.debug("Found matches: {}".format(path_matches)) if path_matches: self.pathmaps[ref_dir] = utils.get_remote_file_path( alt_path) self._log.debug("Mapping this path {} to {}".format( ref_path, self.pathmaps[ref_dir])) return path_matches elif os.path.exists(alt_path): self.pathmaps[ref_dir] = utils.get_remote_file_path( alt_path) self._log.debug("Mapping this path {} to {}".format( ref_path, self.pathmaps[ref_dir])) return [alt_path] self._log.debug("No matches for reference: {}".format(ref_path)) return [ref_path]