def cache_read(self, tag, verbose=0): """Read cached data from the given tag. Args: tag (str): data tag to read verbose (int): print process data Returns: (any): cached data """ from psyhive.utils import read_yaml, File _file = File(self.cache_fmt.format(tag)) lprint('READ CACHE FILE', _file.path, verbose=verbose) if _file.extn == 'yml': try: return read_yaml(_file.path) except OSError: return None else: try: return obj_read(file_=_file.path) except OSError: return None
def get_metadata(self, verbose=1): """Read this work area's metadata yaml file. Args: verbose (int): print process data Returns: (dict): work area metadata """ dprint("Reading metadata", self.path, verbose=verbose) if not os.path.exists(self.yaml): return {} return read_yaml(self.yaml)
def _find_shaders(force=False, parent=None, verbose=0): """Search current prject for shader outputs. Args: force (bool): reread cache from disk parent (QWidget): parent widget (for progress bar) verbose (int): print process data Returns: (dict): shader output, shader list """ if force: tk2.clear_caches() _works = [] for _asset in qt.progress_bar(tk2.obtain_assets(), 'Reading {:d} asset{}', parent=parent): _shade = _asset.find_step_root('shade', catch=True) if not _shade or not _shade.exists(): continue for _work in _shade.find_work(): _works.append(_work) _shd_mbs = {} for _work in qt.progress_bar(_works, 'Checking {:d} work file{}', parent=parent): _shd_mb = _work.map_to(tk2.TTOutputFile, extension='mb', output_name='main', output_type='shadegeo', format='shaders') _yml = _work.map_to(tk2.TTOutputFile, extension='yml', output_name='main', output_type='shadegeo', format='shaders') if not _shd_mb.exists() or not _yml.exists(): continue _shds = read_yaml(_yml.path) _shd_mbs[_shd_mb] = _shds if verbose: print _work print _shds print return _shd_mbs
def read_psylaunch_cfg(self, edit=False, verbose=0): """Read psylaunch config data for this project. Args: edit (bool): open file in editor verbose (int): print process data Returns: (dict): psylaunch config data """ _yaml = abs_path(_PSYLAUNCH_CFG_FMT.format(self.path)) lprint('PSYLAUNCH YAML', _yaml, verbose=verbose) if edit: File(_yaml).edit() return read_yaml(_yaml)
def load_settings(self, verbose=0): """Load settings from disk. Args: verbose (int): print process data """ _settings = read_yaml(self.settings_file) lprint('LOADING', _settings, verbose=verbose) for _attr, _attr_settings in _settings.items(): lprint('APPLING', _attr, verbose=verbose) for _name, _settings in _attr_settings.items(): lprint(' - NAME', _name, verbose=verbose) for _arg_name, _val in _settings.items(): # Find set fn _set_fns = self.set_settings_fns try: _set_fn = _set_fns[_attr][_name][_arg_name] except KeyError: _set_fn = None # Apply value _applied = False if _set_fn: lprint(' - APPLYING', _arg_name, _val, _set_fn, verbose=verbose) try: _set_fn(_val) except TypeError: continue else: _applied = True if not _applied: lprint(' - FAILED TO APPLY', _arg_name, _val) dprint('Loaded settings', self.settings_file)