Esempio n. 1
0
    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)
Esempio n. 2
0
    def __init__(self, path, hint=None, tmpl=None, data=None, verbose=0):
        """Constructor.

        Args:
            path (str): path to object
            hint (str): template name
            tmpl (TemplatePath): override template object
            data (dict): override data dict
            verbose (int): print process data
        """
        _path = abs_path(path)
        lprint('PATH', _path, verbose=verbose)
        super(TTBase, self).__init__(_path)
        self.hint = hint or self.hint
        self.tmpl = tmpl or get_current_engine().tank.templates[self.hint]

        self.project = pipe.Project(path)
        if self.project != pipe.cur_project():
            raise ValueError('Not current project ' + self.path)

        try:
            self.data = data or self.tmpl.get_fields(self.path)
        except tank.TankError as _exc:
            lprint('TANK ERROR', _exc.message, verbose=verbose)
            raise ValueError("Tank rejected {} {}".format(
                self.hint, self.path))
        lprint('DATA', pprint.pformat(self.data), verbose=verbose)
        for _key, _val in self.data.items():
            _key = _key.lower()
            if getattr(self, _key, None) is not None:
                continue
            setattr(self, _key, _val)
Esempio n. 3
0
    def __init__(self, path, hint=None, verbose=0):
        """Constructor.

        Args:
            path (str): path to object
            hint (str): template name
            verbose (int): print process data
        """
        _raw_path = abs_path(path)
        _hint = hint or self.hint
        _tmpl = get_current_engine().tank.templates[_hint]
        _def = abs_path(_tmpl.definition, root=pipe.Project(path).path)
        _path = '/'.join(_raw_path.split('/')[:_def.count('/') + 1])
        if verbose:
            print 'RAW PATH', _raw_path
            print 'PATH    ', _path
        super(TTDirBase, self).__init__(_path, hint=hint, tmpl=_tmpl)
Esempio n. 4
0
def create_workspaces(root, force=False, verbose=0):
    """Create workspaces within the given root asset/shot.

    This creates paths on disk for all of the steps which are attached
    to the root in shotgun.

    Args:
        root (TTRoot): asset/shot to create workspaces for
        force (bool): create workspaces without confirmation
        verbose (int): print process data
    """
    _proj = pipe.Project(root.path)
    _tk = tank.Sgtk(_proj.path)
    _ctx = _tk.context_from_path(_proj.path)

    # Set filter
    _filters = [
        ['project', 'is', _ctx.project],
        ['step', 'is_not', None],
        ['entity', 'is', root.get_sg_data()],
    ]

    # Find tasks
    _sg = tank.platform.current_engine().shotgun
    _all_tasks = _sg.find('Task',
                          _filters,
                          fields=['project', 'entity', 'step'])
    _key = lambda t: (t['project']['id'], t['entity']['id'], t['step']['id'])
    _all_tasks.sort(key=_key)
    _grouped_by_entity = collections.defaultdict(list)
    for _task in _all_tasks:
        _grouped_by_entity[(_task['entity']['type'], _task['entity']['id'],
                            _task['entity']['name'])].append(_task)

    # Find tasks which need creating
    _to_create = []
    for (_entity_type, _entity_id,
         _entity_name), _tasks in sorted(_grouped_by_entity.items()):
        if _entity_type not in ('Asset', 'Shot', 'Sequence'):
            continue
        _entity_id_list = [_task['id'] for _task in _tasks]
        lprint(' - CREATE WORKSPACES',
               _entity_type,
               _entity_id,
               _entity_name,
               _entity_id_list,
               verbose=verbose)
        _to_create.append(
            (_entity_type, _entity_id, _entity_name, _entity_id_list))

    # Execute creation
    if not force:
        qt.ok_cancel('Create {:d} workspace{}?'.format(len(_to_create),
                                                       get_plural(_to_create)))
    _done = list()
    for _entity_type, _entity_id, _entity_name, _entity_id_list in _to_create:
        _key = (_entity_type, _entity_id)
        if _key in _done:
            continue
        _start = time.time()
        print ' - CREATE WORKSPACES {}'.format('/'.join(
            [_ctx.project['name'], _entity_type, _entity_name]))
        _tk.create_filesystem_structure('Task', _entity_id_list)
        print ' - CREATED WORKSPACES FOR {} ({:.01f}s)'.format(
            '/'.join([_ctx.project['name'], _entity_type, _entity_name]),
            time.time() - _start)
        _done.append(_key)