Exemple #1
0
def run(entity_type, selected_ids, **kwargs):

    sgfs = SGFS()
    paths = []

    for id_ in selected_ids:
        entity = sgfs.session.merge(dict(type=entity_type, id=id_))
        path = sgfs.path_for_entity(entity)
        if path:
            print entity, '->', repr(path)
            paths.append(path)

    if not paths:
        notify('No paths for %s %s' % (entity_type, selected_ids))
        return

    notify('Opened ' + ', '.join(sorted(paths)))

    path = paths[0]
    if sys.platform.startswith('darwin'):
        call(['open', '-a', 'Terminal', path])
    else:
        terminal_cmd = 'gnome-terminal'
        if 'MATE_DESKTOP_SESSION_ID' in os.environ:
            terminal_cmd = 'mate-terminal'
        call([terminal_cmd, '--working-directory', path])
Exemple #2
0
def run(entity_type, selected_ids, **kwargs):

    sgfs = SGFS()
    paths = []

    for id_ in selected_ids:
        entity = sgfs.session.merge(dict(type=entity_type, id=id_))
        path = sgfs.path_for_entity(entity)
        if path:
            print entity, "->", repr(path)
            paths.append(path)

    if not paths:
        notify("No paths for %s %s" % (entity_type, selected_ids))
        return

    notify("Opened " + ", ".join(sorted(paths)))

    path = paths[0]
    if sys.platform.startswith("darwin"):
        call(["open", "-a", "Terminal", path])
    else:
        terminal_cmd = "gnome-terminal"
        if "MATE_DESKTOP_SESSION_ID" in os.environ:
            terminal_cmd = "mate-terminal"
        call([terminal_cmd, "--working-directory", path])
Exemple #3
0
def _run(dry_run, entity_type, selected_ids, **kwargs):
    
    title='Preview Folders' if dry_run else 'Creating Folders'
    verb = 'previewing' if dry_run else 'creating'

    progress(message=('Previewing' if dry_run else 'Creating') + ' folders for %s %ss; please wait...' % (len(selected_ids), entity_type))

    sgfs = SGFS()
    
    entities = sgfs.session.merge([dict(type=entity_type, id=id_) for id_ in selected_ids])
    heirarchy = sgfs.session.fetch_heirarchy(entities)
    sgfs.session.fetch_core(heirarchy)
    
    command_log = sgfs.create_structure(entities, dry_run=dry_run)
    
    if command_log:
        details = '\n'.join(command_log)
        if dry_run:
            alert(title='Folder Preview', message=details)
        else:
            notify(
                message='Created folders for %s %ss.' % (len(selected_ids), entity_type),
                details=details,
            )
    else:
        notify(message='Folders are already up to date.')
Exemple #4
0
def _run(dry_run, entity_type, selected_ids, **kwargs):

    title = 'Preview Folders' if dry_run else 'Creating Folders'
    verb = 'previewing' if dry_run else 'creating'

    progress(message=('Previewing' if dry_run else 'Creating') +
             ' folders for %s %ss; please wait...' %
             (len(selected_ids), entity_type))

    sgfs = SGFS()

    entities = sgfs.session.merge(
        [dict(type=entity_type, id=id_) for id_ in selected_ids])
    heirarchy = sgfs.session.fetch_heirarchy(entities)
    sgfs.session.fetch_core(heirarchy)

    command_log = sgfs.create_structure(entities, dry_run=dry_run)

    if command_log:
        details = '\n'.join(command_log)
        if dry_run:
            alert(title='Folder Preview', message=details)
        else:
            notify(
                message='Created folders for %s %ss.' %
                (len(selected_ids), entity_type),
                details=details,
            )
    else:
        notify(message='Folders are already up to date.')
def _run(dry_run, entity_type, selected_ids, **kwargs):
    
    sgfs = SGFS()
    
    entities = sgfs.session.merge([dict(type=entity_type, id=id_) for id_ in selected_ids])
    heirarchy = sgfs.session.fetch_heirarchy(entities)
    sgfs.session.fetch_core(heirarchy)
    
    commands = sgfs.create_structure(entities, dry_run=dry_run)
    
    notify(
        title='Preview Folders' if dry_run else 'Creating Folders',
        message='\n'.join(commands) or 'Everything is up to date.',
    )
Exemple #6
0
def run(entity_type, selected_ids, **kwargs):
    
    sgfs = SGFS()

    entity = sgfs.session.merge(dict(type=entity_type, id=selected_ids[0]))
    path = sgfs.path_for_entity(entity)
    
    if not path:
        notify('No folders for %s %s' % (entity['type'], entity['id']))
        return
    
    print entity, '->', repr(path)
    
    # Signal to maya what entity this is.
    env = dict(os.environ)
    env['SGFS_ENTITY_TYPE'] = entity['type']
    env['SGFS_ENTITY_ID'] = str(entity['id'])
    
    call(['maya_launcher'], cwd=path, env=env)
def run(entity_type, selected_ids, **kwargs):
    sgfs = SGFS()

    for id_ in selected_ids:

        entity = sgfs.session.merge({'type': entity_type, 'id': id_})
        task, code, version, frames_path, movie_path = entity.fetch(
            ('sg_link', 'code', 'sg_version', 'sg_path_to_frames',
             'sg_path_to_movie'))

        # Can't promote it without a movie.
        if not (frames_path or movie_path):
            notify('Version "%s_v%04d" does not have frames or a movie' %
                   (code, version),
                   sticky=True)
            continue

        # Make sure it doesn't already exist.
        existing = sgfs.session.find('Version', [
            ('sg_task', 'is', task),
            ('code', 'is', '%s_v%04d' % (code, version)),
        ])
        if existing:
            notify('Version "%s_v%04d" already exists' % (code, version),
                   sticky=True)
            continue

        versions.promote_publish(entity)
        notify('Promoted to version "%s_v%04d"' %
               (entity['code'], entity['sg_version']))
Exemple #8
0
def run(entity_type, selected_ids, **kwargs):

    sgfs = SGFS()
    paths = []

    for id_ in selected_ids:
        entity = sgfs.session.merge(dict(type=entity_type, id=id_))
        path = sgfs.path_for_entity(entity)
        if path:
            print entity, '->', repr(path)
            paths.append(path)

    if not paths:
        notify('No paths for %s %s' % (entity_type, selected_ids))
        return

    notify('Opening:\n' + '\n'.join(sorted(paths)))

    for path in set(paths):
        if sys.platform.startswith('darwin'):
            call(['open', path])
        else:
            call(['xdg-open', path])
Exemple #9
0
def run(entity_type, selected_ids, **kwargs):
    
    sgfs = SGFS()
    paths = []
    
    for id_ in selected_ids:
        entity = sgfs.session.merge(dict(type=entity_type, id=id_))
        path = sgfs.path_for_entity(entity)
        if path:
            print entity, '->', repr(path)
            paths.append(path)
    
    if not paths:
        notify('No paths for %s %s' % (entity_type, selected_ids))
        return
    
    notify('Opened ' + ', '.join(sorted(paths)))
    
    for path in set(paths):
        if sys.platform.startswith('darwin'):
            call(['open', path])
        else:
            call(['xdg-open', path])
def run(entity_type, selected_ids, **kwargs):
    sgfs = SGFS()
    
    for id_ in selected_ids:
        
        entity = sgfs.session.merge({'type': entity_type, 'id': id_})
        task, code, version, frames_path, movie_path = entity.fetch(('sg_link', 'code', 'sg_version', 'sg_path_to_frames', 'sg_path_to_movie'))
        
        # Can't promote it without a movie.
        if not (frames_path or movie_path):
            notify('Version "%s_v%04d" does not have frames or a movie' % (code, version), sticky=True)
            continue
        
        # Make sure it doesn't already exist.
        existing = sgfs.session.find('Version', [
            ('sg_task', 'is', task),
            ('code', 'is', '%s_v%04d' % (code, version)),
        ])
        if existing:
            notify('Version "%s_v%04d" already exists' % (code, version), sticky=True)
            continue
        
        versions.promote_publish(entity)
        notify('Promoted to version "%s_v%04d"' % (entity['code'], entity['sg_version']))    
Exemple #11
0
def republish(entity_type, selected_ids, type_name, type_code):

    # no fancy UI needed here
    assert entity_type == 'PublishEvent'
    assert selected_ids

    title = 'Republish as %s' % type_name

    progress(title=title, message='Fetching entities...')

    sgfs = SGFS()

    entities = [sgfs.session.merge(dict(type='PublishEvent', id=id_)) for id_ in selected_ids]
    sgfs.session.fetch(entities, ('code', 'sg_link', 'sg_link.Task.entity', 'sg_type', 'sg_path'))


    futures = []
    errors = []

    executor = Executor()

    for i, publish in enumerate(entities):

        if publish['sg_type'] == type_code:
            errors.append('Publish %d is already a %s.' % (publish['id'], type_code))
            continue

        link = publish['sg_link']
        owner = publish.get('sg_link.Task.entity')
        owner_name = owner.name if owner else str(link)
        future_name = 'Republish %s as %s - %s:%s' % (publish['sg_type'], type_code, owner_name, link.name)

        progress(title=title, message='Submitting %s/%s to Qube:\n<em>"%s"</em>' % (i + 1, len(entities), future_name))

        maya_scene = get_maya_scene(publish)
        thumbnail = os.path.join(os.path.dirname(maya_scene), 'thumbnail.jpg')
        thumbnail = thumbnail if os.path.exists(thumbnail) else ''

        if type_code == 'maya_scene':
            future = executor.submit_ext('sgpublish.commands.publish:main',
                args=[(
                    '--link', '%(type)s:%(id)d' % publish['sg_link'],
                    '--code', publish['code'],
                    '--type', type_code,
                    '--thumbnail', thumbnail,
                    maya_scene
                )],
                name=future_name,
                priority=8000,
            )
            futures.append(future)

        elif type_code == 'maya_geocache':
            future = executor.submit_ext('mayatools.geocache.exporter:main',
                args=[(
                    '--publish-link', '%(type)s:%(id)d' % publish['sg_link'],
                    '--publish-name', publish['code'],
                    '--publish-thumbnail', thumbnail,
                    maya_scene,
                )],
                name=future_name,
                interpreter='maya2014_python',
                priority=8000,
            )
            futures.append(future)

        elif type_code == 'maya_camera':
            future = executor.submit_ext('mayatools.camera.exporter:main',
                args=[(
                    '--publish-link', '%(type)s:%(id)d' % publish['sg_link'],
                    '--publish-name', publish['code'],
                    '--publish-thumbnail', thumbnail,
                    maya_scene,
                )],
                name=future_name,
                interpreter='maya2014_python',
                priority=8000,
            )
            futures.append(future)

        else:
            errors.append('Unknown publish type %r.' % type_code)

    messages = []
    if futures:
        messages.append('Submitted to Qube as %s' % ', '.join(str(f.job_id) for f in futures))
    if errors:
        messages.extend('<span style="color:red">%s</span>' % e for e in errors)
    notify(title=title, message='\n'.join(messages))
Exemple #12
0
def run_play(entity_type, selected_ids, **kwargs):

    sgfs = SGFS()
    entities = sgfs.session.get(entity_type, selected_ids)

    if entity_type == 'PublishEvent':
        sgfs.session.fetch(entities,
                           ('code', 'sg_type', 'path_to_frames',
                            'path_to_movie', 'path', 'link.Task.entity'))
    elif entity_type == 'Version':
        sgfs.session.fetch(
            entities, ('code', 'path_to_frames', 'path_to_movie', 'entity'))
    else:
        alert('Cannot play %s entities in RV.' % entity_type)
        return

    chunks = []

    for entity in entities:

        skipped_exts = []

        for path_key in ('path_to_frames', 'path_to_movie', 'path'):

            path = (entity.get(path_key) or '').strip()
            if not path:
                continue

            ext = os.path.splitext(path)[1]
            if ext not in PLAYABLE_EXTS:
                skipped_exts.append(ext)
                continue

            notify('Opening %s in RV...' % path)

            # Convert any %04d into ####
            rv_path = re.sub(r'(?:%0?(\d)[sd])',
                             lambda m: '#' * int(m.group(1)), path)

            # Go looking for audio.
            if entity_type == 'PublishEvent':
                shot = entity['link.Task.entity']
            else:
                shot = entity['entity']
            if shot:
                audio = sgfs.session.find_one('PublishEvent', [
                    ('sg_type', 'is', 'audio'),
                    ('link.Task.entity', 'is', shot),
                ], ['path'])
            else:
                audio = None

            # Open it (optionally with audio).
            if audio:
                chunks.extend(('[', rv_path, audio['path'], ']'))
            else:
                chunks.append(rv_path)
            break

        else:
            if skipped_exts:
                alert(
                    """We don't know how to play %s %d ("%s") with %s extensions."""
                    % (entity['sg_type'] + ' Publish' if entity_type
                       == 'PublishEvent' else entity_type, entity['id'],
                       entity['code'], '/'.join(sorted(skipped_exts))))
            else:
                alert("""%s %d ("%s") has nothing to play.""" % (
                    entity['sg_type'].title() + ' Publish'
                    if entity_type == 'PublishEvent' else entity_type,
                    entity['id'],
                    entity['code'],
                ))
            return

    if chunks:
        # -l -> use lookahead cache
        # -play -> play immediately
        rvlink(['-l'] + chunks)
    else:
        alert("We don't know how to play %s entities." % entity_type)
Exemple #13
0
def republish(entity_type, selected_ids, type_name, type_code):

    # no fancy UI needed here
    assert entity_type == 'PublishEvent'
    assert selected_ids

    progress('Fetching entities...')

    sgfs = SGFS()

    entities = [
        sgfs.session.merge(dict(type=entity_type, id=id_))
        for id_ in selected_ids
    ]
    sgfs.session.fetch(entities,
                       ('code', 'sg_link', 'sg_link.Task.entity', 'sg_type',
                        'sg_path', 'created_by.HumanUser.login'))

    futures = []
    errors = []

    executor = Executor()

    for i, publish in enumerate(entities):

        if publish['sg_type'] == type_code:
            errors.append('Publish %d is already a %s.' %
                          (publish['id'], type_code))
            continue

        link = publish['sg_link']
        owner = publish.get('sg_link.Task.entity')
        owner_name = owner.name if owner else str(link)
        future_name = 'Republish %s as %s - %s:%s' % (
            publish['sg_type'], type_code, owner_name, link.name)

        progress('Submitting %s/%s to Qube:\n<em>"%s"</em>' %
                 (i + 1, len(entities), future_name))

        maya_scene = get_maya_scene(publish)

        # Run the job as the original user.
        qb_extra = {}
        login = publish.get('created_by.HumanUser.login')
        if login:
            qb_extra['user'] = login.split('@')[0]

        if type_code == 'maya_scene':
            future = executor.submit_ext('sgpublish.commands.create:main',
                                         args=[
                                             ('--template', str(publish['id']),
                                              '--type', type_code, maya_scene)
                                         ],
                                         name=future_name,
                                         priority=8000,
                                         **qb_extra)
            futures.append(future)

        elif type_code == 'maya_geocache':
            future = executor.submit_ext('mayatools.geocache.exporter:main',
                                         args=[(
                                             '--publish-template',
                                             str(publish['id']),
                                             maya_scene,
                                         )],
                                         name=future_name,
                                         interpreter='maya2014_python',
                                         priority=8000,
                                         **qb_extra)
            futures.append(future)

        elif type_code == 'maya_camera':
            future = executor.submit_ext('mayatools.camera.exporter:main',
                                         args=[(
                                             '--publish-template',
                                             str(publish['id']),
                                             maya_scene,
                                         )],
                                         name=future_name,
                                         interpreter='maya2014_python',
                                         priority=8000,
                                         **qb_extra)
            futures.append(future)

        else:
            errors.append('Unknown publish type %r.' % type_code)

    messages = []
    if futures:
        messages.append('Submitted to Qube as %s' %
                        ', '.join(str(f.job_id) for f in futures))
    if errors:
        messages.extend('<span style="color:red">%s</span>' % e
                        for e in errors)
    notify('; '.join(messages))
Exemple #14
0
def republish(entity_type, selected_ids, type_name, type_code):

    # no fancy UI needed here
    assert entity_type == 'PublishEvent'
    assert selected_ids

    title = 'Republish as %s' % type_name

    progress(title=title, message='Fetching entities...')

    sgfs = SGFS()

    entities = [
        sgfs.session.merge(dict(type='PublishEvent', id=id_))
        for id_ in selected_ids
    ]
    sgfs.session.fetch(
        entities,
        ('code', 'sg_link', 'sg_link.Task.entity', 'sg_type', 'sg_path'))

    futures = []
    errors = []

    executor = Executor()

    for i, publish in enumerate(entities):

        if publish['sg_type'] == type_code:
            errors.append('Publish %d is already a %s.' %
                          (publish['id'], type_code))
            continue

        link = publish['sg_link']
        owner = publish.get('sg_link.Task.entity')
        owner_name = owner.name if owner else str(link)
        future_name = 'Republish %s as %s - %s:%s' % (
            publish['sg_type'], type_code, owner_name, link.name)

        progress(title=title,
                 message='Submitting %s/%s to Qube:\n<em>"%s"</em>' %
                 (i + 1, len(entities), future_name))

        maya_scene = get_maya_scene(publish)
        thumbnail = os.path.join(os.path.dirname(maya_scene), 'thumbnail.jpg')
        thumbnail = thumbnail if os.path.exists(thumbnail) else ''

        if type_code == 'maya_scene':
            future = executor.submit_ext(
                'sgpublish.commands.publish:main',
                args=[('--link', '%(type)s:%(id)d' % publish['sg_link'],
                       '--code', publish['code'], '--type', type_code,
                       '--thumbnail', thumbnail, maya_scene)],
                name=future_name,
                priority=8000,
            )
            futures.append(future)

        elif type_code == 'maya_geocache':
            future = executor.submit_ext(
                'mayatools.geocache.exporter:main',
                args=[(
                    '--publish-link',
                    '%(type)s:%(id)d' % publish['sg_link'],
                    '--publish-name',
                    publish['code'],
                    '--publish-thumbnail',
                    thumbnail,
                    maya_scene,
                )],
                name=future_name,
                interpreter='maya2014_python',
                priority=8000,
            )
            futures.append(future)

        elif type_code == 'maya_camera':
            future = executor.submit_ext(
                'mayatools.camera.exporter:main',
                args=[(
                    '--publish-link',
                    '%(type)s:%(id)d' % publish['sg_link'],
                    '--publish-name',
                    publish['code'],
                    '--publish-thumbnail',
                    thumbnail,
                    maya_scene,
                )],
                name=future_name,
                interpreter='maya2014_python',
                priority=8000,
            )
            futures.append(future)

        else:
            errors.append('Unknown publish type %r.' % type_code)

    messages = []
    if futures:
        messages.append('Submitted to Qube as %s' %
                        ', '.join(str(f.job_id) for f in futures))
    if errors:
        messages.extend('<span style="color:red">%s</span>' % e
                        for e in errors)
    notify(title=title, message='\n'.join(messages))
Exemple #15
0
def run_play(entity_type, selected_ids, **kwargs):

    sgfs = SGFS()
    entities = sgfs.session.get(entity_type, selected_ids)

    if entity_type == "PublishEvent":
        sgfs.session.fetch(entities, ("code", "sg_type", "path_to_frames", "path_to_movie", "path", "link.Task.entity"))
    elif entity_type == "Version":
        sgfs.session.fetch(entities, ("code", "path_to_frames", "path_to_movie", "entity"))
    else:
        alert("Cannot play %s entities in RV." % entity_type)
        return

    chunks = []

    for entity in entities:

        skipped_exts = []

        for path_key in ("path_to_frames", "path_to_movie", "path"):

            path = (entity.get(path_key) or "").strip()
            if not path:
                continue

            ext = os.path.splitext(path)[1]
            if ext not in PLAYABLE_EXTS:
                skipped_exts.append(ext)
                continue

            notify("Opening %s in RV..." % path)

            # Convert any %04d into ####
            rv_path = re.sub(r"(?:%0?(\d)[sd])", lambda m: "#" * int(m.group(1)), path)

            # Go looking for audio.
            if entity_type == "PublishEvent":
                shot = entity["link.Task.entity"]
            else:
                shot = entity["entity"]
            if shot:
                audio = sgfs.session.find_one(
                    "PublishEvent", [("sg_type", "is", "audio"), ("link.Task.entity", "is", shot)], ["path"]
                )
            else:
                audio = None

            # Open it (optionally with audio).
            if audio:
                chunks.extend(("[", rv_path, audio["path"], "]"))
            else:
                chunks.append(rv_path)
            break

        else:
            if skipped_exts:
                alert(
                    """We don't know how to play %s %d ("%s") with %s extensions."""
                    % (
                        entity["sg_type"] + " Publish" if entity_type == "PublishEvent" else entity_type,
                        entity["id"],
                        entity["code"],
                        "/".join(sorted(skipped_exts)),
                    )
                )
            else:
                alert(
                    """%s %d ("%s") has nothing to play."""
                    % (
                        entity["sg_type"].title() + " Publish" if entity_type == "PublishEvent" else entity_type,
                        entity["id"],
                        entity["code"],
                    )
                )
            return

    if chunks:
        # -l -> use lookahead cache
        # -play -> play immediately
        rvlink(["-l"] + chunks)
    else:
        alert("We don't know how to play %s entities." % entity_type)
Exemple #16
0
def republish(entity_type, selected_ids, type_name, type_code):

    # no fancy UI needed here
    assert entity_type == 'PublishEvent'
    assert selected_ids

    progress('Fetching entities...')

    sgfs = SGFS()

    entities = [sgfs.session.merge(dict(type=entity_type, id=id_)) for id_ in selected_ids]
    sgfs.session.fetch(entities, ('code', 'sg_link', 'sg_link.Task.entity', 'sg_type', 'sg_path',
        'created_by.HumanUser.login'))

    futures = []
    errors = []

    executor = Executor()

    for i, publish in enumerate(entities):

        if publish['sg_type'] == type_code:
            errors.append('Publish %d is already a %s.' % (publish['id'], type_code))
            continue

        link = publish['sg_link']
        owner = publish.get('sg_link.Task.entity')
        owner_name = owner.name if owner else str(link)
        future_name = 'Republish %s as %s - %s:%s' % (publish['sg_type'], type_code, owner_name, link.name)

        progress('Submitting %s/%s to Qube:\n<em>"%s"</em>' % (i + 1, len(entities), future_name))

        maya_scene = get_maya_scene(publish)

        # Run the job as the original user.
        qb_extra = {}
        login = publish.get('created_by.HumanUser.login')
        if login:
            qb_extra['user'] = login.split('@')[0]

        if type_code == 'maya_scene':
            future = executor.submit_ext('sgpublish.commands.create:main',
                args=[(
                    '--template', str(publish['id']),
                    '--type', type_code,
                    maya_scene
                )],
                name=future_name,
                priority=8000,
                **qb_extra
            )
            futures.append(future)

        elif type_code == 'maya_geocache':
            future = executor.submit_ext('mayatools.geocache.exporter:main',
                args=[(
                    '--publish-template', str(publish['id']),
                    maya_scene,
                )],
                name=future_name,
                interpreter='maya2014_python',
                priority=8000,
                **qb_extra
            )
            futures.append(future)

        elif type_code == 'maya_camera':
            future = executor.submit_ext('mayatools.camera.exporter:main',
                args=[(
                    '--publish-template', str(publish['id']),
                    maya_scene,
                )],
                name=future_name,
                interpreter='maya2014_python',
                priority=8000,
                **qb_extra
            )
            futures.append(future)

        else:
            errors.append('Unknown publish type %r.' % type_code)

    messages = []
    if futures:
        messages.append('Submitted to Qube as %s' % ', '.join(str(f.job_id) for f in futures))
    if errors:
        messages.extend('<span style="color:red">%s</span>' % e for e in errors)
    notify('; '.join(messages))