return commits of different branch

This commit is contained in:
Jakub Trllo 2019-02-05 17:58:57 +01:00
parent 67cb3f05d5
commit 3c0550029b
7 changed files with 12 additions and 283 deletions

View file

@ -1,3 +1,5 @@
# :coding: utf-8
# :copyright: Copyright (c) 2017 ftrack
import os
import sys
import argparse

View file

@ -1,3 +1,5 @@
# :coding: utf-8
# :copyright: Copyright (c) 2017 ftrack
import sys
import argparse
import logging

View file

@ -1,3 +1,5 @@
# :coding: utf-8
# :copyright: Copyright (c) 2017 ftrack
import sys
import argparse
import logging

View file

@ -53,7 +53,7 @@ def import_to_avalon(
if entity_type in ['Project']:
type = 'project'
config = get_config_from_ftproject(entity)
config = get_project_config(entity)
schema.validate(config)
av_project_code = None
@ -440,42 +440,16 @@ def get_avalon_project(ft_project):
return avalon_project
def get_config_from_ftproject(entity=None):
def get_project_config(entity):
config = {}
config['schema'] = pypelib.get_avalon_project_config_schema()
config['tasks'] = [{'name': ''}]
config['apps'] = get_project_apps(entity)
config['template'] = pypelib.get_avalon_project_template()
apps = []
tasks = [{'name': ''}]
if entity is not None:
apps = get_project_apps(entity)
tasks = []
if entity.entity_type.lower() != 'project':
project = entity['project']
else:
project = entity
for task_type in get_all_task_types_ftproj(project):
tasks.append({'name': task_type})
config['apps'] = apps
config['tasks'] = tasks
return config
def get_all_task_types_ftproj(project):
tasks = {}
proj_template = project['project_schema']
temp_task_types = proj_template['_task_type_schema']['types']
for type in temp_task_types:
if type['name'] not in tasks:
tasks[type['name']] = type
return tasks
def get_project_apps(entity):
""" Get apps from project
Requirements:
@ -548,18 +522,3 @@ def get_config_data():
log.warning("{} - {}".format(msg, str(e)))
return data
def get_all_object_type_array(self, session):
# basic excluded types
excludes = ['bug', 'epic', 'feature', 'information']
# TODO read from presets which also will be excluded
all_obj_types = set()
for obj in session.query('ObjectType').all():
name = obj['name']
if ' ' in name:
name = name.replace(' ', '')
if name.lower() in excludes:
continue
all_obj_types.add(name)
return list(all_obj_types)

View file

@ -1,3 +1,5 @@
# :coding: utf-8
# :copyright: Copyright (c) 2017 ftrack
import os
import sys
import platform

View file

@ -1,111 +0,0 @@
import pyblish.api
from avalon import io
class IntegrateInstancesToAvalon(pyblish.api.InstancePlugin):
"""
Create entities in ftrack based on collected data from premiere
"""
order = pyblish.api.IntegratorOrder + 0.48
label = 'Integrate To Avalon'
families = []
exclude = []
def process(self, instance):
for ex in self.exclude:
if ex in instance.data['families']:
return
self.log.debug('instance {}'.format(instance))
self.db = io
self.db.install()
# TODO implement how to get right data
all_instances_data = {}
self.import_to_avalon(all_instances_data)
def import_to_avalon(self, input_data, parent=None):
for name in input_data:
entity_data = input_data[name]
entity_type = entity_data['entity_type']
data = {}
# Process project
if entity_type.lower() == 'project':
# TODO: this should be already set if io...?
if self.db.Session['AVALON_PROJECT'] is None:
self.db.Session['AVALON_PROJECT'] = name
entity = self.db.find_one({'type': 'project'})
if entity is None:
# TODO: better exception
raise Exception
# get data from already existing project
for key, value in entity.get('data', {}).items():
data[key] = value
self.av_project = entity
# Raise error if project or parent are not set
elif self.av_project is None or parent is None:
# TODO better exception
raise Exception
# Else process assset
else:
entity = self.db.find_one({'type': 'asset', 'name': name})
# Create entity if doesn't exist
if entity is None:
if self.av_project['_id'] == parent['_id']:
silo = None
elif parent['silo'] is None:
silo = parent['name']
else:
silo = parent['silo']
entity = self.create_avalon_asset(name, silo)
# Else get data from already existing
else:
for key, value in entity.get('data', {}).items():
data[key] = value
data['entityType'] = entity_type
# TASKS
tasks = entity_data.get('tasks', [])
data['tasks'] = tasks
parents = []
visualParent = None
# do not store project's id as visualParent (silo asset)
if self.av_project['_id'] != parent['_id']:
visualParent = parent['_id']
parents.extend(parent['data']['parents'])
parents.append(parent['name'])
data['visualParent'] = visualParent
data['parents'] = parents
# CUSTOM ATTRIBUTES
for key, value in entity_data.get('custom_attributes', {}).items():
data[key] = value
# Update entity data with input data
self.db.update_many(
{'_id': entity['_id']},
{'$set': {
'data': data,
}})
if 'childs' in entity_data:
self.import_to_ftrack(entity_data['childs'], entity)
def create_avalon_asset(self, name, silo):
item = {
'schema': 'avalon-core:asset-2.0',
'name': name,
'silo': silo,
'parent': self.av_project['_id'],
'type': 'asset'
}
entity_id = self.db.insert_one(item).inserted_id
return self.db.find_one({'_id': entity_id})

View file

@ -1,127 +0,0 @@
import pyblish.api
class IntegrateInstancesToFtrack(pyblish.api.InstancePlugin):
"""
Create entities in ftrack based on collected data from premiere
"""
order = pyblish.api.IntegratorOrder + 0.48
label = 'Integrate To Ftrack'
families = ["ftrack"]
exclude = []
def process(self, instance):
for ex in self.exclude:
if ex in instance.data['families']:
return
self.log.debug('instance {}'.format(instance))
self.ft_project = None
self.session = instance.context.data["ftrackSession"]
# TODO implement how to get right data
all_instances_data = {}
self.import_to_ftrack(all_instances_data)
def import_to_ftrack(self, input_data, parent=None):
for entity_name in input_data:
entity_data = input_data[entity_name]
entity_type = entity_data['entity_type']
if entity_type.lower() == 'project':
query = 'Project where full_name is "{}"'.format(entity_name)
entity = self.session.query(query).one()
self.ft_project = entity
self.task_types = self.get_all_task_types(entity)
elif self.ft_project is None:
# TODO better exception
raise Exception
elif parent is None:
# TODO better exception
raise Exception
else:
query = '{} where name is "{}" and parent_id is "{}"'.format(
entity_type, entity_name, parent['id']
)
try:
entity = self.session.query(query).one()
except Exception:
entity = None
# Create entity if not exists
if entity is None:
entity = self.create_entity(
name=entity_name,
type=entity_type,
parent=parent
)
# CUSTOM ATTRIBUTES
custom_attributes = entity_data.get('custom_attributes', [])
for key in custom_attributes:
if key not in entity['custom_attributes']:
# TODO better exception
raise Exception
entity['custom_attributes'][key] = custom_attributes[key]
self.session.commit()
# TASKS
tasks = entity_data.get('tasks', [])
existing_tasks = []
tasks_to_create = []
for child in entity['children']:
if child.entity_type.lower() == 'task':
existing_tasks.append(child['type']['name'])
for task in tasks:
if task in existing_tasks:
print("Task {} already exists".format(task))
continue
tasks_to_create.append(task)
for task in tasks_to_create:
self.create_task(
name=task,
task_type=task,
parent=entity
)
self.session.commit()
if 'childs' in entity_data:
self.import_to_ftrack(entity_data['childs'], entity)
def get_all_task_types(self, project):
tasks = {}
proj_template = project['project_schema']
temp_task_types = proj_template['_task_type_schema']['types']
for type in temp_task_types:
if type['name'] not in tasks:
tasks[type['name']] = type
return tasks
def create_task(self, name, task_type, parent):
task = self.session.create('Task', {
'name': name,
'parent': parent
})
# TODO not secured!!! - check if task_type exists
task['type'] = self.task_types[task_type]
self.session.commit()
return task
def create_entity(self, name, type, parent):
entity = self.session.create(type, {
'name': name,
'parent': parent
})
self.session.commit()
return entity