diff --git a/pype/api.py b/pype/api.py index 801876718a..a97ba35f60 100644 --- a/pype/api.py +++ b/pype/api.py @@ -21,7 +21,6 @@ from pypeapp import Logger from .templates import ( get_project_name, - get_project_code, get_hierarchy, get_asset, get_task, @@ -34,6 +33,7 @@ from .templates import ( from .lib import ( version_up, get_handle_irregular, + get_project, get_project_data, get_asset_data, get_version_from_path, @@ -62,8 +62,8 @@ __all__ = [ "get_handle_irregular", "get_project_data", "get_asset_data", + "get_project", "get_project_name", - "get_project_code", "get_hierarchy", "get_asset", "get_task", diff --git a/pype/aport/api.py b/pype/aport/api.py index bac3e235df..d53ddf11b9 100644 --- a/pype/aport/api.py +++ b/pype/aport/api.py @@ -80,15 +80,19 @@ def publish(json_data_path, gui): @pico.expose() -def context(project, asset, task, app): +def context(project_name, asset, task, app): # http://localhost:4242/pipeline/context?project=this&asset=shot01&task=comp - os.environ["AVALON_PROJECT"] = project + os.environ["AVALON_PROJECT"] = project_name + SESSION["AVALON_PROJECT"] = project_name avalon.update_current_task(task, asset, app) - project_code = pype.get_project_code() - pype.set_project_code(project_code) + project_code = pype.get_project()["data"].get("code", '') + + os.environ["AVALON_PROJECTCODE"] = project_code + SESSION["AVALON_PROJECTCODE"] = project_code + hierarchy = pype.get_hierarchy() pype.set_hierarchy(hierarchy) fix_paths = {k: v.replace("\\", "/") for k, v in SESSION.items() diff --git a/pype/aport/original/api.py b/pype/aport/original/api.py index b1fffed1dc..4f17a6071b 100644 --- a/pype/aport/original/api.py +++ b/pype/aport/original/api.py @@ -82,11 +82,15 @@ def context(project, asset, task, app): # http://localhost:4242/pipeline/context?project=this&asset=shot01&task=comp os.environ["AVALON_PROJECT"] = project + SESSION["AVALON_PROJECT"] = project avalon.update_current_task(task, asset, app) - project_code = pype.get_project_code() - pype.set_project_code(project_code) + project_code = pype.get_project()["data"].get("code", '') + + os.environ["AVALON_PROJECTCODE"] = project_code + SESSION["AVALON_PROJECTCODE"] = project_code + hierarchy = pype.get_hierarchy() pype.set_hierarchy(hierarchy) fix_paths = {k: v.replace("\\", "/") for k, v in SESSION.items() diff --git a/pype/aport/original/pipeline.py b/pype/aport/original/pipeline.py index 1bfd9a8d1e..efb242f659 100644 --- a/pype/aport/original/pipeline.py +++ b/pype/aport/original/pipeline.py @@ -81,11 +81,15 @@ def context(project, asset, task, app): # http://localhost:4242/pipeline/context?project=this&asset=shot01&task=comp os.environ["AVALON_PROJECT"] = project + SESSION["AVALON_PROJECT"] = project avalon.update_current_task(task, asset, app) - project_code = pype.get_project_code() - pype.set_project_code(project_code) + project_code = pype.get_project()["data"].get("code", '') + + os.environ["AVALON_PROJECTCODE"] = project_code + SESSION["AVALON_PROJECTCODE"] = project_code + hierarchy = pype.get_hierarchy() pype.set_hierarchy(hierarchy) fix_paths = {k: v.replace("\\", "/") for k, v in SESSION.items() diff --git a/pype/lib.py b/pype/lib.py index 5da4a67c0c..4a0da2fd51 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -320,6 +320,10 @@ def get_project_data(): return data +def get_project(): + io.install() + return io.find_one({"type": "project"}) + def get_asset_data(asset=None): """Get the data from the current asset diff --git a/pype/nuke/lib.py b/pype/nuke/lib.py index 6a57704fff..70225e541e 100644 --- a/pype/nuke/lib.py +++ b/pype/nuke/lib.py @@ -149,15 +149,15 @@ def format_anatomy(data): if not version: file = script_name() data["version"] = pype.get_version_from_path(file) - + project_document = pype.get_project() data.update({ "root": api.Session["AVALON_PROJECTS"], "subset": data["avalon"]["subset"], "asset": data["avalon"]["asset"], "task": str(pype.get_task()).lower(), "family": data["avalon"]["family"], - "project": {"name": pype.get_project_name(), - "code": pype.get_project_code()}, + "project": {"name": project_document["name"], + "code": project_document["data"].get("code", '')}, "representation": data["nuke_dataflow_writes"]["file_type"], "app": data["application"]["application_dir"], "hierarchy": pype.get_hierarchy(), diff --git a/pype/templates.py b/pype/templates.py index 5892216632..94133c9815 100644 --- a/pype/templates.py +++ b/pype/templates.py @@ -17,17 +17,6 @@ def set_session(): self.SESSION = avalon.session -def get_project_code(): - """ - Obtain project code from database - - Returns: - string: project code - """ - - return io.find_one({"type": "project"})["data"].get("code", '') - - def set_project_code(code): """ Set project code into os.environ @@ -155,11 +144,14 @@ def get_context_data(project=None, """ application = avalonlib.get_application(os.environ["AVALON_APP_NAME"]) + project_doc = io.find_one({"type": "project"}) data = { "task": task or get_task(), "asset": asset or get_asset(), - "project": {"name": project or get_project_name(), - "code": get_project_code()}, + "project": { + "name": project or project_doc["name"], + "code": project_doc["data"].get("code", '') + }, "hierarchy": hierarchy or get_hierarchy(), "app": application["application_dir"] }