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) @task(priority=types.STAGE) @pass_kwargs @returns(store('workspace_item')) def stage_workspace(task, name=None, template=None): '''Stage workspace for creation''' path_template = api.get_path_template('workspace') path = path_template.format(dict(task=task.path, workspace=name)) name = name return dict( name=name, path=path, tags=['workspace'], template=api.get_template(template, 'workspace'), ) @task(priority=types.VALIDATE)
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) @task(priority=types.STAGE) @pass_kwargs @returns(store('task_item')) def stage_task(parent, type, name=None, template=None): '''Stage task for creation''' name = name or type return dict( name=name, path=unipath(parent.path, name), tags=['task', type], template=api.get_template(template, 'task'), ) @task(priority=types.VALIDATE) @requires(success('stage_task')) @params(store('task_item'))
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) @task(priority=types.STAGE) @pass_kwargs @returns(store('collection_item')) def stage_collection(project, name, template=None): '''Stage a new collection''' path_template = api.get_path_template('collection') collection_path = path_template.format( dict(project=project.path, collection=name)) try: template = api.get_template(template, 'collection') except KeyError: template = None return dict( name=name, path=collection_path,
import os import subprocess from construct import api from construct.utils import platform from construct.errors import Fail, Skip, Disable from construct.types import Namespace from construct.tasks import (task, pass_context, requires, success, returns, store, params, pass_args, available, artifact) from construct_launcher.constants import SETUP_LAUNCH, LAUNCH from cpenv.mappings import dict_to_env, env_to_dict, join_dicts @task(priority=SETUP_LAUNCH) @pass_context @pass_args @returns(store('app')) def setup_app(ctx, args): '''Setup application item to launch''' entry = ctx.get_deepest_entry() action = ctx.action app = Namespace( path=action.path, args=list(action.args) + list(args), name=action.name, env=dict(action.env), cwd=entry.path, host=action.host, task=ctx.task, workspace=ctx.workspace, default_workspace=action.default_workspace,
returns, artifact, store, params, success, requires, ) from construct import types, get_host, utils from construct_launcher.constants import BEFORE_LAUNCH # Before launch task @task(priority=BEFORE_LAUNCH) @requires(success('build_app_env')) @params(store('app')) def setup_construct_maya(app): '''Setup Maya environment.''' userSetup = os.path.join(os.path.dirname(__file__), 'userSetup') scpath = os.pathsep.join([userSetup, app.env.get('MAYA_SCRIPT_PATH', '')]) pypath = os.pathsep.join([ userSetup, app.env.get('PYTHONPATH', ''), os.path.join(os.path.dirname(__file__), '..') ]) app.env['MAYA_SCRIPT_PATH'] = scpath app.env['PYTHONPATH'] = pypath
def available(ctx): return ctx.host != 'cli' and ctx.task @task @pass_kwargs def store_frame_range(asset_or_shot, min, start, end, max): '''Stores the frame range in the asset or shot''' asset_or_shot.write(frame_range=[min, start, end, max]) @task @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'''
templates = list(api.get_templates('shot').keys()) if templates: params['template']['options'] = templates params['template']['default'] = sorted(templates)[0] return params @staticmethod def available(ctx): return (ctx.project and ctx.collection and ctx.sequence and not ctx.shot) @task(priority=types.STAGE) @pass_kwargs @returns(store('shot_item')) def stage_shot(project, collection, sequence, name, template=None): '''Stage a new shot Entry''' path_template = api.get_path_template('shot') shot_path = path_template.format( dict(project=project.path, collection=collection, sequence=sequence.name, shot=name)) try: template = api.get_template(template, 'shot') except KeyError: template = None
cmd = shlex.split(editor) + [cpenv_file] kwargs = { 'stdout': subprocess.PIPE, 'stderr': subprocess.STDOUT, } if platform == 'win': CREATE_NO_WINDOW = 0x08000000 kwargs['creationflags'] = CREATE_NO_WINDOW subprocess.Popen(cmd, **kwargs) @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'''
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) @task(priority=types.STAGE) @pass_kwargs @returns(store('sequence_item')) def stage_sequence(project, collection, name, template=None): '''Stage new sequence Entry''' path_template = api.get_path_template('sequence') sequence_path = path_template.format( dict(project=project.path, collection=collection, sequence=name)) try: template = api.get_template(template, 'sequence') except KeyError: template = None return dict( name=name, path=sequence_path,
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 @task(priority=types.STAGE) @pass_kwargs @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']):
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) @task(priority=types.STAGE) @pass_kwargs @returns(store('asset_type')) def stage_asset_type(project, collection, name): '''Stage new asset_type Entry''' path_template = api.get_path_template('asset_type') asset_type_path = path_template.format( dict( project=project.path, collection=collection, asset_type=name, )) return fsfs.get_entry(asset_type_path) @task(priority=types.VALIDATE)
return params if ctx.host == 'cli': params['entry']['default'] = ctx.get_deepest_entry() return params @staticmethod def available(ctx): return False @task(priority=types.STAGE) @pass_context @pass_kwargs @returns(store('template')) def stage_template(ctx, name, entry, include_files): '''Stage template data''' templates_path = unipath(ctx.project.data.path, 'templates') template_path = unipath(templates_path, name) template_item = types.Namespace( entry=entry, name=name, path=template_path, include_files=include_files, ) return template_item
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 @task @pass_kwargs @returns(store('file')) def build_filename(workspace, name, version, ext): '''Builds the full save path''' task = workspace.parent() path_template = get_path_template('workspace_file') filename = path_template.format( dict(task=task.short, name=name, version='{:0>3d}'.format(version), ext=ext)) return utils.unipath(workspace.path, filename) @task @requires(success('build_filename'))