def test_passes_filter(self): assert passes_filter('blah', '-ag', verbose=1) assert passes_filter('blah', 'ah') assert not passes_filter('blah', 'ag') assert passes_filter('test maya', 'test blah') assert not passes_filter('test maya', 'test +blah') # Test key class _Test(object): def __init__(self, name): self.name = name _apple = _Test('apple') _banana = _Test('banana') _key = operator.attrgetter('name') assert passes_filter(_apple, 'apple', key=_key) _list = [_apple, _banana] assert apply_filter(_list, 'apple', key=_key) == [_apple] # Test case sensitive assert passes_filter('aaa', 'AAA') assert not passes_filter('aaa', 'AAA', case_sensitive=True) # Test quotes assert passes_filter('this is text', '"This is"')
def _find_ma_files_to_check(src_dir, ma_filter, work_filter, limit): """Get list of ma files to check. Args: src_dir (str): vendor in directory to search for ma files ma_filter (str): apply filter to ma file path work_filter (str): apply filter to work file path limit (int): limit the number of files to be processed Returns: (FrasierVendorMa list): list of files to check """ assert os.path.exists(src_dir) _mas = find(src_dir, extn='ma', type_='f', filter_=ma_filter, class_=fr_vendor_ma.FrasierVendorMa) if work_filter: _mas = [ _ma for _ma in _mas if passes_filter(_ma.get_work().path, work_filter) ] if limit: _mas = _mas[:limit] return _mas
def get_geos(self): """Get a list of geos to test. Mouth geo seems to give bad bbox results so is ignored. Returns: (str list): visibile geos """ return [ _geo for _geo in cmds.sets(self.get_node('bakeSet'), query=True) if is_visible(_geo) and passes_filter(_geo, '-_eye_Geo -_tongue_Geo -_teeth_Geo') ]
def find_mods(filter_=None, file_filter=None): """Find modules in sys.modules dict. Any modules without names or files are ignored. Args: filter_ (str): module name filter file_filter (str): module file path filter """ _mods = [] for _mod_name in sorted(sys.modules.keys()): if not passes_filter(_mod_name, filter_): continue _mod = sys.modules[_mod_name] if not _mod: continue _file = getattr(_mod, '__file__', None) if not _file: continue _file = abs_path(_file) if not passes_filter(_file, file_filter): continue _mods.append(_mod) return _mods
def find_shots(self, filter_=None, class_=None): """Find shots in this sequence. Args: filter_ (str): filter by shot name class_ (TTRoot): override shot class Returns: (TTRoot list): list of shots """ _shots = [] for _shot in self._read_shots(class_=class_): if filter_ and not passes_filter(_shot.name, filter_): continue _shots.append(_shot) return _shots
def find_attrs(self, filter_=None): """Find attributes on this node. This finds attributes as strings - for plugs use the find_plugs method. Args: filter_ (str): apply filter to the list Returns: (str list): list of attribute names """ _attrs = sorted(['{}.{}'.format(self, _attr) for _attr in self.list_attr() if passes_filter(_attr, filter_)]) return _attrs
def find_plugs(self, filter_=None, keyable=True): """Find plugs on this node. Args: filter_ (str): filter by attr name keyable (bool): search for keyable plugs Returns: (HPlug list): list of plugs """ from maya_psyhive import open_maya as hom _plugs = [] for _attr in (cmds.listAttr(self, keyable=keyable) or []): if not passes_filter(_attr, filter_): continue _plug = hom.HPlug('{}.{}'.format(self, _attr)) _plugs.append(_plug) return _plugs
def find_refs(namespace=None, filter_=None, class_=None, prefix=None, unloaded=True, nested=False, extn=None): """Find reference with given namespace. Args: namespace (str): namespace to match filter_ (str): namespace filter class_ (FileRef): override FileRef class prefix (str): filter by reference prefix (prefix references don't use namespaces) unloaded (bool): return unloaded refs (default is True) nested (bool): include nested references in results extn (str): filter by extension Returns: (FileRef list): scene refs """ _refs = _read_refs(class_=class_) if namespace: _refs = [_ref for _ref in _refs if _ref.namespace == namespace] if extn: _refs = [_ref for _ref in _refs if _ref.extn == extn] if prefix: _refs = [_ref for _ref in _refs if _ref.prefix == prefix] if filter_: _refs = [ _ref for _ref in _refs if _ref.namespace and passes_filter(_ref.namespace, filter_) ] if not unloaded: _refs = [_ref for _ref in _refs if _ref.is_loaded()] if not nested: _refs = [ _ref for _ref in _refs if not _ref.reference_query(parent=True) ] return _refs
def find_asset(filter_=None, asset=None, catch=False): """Find asset matching given filter. Args: filter_ (str): filter by path asset (str): filter by asset name catch (bool): no error on fail Returns: (TTAsset): matching asset root """ _assets = find_assets() if filter_: _assets = [ _asset for _asset in _assets if passes_filter(_asset.path, filter_) ] if asset: _assets = [_asset for _asset in _assets if _asset.asset == asset] return get_single(_assets, catch=catch, verbose=1)
def find_projects(filter_=None): """Find projects on disk. Args: filter_ (str): filter projects by name Returns: (Project list): projects """ _projects = [] for _path in find(PROJECTS_ROOT, depth=1, type_='d'): try: _project = Project(_path) except ValueError: continue if not passes_filter(_project.name, filter_): continue _projects.append(_project) return _projects
def find_shots(self, filter_=None, class_=None): """Find shots in this sequence. Args: filter_ (str): filter by shot name class_ (TTShotRoot): override shot class Returns: (TTShotRoot list): list of shots """ _shots = [] _class = class_ or TTShotRoot for _path in self.find(depth=1): try: _shot = _class(_path) except ValueError: continue if filter_ and not passes_filter(_shot.name, filter_): continue _shots.append(_shot) return _shots
def find_shots(self, filter_=None, verbose=0): """Find shots within this project. Args: filter_ (str): filter shot names verbose (int): print process data Returns: (Shot list): shots """ from psyhive import pipe _shots = [] lprint('SEARCHING', self.seqs_path, verbose=verbose) for _path in find(self.seqs_path, depth=2, type_='d'): try: _shot = pipe.Shot(_path) except ValueError: lprint(' - REJECTED', _path, verbose=verbose) continue if filter_ and not passes_filter(_shot.name, filter_): continue _shots.append(_shot) return _shots
def find_action_works(type_=None, task_filter=None, day_filter=None, max_age=None, after=None, task=None, root=None, filter_=None, version=None, fbx_filter=None, ma_filter=None, name=None, desc=None, force=False, progress=True): """Find action work files in frasier project. Args: type_ (str): filter by type (eg. Vignette, Disposition) task_filter (str): apply filter to work task attribute day_filter (str): filter by day (in %y%m%d format) max_age (float): reject any work files older than is many secs after (str): return works on or after this day (in %y%m%d format) task (str): filter by exact task name root (TTRoot): filter by root filter_ (str): apply filter to work file path version (int): filter by version (v001 are always ingested files) fbx_filter (str): apply filter export fbx path ma_filter (str): filter by vendor ma path name (str): filter by exact name desc (str): filter by exact desc force (bool): force reread actions from disk progress (bool): show progress bar on read Returns: (FrasierWork list): list of work files """ _works = _read_action_works(force=force, progress=progress) # Filters if filter_: _works = apply_filter(_works, filter_, key=operator.attrgetter('path')) if task_filter: _works = apply_filter(_works, task_filter, key=operator.attrgetter('task')) if fbx_filter: _works = [ _work for _work in _works if passes_filter(_work.get_export_fbx().path, fbx_filter) ] if ma_filter: _works = [ _work for _work in _works if _work.get_mtime() and passes_filter(_work.get_vendor_file(), ma_filter) ] # Match attr if task: _works = [_work for _work in _works if _work.task == task] if type_: _works = [_work for _work in _works if _work.type_ == type_] if root: _works = [_work for _work in _works if _work.get_root() == root] if name: _works = [_work for _work in _works if _work.name == name] if desc: _works = [_work for _work in _works if _work.desc == desc] if version: _works = [_work for _work in _works if _work.version == version] # Date match if max_age is not None: _works = [_work for _work in _works if _work.get_age() < max_age] if day_filter: _works = [ _work for _work in _works if _work.get_mtime() and _work.get_mtime_fmt('%y%m%d') == day_filter ] if after: _cutoff = get_time_f(time.strptime(after, '%y%m%d')) _works = [ _work for _work in _works if _work.get_mtime() and _work.get_mtime() >= _cutoff ] return _works