From 0c99fc849d131e01a4cf4f25c22414bdd2f1378c Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Mon, 6 Apr 2020 10:04:05 +0200 Subject: [PATCH] renamed `load_containers_to_workfile` to `build_workfile` and removed `create_first_workfile` --- pype/lib.py | 97 +---------------------------------------------- pype/maya/menu.py | 7 ++-- 2 files changed, 5 insertions(+), 99 deletions(-) diff --git a/pype/lib.py b/pype/lib.py index 67c5e82611..d38e76a5ee 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -1054,8 +1054,8 @@ def collect_last_version_repres(asset_entities): return output -def load_containers_to_workfile(): - """Load containers for (first) workfile. +def build_workfile(): + """Load representations for current context as containers into workfile. Loads latest versions of current and linked assets to workfile by logic stored in Workfile variants from presets. Variants are set by host, @@ -1226,96 +1226,3 @@ def get_last_workfile_path(root, template, file_ext): last_file_path = os.path.join(root, last_file_name) return last_file_path - - -def create_first_workfile(file_ext=None): - """Builds first workfile and load containers for it. - - :param file_ext: Work file extension may be specified otherwise first - extension in host's registered extensions is used. - :type file_ext: str - :return: Workfile path and loaded containers by Asset entity - :rtype: tuple - """ - # Get host - host = avalon.api.registered_host() - - # Workfile extension - if file_ext is None: - if not host.file_extensions(): - raise AssertionError( - "Host doesn't have set file extensions. Can't create workfile." - ) - file_ext = host.file_extensions()[0] - - workfile_root = host.work_root(io.Session) - - # make sure extension has dot - if not file_ext.startswith("."): - file_ext = ".{}".format(file_ext) - - # Create new workfile - project_doc = io.find_one({"type": "project"}) - asset_name = io.Session["AVALON_ASSET"] - asset_doc = io.find_one({ - "type": "asset", - "name": asset_name - }) - if not asset_doc: - raise AssertionError( - "Asset with name `{}` was not found.".format(asset_name) - ) - - root = avalon.api.registered_root() - template = project_doc["config"]["template"]["workfile"] - file_path = get_last_workfile_path(root, template, file_ext) - # TODO what should do if already exists? - # 1.) create new - # 2.) override - # 3.) raise exception - if file_path is not None: - log.warning("Workfile already exists`{}`.".format(file_path)) - return file_path - - hierarchy = "" - parents = asset_doc["data"].get("parents") - if parents: - hierarchy = "/".join(parents) - - # Use same data as Workfiles tool - template_data = { - "root": root, - "project": { - "name": project_doc["name"], - "code": project_doc["data"].get("code") - }, - "asset": asset_name, - "task": io.Session["AVALON_TASK"], - "hierarchy": hierarchy, - "version": 1, - "user": getpass.getuser(), - "ext": file_ext - } - - # Use same template as in Workfiles Tool - template_filled = pipeline.format_template_with_optional_keys( - template_data, template - ) - - # make sure filled template does not have more dots due to extension - while ".." in template_filled: - template_filled = template_filled.replace("..", ".") - - workfile_path = os.path.join(workfile_root, template_filled) - host.save_file(workfile_path) - - return workfile_path - - -def build_first_workfile(file_ext=None): - # DEBUG this should probably be host specific - # Create workfile - workfile_path = create_first_workfile(file_ext) - # Load containers - loaded_containers = load_containers_to_workfile() - return (workfile_path, loaded_containers) diff --git a/pype/maya/menu.py b/pype/maya/menu.py index efe338b4af..c25166f210 100644 --- a/pype/maya/menu.py +++ b/pype/maya/menu.py @@ -2,10 +2,9 @@ import sys import os import logging -from avalon.vendor.Qt import QtWidgets, QtCore, QtGui +from avalon.vendor.Qt import QtWidgets, QtGui from avalon.maya import pipeline -import avalon.api -from ..lib import build_first_workfile +from ..lib import build_workfile import maya.cmds as cmds self = sys.modules[__name__] @@ -30,7 +29,7 @@ def deferred(): cmds.menuItem( "Build First Workfile", parent=pipeline._menu, - command=lambda *args: build_first_workfile() + command=lambda *args: build_workfile() ) log.info("Attempting to install scripts menu..")