added debug logs into sync to avalon so we can track what happened

This commit is contained in:
iLLiCiTiT 2019-10-01 19:04:19 +02:00
parent 9853e258e4
commit c997ca6eff
3 changed files with 65 additions and 12 deletions

View file

@ -88,6 +88,7 @@ class SyncToAvalon(BaseAction):
})
session.commit()
try:
self.log.debug("Preparing entities for synchronization")
self.importable = []
# get from top entity in hierarchy all parent entities

View file

@ -113,6 +113,7 @@ class SyncToAvalon(BaseAction):
})
session.commit()
try:
self.log.debug("Preparing entities for synchronization")
self.importable = []
# get from top entity in hierarchy all parent entities

View file

@ -27,6 +27,11 @@ def import_to_avalon(
output = {}
errors = []
entity_type = entity.entity_type
ent_path = "/".join([ent["name"] for ent in entity['link']])
log.debug("{} [{}] - Processing".format(ent_path, entity_type))
ca_mongoid = get_ca_mongoid()
# Validate if entity has custom attribute avalon_mongo_id
if ca_mongoid not in entity['custom_attributes']:
@ -34,6 +39,7 @@ def import_to_avalon(
'Custom attribute "{}" for "{}" is not created'
' or don\'t have set permissions for API'
).format(ca_mongoid, entity['name'])
log.error(msg)
errors.append({'Custom attribute error': msg})
output['errors'] = errors
return output
@ -42,7 +48,12 @@ def import_to_avalon(
try:
avalon_check_name(entity)
except ValidationError:
msg = '"{}" includes unsupported symbols like "dash" or "space"'
msg = (
"{} - name \"{}\" includes unsupported symbols"
" like \"dash\" or \"space\""
).format(ent_path, name)
log.error(msg)
errors.append({'Unsupported character': msg})
output['errors'] = errors
return output
@ -61,6 +72,7 @@ def import_to_avalon(
ft_project_code = ft_project['name']
if av_project is None:
log.debug("{} - Creating project".format(project_name))
item = {
'schema': "avalon-core:project-2.0",
'type': type,
@ -96,10 +108,20 @@ def import_to_avalon(
'Project name', av_project['name'], project_name
)}
)
if (
av_project_code is not None and
av_project_code != ft_project_code
):
log.warning((
"{0} - Project code"
" is different in Avalon (\"{1}\")"
" that in Ftrack (\"{2}\")!"
" Trying to change it back in Ftrack to \"{1}\"."
).format(
ent_path, str(av_project_code), str(ft_project_code)
))
entity['name'] = av_project_code
errors.append(
{'Changed name error': msg.format(
@ -107,7 +129,18 @@ def import_to_avalon(
)}
)
session.commit()
try:
session.commit()
log.info((
"{} - Project code was changed back to \"{}\""
).format(ent_path, str(av_project_code)))
except Exception:
log.error(
(
"{} - Couldn't change project code back to \"{}\"."
).format(ent_path, str(av_project_code)),
exc_info=True
)
output['errors'] = errors
return output
@ -138,6 +171,7 @@ def import_to_avalon(
for k, v in data.items():
enter_data[k] = v
log.debug("{} - Updating data".format(ent_path))
database[project_name].update_many(
{'_id': ObjectId(projectId)},
{'$set': {
@ -188,10 +222,13 @@ def import_to_avalon(
avalon_asset = None
# existence of this custom attr is already checked
if ca_mongoid not in entity['custom_attributes']:
msg = '"{}" don\'t have "{}" custom attribute'
errors.append({'Missing Custom attribute': msg.format(
entity_type, ca_mongoid
)})
msg = (
"Entity type \"{}\" don't have created custom attribute \"{}\""
" or user \"{}\" don't have permissions to read or change it."
).format(entity_type, ca_mongoid, session.api_user)
log.error(msg)
errors.append({'Missing Custom attribute': msg})
output['errors'] = errors
return output
@ -222,15 +259,23 @@ def import_to_avalon(
}
schema.validate(item)
mongo_id = database[project_name].insert_one(item).inserted_id
log.debug("{} - Created in project \"{}\"".format(
ent_path, project_name
))
# Raise error if it seems to be different ent. with same name
elif (
avalon_asset['data']['parents'] != data['parents'] or
avalon_asset['silo'] != silo
):
db_asset_path_items = [project_name,]
db_asset_path_items.extend(avalon_asset['data']['parents'])
db_asset_path_items.append(name)
msg = (
'In Avalon DB already exists entity with name "{0}"'
).format(name)
"{} - In Avalon DB already exists entity with name \"{}\""
"\n- \"{}\""
).format(ent_path, name, "/".join(db_asset_path_items))
log.error(msg)
errors.append({'Entity name duplication': msg})
output['errors'] = errors
return output
@ -242,11 +287,13 @@ def import_to_avalon(
if avalon_asset['name'] != entity['name']:
if silo is None or changeability_check_childs(entity) is False:
msg = (
'You can\'t change name {} to {}'
'{} - You can\'t change name "{}" to "{}"'
', avalon wouldn\'t work properly!'
'\n\nName was changed back!'
'\n\nCreate new entity if you want to change name.'
).format(avalon_asset['name'], entity['name'])
).format(ent_path, avalon_asset['name'], entity['name'])
log.warning(msg)
entity['name'] = avalon_asset['name']
session.commit()
errors.append({'Changed name error': msg})
@ -282,6 +329,7 @@ def import_to_avalon(
avalon_asset['name'], old_path, new_path,
'entity was moved back'
)
log.warning(msg)
moved_back = True
except Exception:
@ -292,6 +340,7 @@ def import_to_avalon(
avalon_asset['name'], old_path, new_path,
'please move it back'
)
log.error(msg)
errors.append({'Hierarchy change error': msg})
@ -319,7 +368,9 @@ def import_to_avalon(
'data': enter_data,
'parent': ObjectId(projectId)
}})
log.debug("{} - Updated data (in project \"{}\")".format(
ent_path, project_name
))
entity['custom_attributes'][ca_mongoid] = str(mongo_id)
session.commit()