From 1ddb8e64cb029aa430580c993c13c77c433e8dd6 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 25 Sep 2020 12:45:42 +0200 Subject: [PATCH 1/2] #180 - Changed tasks to dictionaries Modifications based on change --- avalon/inventory.py | 4 +- avalon/schema/config-1.1.json | 83 ++++++++++++++++++++++++++++++ avalon/schema/inventory-1.1.json | 10 ++++ avalon/schema/project-2.1.json | 86 ++++++++++++++++++++++++++++++++ avalon/tests/test_inventory.py | 20 ++++---- avalon/tools/models.py | 10 ++-- 6 files changed, 196 insertions(+), 17 deletions(-) create mode 100644 avalon/schema/config-1.1.json create mode 100644 avalon/schema/inventory-1.1.json create mode 100644 avalon/schema/project-2.1.json diff --git a/avalon/inventory.py b/avalon/inventory.py index a33dc126e..248da0499 100644 --- a/avalon/inventory.py +++ b/avalon/inventory.py @@ -34,7 +34,7 @@ DEFAULTS = { "config": { - "schema": "avalon-core:config-1.0", + "schema": "avalon-core:config-1.1", "apps": [ { "name": "shell", @@ -98,7 +98,7 @@ def create_project(name): raise RuntimeError("%s already exists" % name) return io.insert_one({ - "schema": "avalon-core:project-2.0", + "schema": "avalon-core:project-2.1", "type": "project", "name": name, "data": dict(), diff --git a/avalon/schema/config-1.1.json b/avalon/schema/config-1.1.json new file mode 100644 index 000000000..5f4fe4b2f --- /dev/null +++ b/avalon/schema/config-1.1.json @@ -0,0 +1,83 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + + "title": "avalon-core:config-1.1", + "description": "A project configuration.", + + "type": "object", + + "additionalProperties": false, + "required": [ + "template", + "tasks", + "apps" + ], + + "properties": { + "schema": { + "description": "Schema identifier for payload", + "type": "string" + }, + "template": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^.*$": { + "type": "string" + } + } + }, + "tasks": { + "type": "object", + "properties": { + "short_name": {"type": "string"}, + "icon": {"type": "string"}, + "group": {"type": "string"}, + "label": {"type": "string"} + }, + "required": ["short_name"] + }, + "apps": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "icon": {"type": "string"}, + "group": {"type": "string"}, + "label": {"type": "string"} + }, + "required": ["name"] + } + }, + "families": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "icon": {"type": "string"}, + "label": {"type": "string"}, + "hideFilter": {"type": "boolean"} + }, + "required": ["name"] + } + }, + "groups": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "icon": {"type": "string"}, + "color": {"type": "string"}, + "order": {"type": ["integer", "number"]} + }, + "required": ["name"] + } + }, + "copy": { + "type": "object" + } + } +} diff --git a/avalon/schema/inventory-1.1.json b/avalon/schema/inventory-1.1.json new file mode 100644 index 000000000..f46df6973 --- /dev/null +++ b/avalon/schema/inventory-1.1.json @@ -0,0 +1,10 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + + "title": "avalon-core:config-1.1", + "description": "A project configuration.", + + "type": "object", + + "additionalProperties": true +} diff --git a/avalon/schema/project-2.1.json b/avalon/schema/project-2.1.json new file mode 100644 index 000000000..22327b2f0 --- /dev/null +++ b/avalon/schema/project-2.1.json @@ -0,0 +1,86 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + + "title": "avalon-core:project-2.1", + "description": "A unit of data", + + "type": "object", + + "additionalProperties": true, + + "required": [ + "schema", + "type", + "name", + "data", + "config" + ], + + "properties": { + "schema": { + "description": "Schema identifier for payload", + "type": "string", + "enum": ["avalon-core:project-2.1"], + "example": "avalon-core:project-2.1" + }, + "type": { + "description": "The type of document", + "type": "string", + "enum": ["project"], + "example": "project" + }, + "parent": { + "description": "Unique identifier to parent document", + "example": "592c33475f8c1b064c4d1696" + }, + "name": { + "description": "Name of directory", + "type": "string", + "pattern": "^[a-zA-Z0-9_.]*$", + "example": "hulk" + }, + "data": { + "description": "Document metadata", + "type": "object", + "example": { + "fps": 24, + "width": 1920, + "height": 1080 + } + }, + "config": { + "type": "object", + "description": "Document metadata", + "example": { + "schema": "avalon-core:config-1.1", + "apps": [ + { + "name": "maya2016", + "label": "Autodesk Maya 2016" + }, + { + "name": "nuke10", + "label": "The Foundry Nuke 10.0" + } + ], + "tasks": { + "Model": {"short_name": "mdl"}, + "Render": {"short_name": "rnd"}, + "Animate": {"short_name": "anim"}, + "Rig": {"short_name": "rig"}, + "Lookdev": {"short_name": "look"}, + "Layout": {"short_name": "lay"} + }, + "template": { + "work": + "{root}/{project}/{silo}/{asset}/work/{task}/{app}", + "publish": + "{root}/{project}/{silo}/{asset}/publish/{subset}/v{version:0>3}/{subset}.{representation}" + } + }, + "$ref": "config-1.1.json" + } + }, + + "definitions": {} +} diff --git a/avalon/tests/test_inventory.py b/avalon/tests/test_inventory.py index bc9471d4d..7ff2b771f 100644 --- a/avalon/tests/test_inventory.py +++ b/avalon/tests/test_inventory.py @@ -19,12 +19,12 @@ self = sys.modules[__name__] self._project = { - "schema": "avalon-core:project-2.0", + "schema": "avalon-core:project-2.1", "type": "project", "name": PROJECT_NAME, "config": { "template": {}, - "tasks": [], + "tasks": {}, "apps": [], "copy": {} }, @@ -36,10 +36,10 @@ {"name": "app1"}, {"name": "app2"}, ], - "tasks": [ - {"name": "task1"}, - {"name": "task2"}, - ], + "tasks": { + {"Animation": {"short_name": "anim"}}, + {"Modeling": {"short_name": "mdl"}}, + }, "template": { "work": "{root}/{project}/{silo}/{asset}/work/" @@ -122,10 +122,10 @@ def test_save(): {"name": "app1"}, {"name": "app2"}, ], - "tasks": [ - {"name": "task1"}, - {"name": "task2"}, - ], + "tasks": { + {"Animation": {"short_name": "anim"}}, + {"Modeling": {"short_name": "mdl"}}, + }, "template": { "work": "{root}/{project}/{silo}/{asset}/work/" diff --git a/avalon/tools/models.py b/avalon/tools/models.py index 04597fad4..4f2d4ccd4 100644 --- a/avalon/tools/models.py +++ b/avalon/tools/models.py @@ -216,13 +216,13 @@ def __init__(self, parent=None): def _get_task_icons(self): # Get the project configured icons from database project = io.find_one({"type": "project"}) - tasks = project["config"].get("tasks", []) - for task in tasks: + tasks = project["config"].get("tasks", {}) + for task_name, task in tasks.items(): icon_name = task.get("icon", None) if icon_name: icon = qtawesome.icon("fa.{}".format(icon_name), color=style.colors.default) - self._icons[task["name"]] = icon + self._icons[task_name] = icon def set_assets(self, asset_ids=None, asset_docs=None): """Set assets to track by their database id @@ -257,8 +257,8 @@ def set_assets(self, asset_ids=None, asset_docs=None): tasks = collections.Counter() for asset_doc in asset_docs: - asset_tasks = asset_doc.get("data", {}).get("tasks", []) - tasks.update(asset_tasks) + asset_tasks = asset_doc.get("data", {}).get("tasks", {}) + tasks.update(asset_tasks.keys()) self.clear() self.beginResetModel() From dadf0fa6c3201c62bdb705e0294631f039c2623b Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 2 Oct 2020 11:04:00 +0200 Subject: [PATCH 2/2] Fix config schema for correct creation from empty DB --- avalon/schema/config-1.1.json | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/avalon/schema/config-1.1.json b/avalon/schema/config-1.1.json index 5f4fe4b2f..c278b6be3 100644 --- a/avalon/schema/config-1.1.json +++ b/avalon/schema/config-1.1.json @@ -29,13 +29,18 @@ }, "tasks": { "type": "object", - "properties": { - "short_name": {"type": "string"}, - "icon": {"type": "string"}, - "group": {"type": "string"}, - "label": {"type": "string"} - }, - "required": ["short_name"] + "items": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "icon": {"type": "string"}, + "group": {"type": "string"}, + "label": {"type": "string"} + }, + "required": [ + "short_name" + ] + } }, "apps": { "type": "array",