def get_sg_data(self, verbose=0): """Find shotgun data for this publish. Args: verbose (int): print process data Returns: (dict): shoutgun data """ from psyhive import tk2 _proj = tk2.get_project_sg_data(pipe.Project(self.path)) _root = tk2.TTRoot(self.path) _task = tk2.get_sg_data( 'Task', content=self.task, project=_proj, entity=_root.get_sg_data()) _data = tk2.get_sg_data( 'PublishedFile', version_number=self.ver_n, sg_format=self.extn, project=_proj, task=_task, limit=2, code=self.filename.replace('%04d', '####'), fields=['task', 'code', 'short_name']) if verbose: pprint.pprint(_data) if len(_data) > 1: raise RuntimeError(self.path) return get_single(_data, catch=True)
def map_tag_to_shot(tag): """Map the given tag to a shot in the current project. Args: tag (str): tag to match Returns: (TTShot): shot root """ # Try existing shot on disk _shot = tk2.find_shot(tag, catch=True, mode='sg') if _shot: return _shot # Try shot from sg _data = get_single(tk2.get_sg_data('Shot', code=tag, fields=['sg_sequence']), catch=True) if _data: _path = '{}/sequences/{}/{}'.format(pipe.cur_project().path, _data['sg_sequence']['name'], tag) return tk2.TTShot(_path) return None
def find_shots(class_=None, filter_=None, sequence=None, mode='disk'): """Find shots in the current job. Args: class_ (class): override shot root class filter_ (str): filter by shot name sequence (str): filter by sequence name mode (str): where to search for shot (disk/sg) Returns: (TTRoot): list of shots """ if mode == 'disk': _seqs = find_sequences() if sequence: _seqs = [_seq for _seq in _seqs if _seq.name == sequence] return sum([ _seq.find_shots(class_=class_, filter_=filter_) for _seq in _seqs ], []) elif mode == 'sg': from psyhive import tk2 _path_fmt = '{}/sequences/{}/{}' _shots = [] for _seq in tk2.get_sg_data(type_='Sequence', fields=['shots', 'code'], limit=0): for _shot in _seq['shots']: _shot_path = _path_fmt.format(pipe.cur_project().path, _seq['code'], _shot['name']) _shot = tk2.TTShot(_shot_path) _shots.append(_shot) return _shots else: raise ValueError(mode)
def has_sg_version(self): """Test if there is a shotgun version for this seq. NOTE: there could be more than one if someone already published it through Publish Files tool manually. Returns: (bool): whether version found in shotgun """ from psyhive import tk2 _data = tk2.get_sg_data( 'Version', entity=self.get_root().get_sg_data(), code=self.basename, fields=['sg_path_to_frames']) if not _data or not _data[0]['sg_path_to_frames']: return False _path = abs_path(_data[0]['sg_path_to_frames']).replace('####', '%04d') print ' - VER PATH', _path assert _path == self.path return True