コード例 #1
0
class NewSequence(Action):
    '''Create a new Sequence'''

    label = 'New Sequence'
    identifier = 'new.sequence'
    returns = artifact('sequence')

    @staticmethod
    def parameters(ctx):
        params = dict(project={
            'label': 'Project',
            'help': 'Project Entry',
            'required': True,
            'type': types.Entry,
        },
                      collection={
                          'label': 'Collection',
                          'help': 'Collection Name',
                          'required': True,
                          'type': types.String
                      },
                      name={
                          'label': 'Sequence Name',
                          'required': True,
                          'type': types.String,
                          'help': 'Name of sequence',
                      },
                      template={
                          'label': 'Sequence Template',
                          'required': False,
                          'type': types.String,
                          'help': 'Name of sequence template'
                      })

        if not ctx:
            return params

        if ctx.project:
            params['project']['default'] = ctx.project
            params['project']['required'] = False

            # TODO: fix search speed upstream...
            # collection_types = [e.name for e in ctx.project.collections]
            # params['collection']['options'] = collection_types

        if ctx.collection:
            params['collection']['default'] = ctx.collection.name
            params['collection']['required'] = False

        templates = list(api.get_templates('sequence').keys())
        if templates:
            params['template']['default'] = templates[0]
            params['template']['options'] = templates

        return params

    @staticmethod
    def available(ctx):
        return (ctx.project and ctx.collection and not ctx.sequence
                and not ctx.asset_type)
コード例 #2
0
class NewProject(Action):
    '''Create a new Project'''

    label = 'New Project'
    identifier = 'new.project'
    returns = artifact('project')

    @classmethod
    def parameters(cls, ctx):
        params = dict(root={
            'label': 'Project Root',
            'required': True,
            'type': types.String,
            'help': 'project root directory',
        },
                      template={
                          'label': 'Project Template',
                          'required': True,
                          'type': types.String,
                          'help': 'name of a project template',
                      })

        if not ctx:
            return params

        templates = list(api.get_templates('project').keys())
        params['template']['options'] = templates
        if templates:
            params['template']['default'] = templates[0]

        return params

    @staticmethod
    def available(ctx):
        return not ctx.project
コード例 #3
0
class SetWorkspace(Action):
    '''Set the current workspace'''

    label = 'Set Workspace'
    identifier = 'set_workspace'
    returns = artifact('workspace')

    @staticmethod
    def parameters(ctx):
        params = dict(
            task={
                'label': 'Parent Entry',
                'required': True,
                'type': types.Entry,
                'help': 'Parent entry of workspace',
            },
            name={
                'label': 'Workspace Name',
                'required': True,
                'type': types.String,
                'help': 'Name of workspace'
            },
            template={
                'label': 'Workspace template Name',
                'required': True,
                'type': types.String,
                'help': 'Name of template to use if the task has no workspace'
            })

        if not ctx:
            return params

        if ctx.task:
            params['task']['default'] = ctx.task
            params['task']['required'] = False

        # Get default workspace for this host
        host = api.get_host()
        params['name']['default'] = host.name

        default_workspace = host.name
        for name, data in api.config['SOFTWARE'].items():
            if data['host'] == host.name:
                default_workspace = data['default_workspace']
                break

        template = api.get_template(default_workspace, 'workspace')
        if template:
            params['template']['default'] = template.name

        templates = api.get_templates('workspace')
        if templates:
            params['template']['options'] = list(templates.keys())

        return params

    @staticmethod
    def available(ctx):
        return ctx.host != 'cli' and ctx.project
コード例 #4
0
class NewTask(Action):
    '''Create a new Task'''

    label = 'New Task'
    identifier = 'new.task'
    returns = artifact('task')

    @staticmethod
    def parameters(ctx):
        params = dict(parent={
            'label': 'Parent Entry',
            'required': True,
            'type': types.Entry,
            'help': 'Parent entry of task',
        },
                      type={
                          'label': 'Task Type',
                          'required': True,
                          'type': types.String,
                          'help': 'Type of task',
                      },
                      name={
                          'label': 'Task Name',
                          'required': False,
                          'type': types.String,
                          'help': 'Name of task'
                      },
                      template={
                          'label': 'Task Template Name',
                          'required': False,
                          'type': types.String,
                          'help': 'Name of task template'
                      })

        if not ctx:
            return params

        params['type']['options'] = list(config['TASK_TYPES'].keys())

        if ctx.shot:
            params['parent']['default'] = ctx.shot
            params['parent']['required'] = False

        elif ctx.asset:
            params['parent']['default'] = ctx.asset
            params['parent']['required'] = False

        templates = list(api.get_templates('task').keys())
        if templates:
            params['template']['options'] = templates
            params['template']['default'] = templates[0]

        return params

    @staticmethod
    def available(ctx):
        return (ctx.project and (ctx.shot or ctx.asset) and not ctx.task)
コード例 #5
0
class Publish(Action):
    '''Publish the current open file'''

    label = 'Publish'
    identifier = 'publish'
    returns = artifact('file')

    @staticmethod
    def parameters(ctx):
        return {}

    @staticmethod
    def available(ctx):
        return ctx.host != 'cli' and ctx.task and ctx.file
コード例 #6
0
class NewCollection(Action):
    '''Create a new Collection'''

    label = 'New Collection'
    identifier = 'new.collection'
    returns = artifact('collection')

    @staticmethod
    def parameters(ctx):
        params = dict(
            project={
                'label': 'Project',
                'help': 'Project Entry',
                'required': True,
                'type': types.Entry,
            },
            name={
                'label': 'Collection Name',
                'required': True,
                'type': types.String,
                'help': 'Name of Collection',
            },
            template={
                'label': 'Collection Template',
                'require': False,
                'type': types.String,
                'help': 'Name of template',
            },
        )

        if not ctx:
            return params

        if ctx.project:
            params['project']['default'] = ctx.project
            params['project']['required'] = False

        templates = list(api.get_templates('collection').keys())
        if templates:
            params['template']['options'] = templates
            params['template']['default'] = templates[0]

        return params

    @staticmethod
    def available(ctx):
        return (ctx.project and not ctx.collection)
コード例 #7
0
class NewAssetType(Action):
    '''Create a new Asset Type'''

    label = 'New Asset Type'
    identifier = 'new.asset_type'
    returns = artifact('asset_type')

    @staticmethod
    def parameters(ctx):
        params = dict(
            project={
                'label': 'Project',
                'help': 'Project Entry',
                'required': True,
                'type': types.Entry,
            },
            collection={
                'label': 'Collection',
                'help': 'Collection Name',
                'required': True,
                'type': types.String
            },
            name={
                'label': 'Asset Type Name',
                'required': True,
                'type': types.String,
                'help': 'Name of Asset Type',
            },
        )

        if not ctx:
            return params

        if ctx.project:
            params['project']['default'] = ctx.project
            params['project']['required'] = False

        if ctx.collection:
            params['collection']['default'] = ctx.collection.name
            params['collection']['required'] = False

        return params

    @staticmethod
    def available(ctx):
        return (ctx.project and ctx.collection and not ctx.asset_type
                and not ctx.sequence)
コード例 #8
0
class NewWorkspace(Action):
    '''Create a new Workspace'''

    label = 'New Workspace'
    identifier = 'new.workspace'
    returns = artifact('workspace')

    @staticmethod
    def parameters(ctx):
        params = dict(task={
            'label': 'Parent Entry',
            'required': True,
            'type': types.Entry,
            'help': 'Parent entry of workspace',
        },
                      name={
                          'label': 'Workspace Name',
                          'required': True,
                          'type': types.String,
                          'help': 'Name of workspace'
                      },
                      template={
                          'label': 'Workspace Template Name',
                          'required': True,
                          'type': types.String,
                          'help': 'Name of workspace template'
                      })

        if not ctx:
            return params

        if ctx.task:
            params['task']['default'] = ctx.task
            params['task']['required'] = False

        templates = api.get_templates('workspace')
        if templates:
            params['template']['options'] = list(templates.keys())

        return params

    @staticmethod
    def available(ctx):
        return (ctx.project and (ctx.shot or ctx.asset) and ctx.task
                and not ctx.workspace)
コード例 #9
0
class NewTemplate(Action):
    '''Create a new Template from an Entry'''

    label = 'New Template'
    identifier = 'new.template'
    returns = artifact('template')

    @staticmethod
    def parameters(ctx):
        params = dict(name={
            'label': 'Template Name',
            'required': True,
            'type': types.String,
            'help': 'Name of new template',
        },
                      entry={
                          'label': 'Entry',
                          'required': True,
                          'type': types.Entry,
                          'help': 'Entry to create template from',
                      },
                      include_files={
                          'label': 'Include Files',
                          'type': bool,
                          'default': False,
                          'help':
                          'Include all files in entry not just entry data',
                      })
        if not ctx:
            return params

        if ctx.host == 'cli':
            params['entry']['default'] = ctx.get_deepest_entry()

        return params

    @staticmethod
    def available(ctx):
        return False
コード例 #10
0
        template=template,
    )


@task(priority=types.VALIDATE)
@requires(success('stage_shot'))
@params(store('shot_item'))
def validate_shot(shot_item):
    '''Make sure shot does not exist'''

    if os.path.exists(shot_item['path']):
        raise Abort('Shot already exists: ' + shot_item['name'])
    return True


@task(priority=types.COMMIT)
@requires(success('validate_shot'))
@params(store('shot_item'))
@returns(artifact('shot'))
def commit_shot(shot_item):
    '''Create new shot'''

    if shot_item['template']:
        shot = shot_item['template'].copy(shot_item['path'])
    else:
        shot = fsfs.get_entry(shot_item['path'])

    shot.tag(*shot_item['tags'])

    return shot
コード例 #11
0
        template=api.get_template(template, 'task'),
    )


@task(priority=types.VALIDATE)
@requires(success('stage_task'))
@params(store('task_item'))
def validate_task(task_item):
    '''Validate potential task'''

    if os.path.exists(task_item['path']):
        raise Abort('Task already exists: ' + task_item['name'])
    return True


@task(priority=types.COMMIT)
@requires(success('validate_task'))
@params(store('task_item'))
@returns(artifact('task'))
def commit_task(task_item):
    '''Create new task'''

    if task_item['template']:
        task = task_item['template'].copy(task_item['path'])
    else:
        task = fsfs.get_entry(task_item['path'])

    task.tag(*task_item['tags'])

    return task
コード例 #12
0
    template_item = types.Namespace(
        entry=entry,
        name=name,
        path=template_path,
        include_files=include_files,
    )
    return template_item


@task(priority=types.VALIDATE)
@requires(success('stage_template_data'))
@params(store('template'))
def validate_template(template):
    '''Make sure template does not already exist'''

    if (os.path.exists(template.path)
            or template.name in construct.get_templates()):
        raise Abort('Template already exists: ' + template.name)


@task(priority=types.COMMIT)
@requires(success('validate_template'))
@params(store('template'))
@returns(artifact('template'))
def commit_template(template):
    '''Commit template'''

    new_template = entry.copy(template_path, only_data=not include_files)
    return new_template
コード例 #13
0
@task(priority=types.VALIDATE)
@requires(success('stage_workspace'))
@params(store('workspace_item'))
def validate_workspace(workspace_item):
    '''Validate potential workspace'''

    if os.path.exists(workspace_item['path']):
        raise Abort('Task already exists: ' + workspace_item['name'])
    return True


@task(priority=types.COMMIT)
@requires(success('validate_workspace'))
@params(store('workspace_item'))
@returns(artifact('workspace'))
def commit_workspace(workspace_item):
    '''Create new workspace'''

    if workspace_item['template']:
        workspace = workspace_item['template'].copy(workspace_item['path'])
    else:
        workspace = fsfs.get_entry(workspace_item['path'])

    workspace.tag(*workspace_item['tags'])

    return workspace


class SetWorkspace(Action):
    '''Set the current workspace'''
コード例 #14
0
    )


@task(priority=types.VALIDATE)
@requires(success('stage_collection'))
@params(store('collection_item'))
def validate_collection(collection_item):
    '''Make sure new collection does not exist'''

    if os.path.exists(collection_item['path']):
        raise Abort('collection already exists: ' + collection_item['name'])

    return True


@task(priority=types.COMMIT)
@requires(success('validate_collection'))
@params(store('collection_item'))
@returns(artifact('collection'))
def commit_collection(collection_item):
    '''Make new collection'''

    if collection_item['template']:
        collection = collection_item['template'].copy(collection_item['path'])
    else:
        collection = fsfs.get_entry(collection_item['path'])

    collection.tag(*collection_item['tags'])

    return collection
コード例 #15
0
ファイル: time.py プロジェクト: construct-org/construct
@pass_kwargs
@pass_context
@returns(store('frame_range'))
def get_frame_range(ctx, asset_or_shot):
    '''Get the Asset or Shot frame range'''

    frame_range = asset_or_shot.data.get(
        'frame_range', ctx.project.data.get('frame_range',
                                            [101, 101, 580, 580]))
    return frame_range


@task
@requires(store('frame_range'))
@params(store('frame_range'))
@returns(artifact('frame_range'))
def apply_frame_range(frame_range):
    '''Applies the frame range to your current scene'''

    host = get_host()
    host.set_frame_range(*frame_range)
    return {'frame_range': frame_range}


class SaveFPS(Action):
    '''Save the frame rate for this shot or asset'''

    label = 'Save FPS'
    identifier = 'time.savefps'

    @staticmethod
コード例 #16
0
@task
@params(kwarg('modules'))
@returns(store('cpenv_modules'))
def validate_cpenv_modules(modules):
    '''Validate cpenv modules'''

    import cpenv
    modules = modules.split()
    return cpenv.resolve(modules)


@task
@requires(success('validate_cpenv_modules'))
@params(kwarg('root'), store('cpenv_modules'))
@returns(artifact('cpenv_file'))
def write_cpenv_modules(root, modules):
    '''Write a cpenv file to root'''

    resolver_str = ' '.join([m.qual_name for m in modules])
    cpenv_file = os.path.join(root.path, '.cpenv').replace('\\', '/')
    with open(cpenv_file, 'w') as f:
        f.write(resolver_str)
    return cpenv_file


@task
@params(kwarg('root'))
@returns(store('cpenv_modules'))
def get_cpenv(root):
    '''Resolve cpenv modules for the given path'''
コード例 #17
0
class Save(Action):
    '''Save the current file'''

    label = 'Save'
    identifier = 'file.save'
    returns = artifact('file')

    @staticmethod
    def parameters(ctx):
        params = dict(
            workspace={
                'label': 'Workspace',
                'required': False,
                'type': types.Entry,
                'help': 'Workspace to save to',
            },
            name={
                'label': 'Name',
                'required': False,
                'type': types.String,
                'help': 'Filename',
            },
            version={
                'label': 'Version',
                'required': True,
                'type': types.Integer,
                'help': 'File Version',
            },
            ext={
                'label': 'Extension',
                'require': True,
                'type': types.String,
                'help': 'File Extension',
            },
        )

        if not ctx:
            return params

        params['workspace']['default'] = ctx.workspace
        name = ctx.task.parent().name
        extensions = ctx.workspace.config['extensions']
        extension = extensions[0]
        path_template = get_path_template('workspace_file')
        try:
            data = path_template.parse(str(ctx.file))
        except ParseError:
            pass
        else:
            name = data['name']
            extension = data['ext']

        params['name']['default'] = name

        params['ext']['default'] = extension
        params['ext']['options'] = extensions
        params['ext']['required'] = False

        next_version = ctx.workspace.get_next_version(name, extension)
        params['version']['default'] = next_version
        params['version']['required'] = False
        return params

    @staticmethod
    def available(ctx):
        return ctx.host != 'cli' and ctx.workspace
コード例 #18
0
        template=template,
    )


@task(priority=types.VALIDATE)
@requires(success('stage_sequence'))
@params(store('sequence_item'))
def validate_sequence(sequence_item):
    '''Make sure new sequence does not exist.'''

    if os.path.exists(sequence_item['path']):
        raise Abort('Sequence already exists: ' + sequence_item['name'])
    return True


@task(priority=types.COMMIT)
@requires(success('validate_sequence'))
@params(store('sequence_item'))
@returns(artifact('sequence'))
def commit_sequence(sequence_item):
    '''Make new sequence'''

    if sequence_item['template']:
        sequence = sequence_item['template'].copy(sequence_item['path'])
    else:
        sequence = fsfs.get_entry(sequence_item['path'])

    sequence.tag(*sequence_item['tags'])

    return sequence
コード例 #19
0
@task(priority=types.VALIDATE)
@requires(success('stage_asset_type'))
@params(store('asset_type'))
def validate_asset_type(asset_type):
    '''Make sure new asset_type does not already exist'''

    if asset_type.exists:
        raise Abort('Asset Type already exists: %s' % asset_type.name)
    return True


@task(priority=types.COMMIT)
@requires(success('validate_asset_type'))
@params(store('asset_type'))
@returns(artifact('asset_type'))
def commit_asset_type(asset_type):
    '''Commit new asset_type Entry'''

    asset_type.tag('asset_type')
    return asset_type


class NewAsset(Action):
    '''Create a new Asset'''

    label = 'New Asset'
    identifier = 'new.asset'
    returns = artifact('asset')

    @staticmethod
コード例 #20
0
@returns(store('project_item'))
def stage_project(root, template):
    '''Stage project data for validation'''

    return dict(path=unipath(root),
                name=os.path.basename(root),
                template=api.get_template(template))


@task(priority=types.VALIDATE)
@params(store('project_item'))
@requires(success('stage_project'))
def validate_project(project_item):
    '''Make sure the project does not already exist.'''

    if os.path.exists(project_item['path']):
        raise Abort('Project already exists: %s' % project_item['path'])

    return True


@task(priority=types.COMMIT)
@params(store('project_item'))
@requires(success('validate_project'))
@returns(artifact('project'))
def commit_project(project_item):
    '''Copy the project template to project directory'''

    project = project_item['template'].copy(project_item['path'])
    return project