From e29b61b6491cec83a98b25633f5bc1fc33bd70b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 5 Jul 2016 16:47:37 +0200 Subject: [PATCH] Using pillarsdk.Node.create_asset_from_file() --- blender_cloud/settings_sync.py | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/blender_cloud/settings_sync.py b/blender_cloud/settings_sync.py index 79242c5..4b9d89f 100644 --- a/blender_cloud/settings_sync.py +++ b/blender_cloud/settings_sync.py @@ -202,32 +202,11 @@ async def attach_file_to_group(file_path: pathlib.Path, future=None) -> pillarsdk.Node: """Creates an Asset node and attaches a file document to it.""" - # First upload the file... - file_id = await pillar.upload_file(home_project_id, file_path, - future=future) - - # Then attach it to a node. - node, created = await find_or_create_node( - where={ - 'project': home_project_id, - 'node_type': 'asset', - 'parent': group_node_id, - 'name': file_path.name, - 'user': user_id}, - additional_create_props={ - 'properties': {'file': file_id}, - }) - - if not created: - # Update the existing node. - node.properties = {'file': file_id} - updated_ok = await pillar_call(node.update) - if not updated_ok: - log.error( - 'Blender Cloud addon: unable to update asset node on the Cloud for file %s.', - file_path) - raise pillar.PillarError( - 'Unable to update asset node on the Cloud for file %s' % file_path.name) + node = await pillar_call(pillarsdk.Node.create_asset_from_file, + home_project_id, + group_node_id, + 'file', + str(file_path)) return node