mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 21:32:15 +01:00
Merged in feature/PYPE-140_software_folders (pull request #103)
Feature/PYPE-140 software folders Approved-by: Milan Kolar <milan@orbi.tools>
This commit is contained in:
commit
aa8f9c7ece
4 changed files with 164 additions and 4 deletions
155
pype/ftrack/actions/action_create_sw_folders.py
Normal file
155
pype/ftrack/actions/action_create_sw_folders.py
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
import os
|
||||
import sys
|
||||
import json
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
import ftrack_api
|
||||
from avalon import lib as avalonlib
|
||||
from avalon.tools.libraryloader.io_nonsingleton import DbConnector
|
||||
from pype import lib as pypelib
|
||||
from pype.ftrack import BaseAction
|
||||
|
||||
|
||||
class CreateSWFolders(BaseAction):
|
||||
'''Edit meta data action.'''
|
||||
|
||||
#: Action identifier.
|
||||
identifier = 'create.sw.folders'
|
||||
#: Action label.
|
||||
label = 'Create SW Folders'
|
||||
#: Action description.
|
||||
description = 'Creates folders for all SW in project'
|
||||
|
||||
|
||||
def __init__(self, session):
|
||||
super().__init__(session)
|
||||
self.avalon_db = DbConnector()
|
||||
self.avalon_db.install()
|
||||
|
||||
def discover(self, session, entities, event):
|
||||
''' Validation '''
|
||||
|
||||
return True
|
||||
|
||||
def launch(self, session, entities, event):
|
||||
if len(entities) != 1:
|
||||
self.log.warning(
|
||||
'There are more entities in selection!'
|
||||
)
|
||||
return False
|
||||
entity = entities[0]
|
||||
if entity.entity_type.lower() != 'task':
|
||||
self.log.warning(
|
||||
'Selected entity is not Task!'
|
||||
)
|
||||
return False
|
||||
asset = entity['parent']
|
||||
project = asset['project']
|
||||
|
||||
project_name = project["full_name"]
|
||||
self.avalon_db.Session['AVALON_PROJECT'] = project_name
|
||||
av_project = self.avalon_db.find_one({'type': 'project'})
|
||||
av_asset = self.avalon_db.find_one({
|
||||
'type': 'asset',
|
||||
'name': asset['name']
|
||||
})
|
||||
|
||||
templates = av_project["config"]["template"]
|
||||
template = templates.get("work", None)
|
||||
if template is None:
|
||||
return False
|
||||
|
||||
|
||||
data = {
|
||||
"root": os.environ["AVALON_PROJECTS"],
|
||||
"project": {
|
||||
"name": project_name,
|
||||
"code": project["name"]
|
||||
},
|
||||
"hierarchy": av_asset['data']['hierarchy'],
|
||||
"asset": asset['name'],
|
||||
"task": entity['name'],
|
||||
}
|
||||
|
||||
apps = []
|
||||
if '{app}' in template:
|
||||
# Apps in project
|
||||
for app in av_project['data']['applications']:
|
||||
app_data = avalonlib.get_application(app)
|
||||
app_dir = app_data['application_dir']
|
||||
if app_dir not in apps:
|
||||
apps.append(app_dir)
|
||||
# Apps in presets
|
||||
path_items = [pypelib.get_presets_path(), 'tools', 'sw_folders.json']
|
||||
filepath = os.path.sep.join(path_items)
|
||||
|
||||
presets = dict()
|
||||
try:
|
||||
with open(filepath) as data_file:
|
||||
presets = json.load(data_file)
|
||||
except Exception as e:
|
||||
self.log.warning('Wasn\'t able to load presets')
|
||||
preset_apps = presets.get(project_name, presets.get('__default__', []))
|
||||
for app in preset_apps:
|
||||
if app not in apps:
|
||||
apps.append(app)
|
||||
|
||||
# Create folders for apps
|
||||
for app in apps:
|
||||
data['app'] = app
|
||||
self.log.info('Created folder for app {}'.format(app))
|
||||
path = os.path.normpath(template.format(**data))
|
||||
if os.path.exists(path):
|
||||
continue
|
||||
os.makedirs(path)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def register(session, **kw):
|
||||
'''Register plugin. Called when used as an plugin.'''
|
||||
|
||||
if not isinstance(session, ftrack_api.session.Session):
|
||||
return
|
||||
|
||||
CreateSWFolders(session).register()
|
||||
|
||||
|
||||
def main(arguments=None):
|
||||
'''Set up logging and register action.'''
|
||||
if arguments is None:
|
||||
arguments = []
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
# Allow setting of logging level from arguments.
|
||||
loggingLevels = {}
|
||||
for level in (
|
||||
logging.NOTSET, logging.DEBUG, logging.INFO, logging.WARNING,
|
||||
logging.ERROR, logging.CRITICAL
|
||||
):
|
||||
loggingLevels[logging.getLevelName(level).lower()] = level
|
||||
|
||||
parser.add_argument(
|
||||
'-v', '--verbosity',
|
||||
help='Set the logging output verbosity.',
|
||||
choices=loggingLevels.keys(),
|
||||
default='info'
|
||||
)
|
||||
namespace = parser.parse_args(arguments)
|
||||
|
||||
# Set up basic logging
|
||||
logging.basicConfig(level=loggingLevels[namespace.verbosity])
|
||||
|
||||
session = ftrack_api.Session()
|
||||
register(session)
|
||||
|
||||
# Wait for events
|
||||
logging.info(
|
||||
'Registered actions and listening for events. Use Ctrl-C to abort.'
|
||||
)
|
||||
session.event_hub.wait()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
|
|
@ -198,10 +198,13 @@ class AppAction(BaseHandler):
|
|||
if parents:
|
||||
hierarchy = os.path.join(*parents)
|
||||
|
||||
application = avalonlib.get_application(os.environ["AVALON_APP_NAME"])
|
||||
|
||||
data = {"project": {"name": entity['project']['full_name'],
|
||||
"code": entity['project']['name']},
|
||||
"task": entity['name'],
|
||||
"asset": entity['parent']['name'],
|
||||
"app": application["application_dir"],
|
||||
"hierarchy": hierarchy}
|
||||
try:
|
||||
anatomy = anatomy.format(data)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import sys
|
|||
from collections import OrderedDict
|
||||
from pprint import pprint
|
||||
from avalon.vendor.Qt import QtGui
|
||||
from avalon import api, io
|
||||
from avalon import api, io, lib
|
||||
import avalon.nuke
|
||||
import pype.api as pype
|
||||
import nuke
|
||||
|
|
@ -88,6 +88,7 @@ def create_write_node(name, data):
|
|||
)
|
||||
nuke_dataflow_writes = get_dataflow(**data)
|
||||
nuke_colorspace_writes = get_colorspace(**data)
|
||||
application = lib.get_application(os.environ["AVALON_APP_NAME"])
|
||||
try:
|
||||
anatomy_filled = format_anatomy({
|
||||
"subset": data["avalon"]["subset"],
|
||||
|
|
@ -97,6 +98,7 @@ def create_write_node(name, data):
|
|||
"project": {"name": pype.get_project_name(),
|
||||
"code": pype.get_project_code()},
|
||||
"representation": nuke_dataflow_writes.file_type,
|
||||
"app": application["application_dir"],
|
||||
})
|
||||
except Exception as e:
|
||||
log.error("problem with resolving anatomy tepmlate: {}".format(e))
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
from avalon import io
|
||||
from avalon import api as avalon
|
||||
from avalon import io, api as avalon, lib as avalonlib
|
||||
from . import lib
|
||||
from app.api import (Templates, Logger, format)
|
||||
log = Logger.getLogger(__name__,
|
||||
|
|
@ -222,13 +221,14 @@ def get_context_data(project=None,
|
|||
dict: contextual data
|
||||
|
||||
"""
|
||||
|
||||
application = avalonlib.get_application(os.environ["AVALON_APP_NAME"])
|
||||
data = {
|
||||
"task": task or get_task(),
|
||||
"asset": asset or get_asset(),
|
||||
"project": {"name": project or get_project_name(),
|
||||
"code": get_project_code()},
|
||||
"hierarchy": hierarchy or get_hierarchy(),
|
||||
"app": application["application_dir"]
|
||||
}
|
||||
return data
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue