Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #255 from pypeclub/feature/premiere-workfile-multi…
Browse files Browse the repository at this point in the history
…root-fixes

premiere workfile root per task (multi-root)
  • Loading branch information
mkolar authored Jun 16, 2020
2 parents 6b0cb54 + 64b7a79 commit 6f6bd58
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 22 deletions.
94 changes: 92 additions & 2 deletions pype/hooks/premiere/prelaunch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import traceback
from avalon import api, io, lib
from pype.lib import PypeHook
from pype.api import Logger
from pype.api import Logger, Anatomy
from pype.hosts.premiere import lib as prlib


Expand All @@ -12,6 +13,7 @@ class PremierePrelaunch(PypeHook):
path to the project by environment variable to Premiere launcher
shell script.
"""
project_code = None

def __init__(self, logger=None):
if not logger:
Expand All @@ -26,6 +28,33 @@ def execute(self, *args, env: dict = None) -> bool:
if not env:
env = os.environ

# initialize
self._S = api.Session

# get context variables
self._S["AVALON_PROJECT"] = env["AVALON_PROJECT"]
self._S["AVALON_ASSET"] = env["AVALON_ASSET"]
task = self._S["AVALON_TASK"] = env["AVALON_TASK"]

# get workfile path
anatomy_filled = self.get_anatomy_filled()

# if anatomy template should have different root for particular task
# just add for example > work[conforming]:
workfile_search_key = f"work[{task.lower()}]"
workfile_key = anatomy_filled.get(
workfile_search_key,
anatomy_filled.get("work")
)
workdir = env["AVALON_WORKDIR"] = workfile_key["folder"]

# create workdir if doesn't exist
os.makedirs(workdir, exist_ok=True)
self.log.info(f"Work dir is: `{workdir}`")

# adding project code to env
env["AVALON_PROJECT_CODE"] = self.project_code

try:
__import__("pype.hosts.premiere")
__import__("pyblish")
Expand All @@ -36,7 +65,68 @@ def execute(self, *args, env: dict = None) -> bool:

else:
# Premiere Setup integration
# importlib.reload(prlib)
prlib.setup(env)

return True

def get_anatomy_filled(self):
root_path = api.registered_root()
project_name = self._S["AVALON_PROJECT"]
asset_name = self._S["AVALON_ASSET"]

io.install()
project_entity = io.find_one({
"type": "project",
"name": project_name
})
assert project_entity, (
"Project '{0}' was not found."
).format(project_name)
self.log.debug("Collected Project \"{}\"".format(project_entity))

asset_entity = io.find_one({
"type": "asset",
"name": asset_name,
"parent": project_entity["_id"]
})
assert asset_entity, (
"No asset found by the name '{0}' in project '{1}'"
).format(asset_name, project_name)

project_name = project_entity["name"]
self.project_code = project_entity["data"].get("code")

self.log.info(
"Anatomy object collected for project \"{}\".".format(project_name)
)

hierarchy_items = asset_entity["data"]["parents"]
hierarchy = ""
if hierarchy_items:
hierarchy = os.path.join(*hierarchy_items)

template_data = {
"root": root_path,
"project": {
"name": project_name,
"code": self.project_code
},
"asset": asset_entity["name"],
"hierarchy": hierarchy.replace("\\", "/"),
"task": self._S["AVALON_TASK"],
"ext": "ppro",
"version": 1,
"username": os.getenv("PYPE_USERNAME", "").strip()
}

avalon_app_name = os.environ.get("AVALON_APP_NAME")
if avalon_app_name:
application_def = lib.get_application(avalon_app_name)
app_dir = application_def.get("application_dir")
if app_dir:
template_data["app"] = app_dir

anatomy = Anatomy(project_name)
anatomy_filled = anatomy.format_all(template_data).get_solved()

return anatomy_filled
1 change: 0 additions & 1 deletion pype/hosts/premiere/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from avalon import api as avalon
from pyblish import api as pyblish
from pype.api import Logger
Expand Down
17 changes: 3 additions & 14 deletions pype/hosts/premiere/extensions/com.pype/jsx/batchRenamer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,12 @@ var BatchRenamer = {
var seq = app.project.activeSequence;
var metadata = $.pype.getSequencePypeMetadata(seq, true);

var startCount = 10;
var stepCount = 10;
var padding = 3;
var newItems = {};
var projectCode = data.projectCode
var episode = data.ep;
var episodeSuf = data.epSuffix;
var shotPref = 'sh';
var count = 0;
var seqCheck = '';

for (var c = 0; c < selected.length; c++) {
// fill in hierarchy if set
Expand All @@ -79,15 +76,7 @@ var BatchRenamer = {
var sequenceName = name.slice(0, 5);
var shotNum = Number(name.slice((name.length - 3), name.length));

// if (sequenceName !== seqCheck) {
// seqCheck = sequenceName;
// count = 0;
// };
//
// var seqCount = (count * stepCount) + startCount;
// count += 1;

var newName = episode + sequenceName + shotPref + (shotNum).pad(padding);
var newName = projectCode + episode + sequenceName + shotPref + (shotNum).pad(padding);
$.pype.log(newName);
selected[c].clip.name = newName;

Expand All @@ -113,4 +102,4 @@ var BatchRenamer = {
$.pype.setSequencePypeMetadata(seq, metadata);
return JSON.stringify(metadata);
}
}
}
12 changes: 7 additions & 5 deletions pype/hosts/premiere/ppro/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@
<div class="input-group input-group-sm mb-1">

<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon6">Rename targeted text layers<br />
converts sc010sh020
<br />to lbb201sc010sh020<br />and creates ftrack metadata</span>
<span class="input-group-text" id="basic-addon6">
Rename targeted text layers<br />
converts `sc010sh020`<br />
to `proj01ep01sc01sh01`<br />
and creates ftrack metadata</span>
<div class="input-group-text">
<input type="text" name="episode" placeholder="lbb2" aria-label="episode" aria-describedby="basic-addon5" value="" style="width:75px;">
<input type="text" name="episode" placeholder="ep01" aria-label="episode" aria-describedby="basic-addon5" value="" style="width:75px;">
</div>
<div class="input-group-text">
<input type="text" name="ep_suffix" placeholder="nameofepisode" aria-label="Name of episode" aria-describedby="basic-addon5" value="">
<input type="text" name="ep_suffix" placeholder="longerEpisodeName" aria-label="Name of episode" aria-describedby="basic-addon5" value="">
</div>
</div>
<div class="input-group-append">
Expand Down
1 change: 1 addition & 0 deletions pype/hosts/premiere/ppro/js/pype.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Pype {
let data = {};
data.ep = $('input[name=episode]', $renameId).val();
data.epSuffix = $('input[name=ep_suffix]', $renameId).val();
data.projectCode = this.env.AVALON_PROJECT_CODE;

if (!data.ep) {
this.csi.evalScript('$.pype.alert_message("' + 'Need to fill episode code' + '")');
Expand Down

0 comments on commit 6f6bd58

Please sign in to comment.