mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
name check in sync to avalon is not checked by schema validation but with re module
This commit is contained in:
parent
ce1d2e1e6e
commit
40ff6f25ff
1 changed files with 16 additions and 32 deletions
|
|
@ -39,13 +39,7 @@ def import_to_avalon(
|
||||||
return output
|
return output
|
||||||
|
|
||||||
# Validate if entity name match REGEX in schema
|
# Validate if entity name match REGEX in schema
|
||||||
try:
|
avalon_check_name(entity)
|
||||||
avalon_check_name(entity)
|
|
||||||
except ValidationError:
|
|
||||||
msg = '"{}" includes unsupported symbols like "dash" or "space"'
|
|
||||||
errors.append({'Unsupported character': msg})
|
|
||||||
output['errors'] = errors
|
|
||||||
return output
|
|
||||||
|
|
||||||
entity_type = entity.entity_type
|
entity_type = entity.entity_type
|
||||||
# Project ////////////////////////////////////////////////////////////////
|
# Project ////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -531,34 +525,24 @@ def get_project_apps(entity):
|
||||||
return apps
|
return apps
|
||||||
|
|
||||||
|
|
||||||
def avalon_check_name(entity, inSchema=None):
|
def avalon_check_name(entity, in_schema=None):
|
||||||
ValidationError = jsonschema.ValidationError
|
default_pattern = "^[a-zA-Z0-9_.]*$"
|
||||||
alright = True
|
|
||||||
name = entity['name']
|
|
||||||
if " " in name:
|
|
||||||
alright = False
|
|
||||||
|
|
||||||
data = {}
|
name = entity["name"]
|
||||||
data['data'] = {}
|
schema_name = "asset-3.0"
|
||||||
data['type'] = 'asset'
|
|
||||||
schema = "avalon-core:asset-3.0"
|
|
||||||
# TODO have project any REGEX check?
|
|
||||||
if entity.entity_type in ['Project']:
|
|
||||||
# data['type'] = 'project'
|
|
||||||
name = entity['full_name']
|
|
||||||
# schema = "avalon-core:project-2.0"
|
|
||||||
|
|
||||||
if inSchema is not None:
|
if in_schema:
|
||||||
schema = inSchema
|
schema_name = in_schema
|
||||||
data['schema'] = schema
|
elif entity.entity_type.lower() == "project":
|
||||||
data['name'] = name
|
name = entity["full_name"]
|
||||||
try:
|
schema_name = "project-2.0"
|
||||||
avalon.schema.validate(data)
|
|
||||||
except ValidationError:
|
|
||||||
alright = False
|
|
||||||
|
|
||||||
if alright is False:
|
schema_obj = avalon.schema._cache.get(schema_name + ".json")
|
||||||
msg = '"{}" includes unsupported symbols like "dash" or "space"'
|
name_pattern = schema_obj.get("properties", {}).get("name", {}).get(
|
||||||
|
"pattern", default_pattern
|
||||||
|
)
|
||||||
|
if not re.match(name_pattern, name):
|
||||||
|
msg = "\"{}\" includes unsupported symbols like \"dash\" or \"space\""
|
||||||
raise ValueError(msg.format(name))
|
raise ValueError(msg.format(name))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue