def inject_paths(event, entities): templates = lucidity.discover_templates() event["data"]["files"] = [] event["data"]["directories"] = [] for entity in entities: valid_templates = templates[0].get_valid_templates(entity, templates) for template in valid_templates: try: path = os.path.abspath(template.format(entity)).replace( "\\", "/") except lucidity.error.FormatError: continue else: if hasattr(template, "source"): event["data"]["files"].append((template.source, path)) else: if os.path.exists(path): continue event["data"]["directories"].append(path) return event
def assert_entity(entity): templates = lucidity.discover_templates() msg = ("No valid templates found for template name: \"{0}\", and entity: " "\"{1}\"".format(templates[0].get_template_name(entity), entity)) assert templates[0].get_valid_templates(entity, templates), msg get_resolved_paths(entity)
def __init__(self): super(LaunchPad, self).__init__() self.prefix = 'C:/Users/Nata/Documents/Loco' templatesPath = os.path.abspath( os.path.join(os.path.dirname(__file__), 'templates')) self.templates = lucidity.discover_templates(paths=[templatesPath])
def __init__(self): super(LaunchPad, self).__init__() self.prefix = 'C:/Users/Nata/Documents/Loco' templatesPath = os.path.abspath( os.path.join(os.path.dirname(__file__), 'templates')) self.templates = lucidity.discover_templates(paths=[templatesPath])
def get_resolved_paths(entity): templates = lucidity.discover_templates() valid_templates = templates[0].get_valid_templates(entity, templates) resolved_paths = [] for template in valid_templates: try: resolved_paths.append(template.format(entity)) except lucidity.error.FormatError as e: msg = e.message + "\nTemplate name: {0}".format(template.name) raise type(e)(msg) return resolved_paths
def get_resource_identifier(self, entity, context=None): templates = lucidity.discover_templates() valid_templates = templates[0].get_valid_templates(entity, templates) if valid_templates: return valid_templates[0].format(entity) msg = ( 'Could not find any templates for {0} with template name "{1}".') raise ValueError( msg.format(entity, templates[0].get_template_name(entity)))
def process(self, context): import os import shutil import lucidity session = context.data["ftrackSession"] templates = lucidity.discover_templates() # Get all entities in context and their parents. entities = [] for instance in context: if "ftrackEntity" not in instance.data["families"]: continue if not instance.data.get("entity"): continue for item in instance.data["entity"]["link"]: entities.append(session.get(item["type"], item["id"])) # Get all resolved paths and their templates. path_templates = [] for entity in list(set(entities)): valid_templates = templates[0].get_valid_templates( entity, templates) for template in valid_templates: try: path = os.path.abspath(template.format(entity)) except lucidity.error.FormatError: continue else: path_templates.append((path.replace("\\", "/"), template)) for path, template in path_templates: # Copy source templates. if hasattr(template, "source"): if not os.path.exists(os.path.dirname(path)): self.log.debug('Creating directory: "{0}".'.format( os.path.dirname(path))) os.makedirs(os.path.dirname(path)) self.log.debug('Copying "{0}" to "{1}".'.format( template.source, path)) shutil.copy(template.source, path) else: # Create directories. if not os.path.exists(path): self.log.debug('Creating directory: "{0}".'.format(path)) os.makedirs(path)
def test_unused_templates(): templates = lucidity.discover_templates() used_templates = [] for entity in get_entities(): valid_templates = templates[0].get_valid_templates(entity, templates) used_templates.extend(valid_templates) # Cover templates not used unused_templates = list(set(templates) - set(used_templates)) msg = "Templates not used:" for template in unused_templates: msg += "\n{0}".format(template) assert not unused_templates, msg
def modify_launch(event): """Return each entities in the selection in data dictionaries.""" data = event["data"] task = get_shared_session().get( "Task", event["data"]["context"]["selection"][0]["entityId"]) templates = lucidity.discover_templates() template_name = templates[0].get_template_name(task["parent"]) for template in templates: if template.name == template_name: # Return first valid path. This is up to the templates # definition to order what comes first. return data["command"].extend( ["--path", template.format(task["parent"])])
def modify_launch(event): """Return each entities in the selection in data dictionaries.""" session = get_shared_session() templates = lucidity.discover_templates() file_paths = [] paths_searched = [] for item in event["data"].get("selection", []): entity = session.get(item["entityType"].title(), item["entityId"]) template_name = templates[0].get_template_name(entity["parent"]) for template in templates: if template.name == template_name: path = template.format(entity["parent"]) for root, subFolder, files in os.walk(path): path = os.path.abspath(root) if path in paths_searched: continue else: paths_searched.append(path) for f in files: if not f.endswith(".exr"): continue file_paths.append( os.path.abspath(os.path.join(root, f))) collections = clique.assemble(list(set(file_paths)))[0] for collection in collections: event["data"]["items"].append({ "label": os.path.basename(collection.format()), "value": list(collection)[0] }) return event
def test_discover_with_env(path, expected, monkeypatch): '''Discover templates using environment variable.''' monkeypatch.setenv('LUCIDITY_TEMPLATE_PATH', path) templates = lucidity.discover_templates() assert map(operator.attrgetter('name'), templates) == expected
def process(self, instance): import os import lucidity from tgbvfx_environment import utils # Ignore source instance if "source" == instance.data["family"]: return # Ignore review instance if "review" == instance.data["family"]: return # Ignore NukeStudio for now if pyblish.api.current_host() == "nukestudio": return templates = lucidity.discover_templates() families = [ "img", "gizmo", "lut", "scene", "cache", "mov", "camera", "geometry" ] assettype_short = list( set(instance.data["families"]) & set(families) )[0] if assettype_short in ["gizmo", "lut"]: assettype_short = "nuke_gizmo" if assettype_short in ["geometry"]: assettype_short = "model" assettype = utils.mock_entity( ("short", assettype_short), entity_type="AssetType" ) asset = utils.mock_entity( ("parent", instance.context.data["ftrackTask"]["parent"]), ("type", assettype), entity_type="Asset" ) assetversion = utils.mock_entity( ("asset", asset), ("task", instance.context.data["ftrackTask"]), ("version", 1), ("metadata", {"instance_name": instance.data["name"]}), entity_type="AssetVersion" ) entity = None if "collection" in instance.data.keys(): path = instance.data["collection"].format("{head}{padding}{tail}") entity = utils.mock_entity( ("version", assetversion), ("name", "main"), ("file_type", os.path.splitext(path)[1]), entity_type="SequenceComponent" ) if "output_path" in instance.data.keys(): path = instance.data["output_path"] entity = utils.mock_entity( ("version", assetversion), ("name", "main"), ("file_type", os.path.splitext(path)[1]), entity_type="FileComponent" ) file_template_exists = False template_name = templates[0].get_template_name(entity) for template in templates: if template_name == template.name: file_template_exists = True msg = "Could not find any file templates for \"{0}\"" assert file_template_exists, msg.format(template_name)
def test_discover(recursive, expected): '''Discover templates via registration mount points.''' templates = lucidity.discover_templates( [TEST_TEMPLATE_PATH], recursive=recursive ) assert map(operator.attrgetter('name'), templates) == expected
def test_templates_existence(): templates = lucidity.discover_templates() assert templates, "No templates discovered."
__author__ = 'Nata' import os import lucidity templatesPath = os.path.abspath( os.path.join(os.path.dirname(__file__), 'templates') ) templates = lucidity.discover_templates(paths=[templatesPath]) data = { 'project': { 'name': 'launcher' }, 'shot': { 'name': 'shot 001' } } for template in templates: print template.format(data)
def test_discover(recursive, expected): '''Discover templates via registration mount points.''' templates = lucidity.discover_templates([TEST_TEMPLATE_PATH], recursive=recursive) assert [template.name for template in templates] == expected
def test_discover_with_env(path, expected, monkeypatch): '''Discover templates using environment variable.''' monkeypatch.setenv('LUCIDITY_TEMPLATE_PATH', path) templates = lucidity.discover_templates() assert [template.name for template in templates] == expected
def test_discover_with_env(path, expected, monkeypatch): '''Discover templates using environment variable.''' monkeypatch.setenv('LUCIDITY_TEMPLATE_PATH', path) templates = lucidity.discover_templates() assert map(operator.attrgetter('name'), templates) == expected
def test_discover(recursive, expected): '''Discover templates via registration mount points.''' templates = lucidity.discover_templates([TEST_TEMPLATE_PATH], recursive=recursive) assert map(operator.attrgetter('name'), templates) == expected
__author__ = 'Nata' import os import lucidity templatesPath = os.path.abspath( os.path.join(os.path.dirname(__file__), 'templates')) templates = lucidity.discover_templates(paths=[templatesPath]) data = {'project': {'name': 'launcher'}, 'shot': {'name': 'shot 001'}} for template in templates: print template.format(data)