Using pillarsdk.Node.create_asset_from_file()
This commit is contained in:
parent
1d1c8cf3d6
commit
e29b61b649
@ -202,32 +202,11 @@ async def attach_file_to_group(file_path: pathlib.Path,
|
|||||||
future=None) -> pillarsdk.Node:
|
future=None) -> pillarsdk.Node:
|
||||||
"""Creates an Asset node and attaches a file document to it."""
|
"""Creates an Asset node and attaches a file document to it."""
|
||||||
|
|
||||||
# First upload the file...
|
node = await pillar_call(pillarsdk.Node.create_asset_from_file,
|
||||||
file_id = await pillar.upload_file(home_project_id, file_path,
|
home_project_id,
|
||||||
future=future)
|
group_node_id,
|
||||||
|
'file',
|
||||||
# Then attach it to a node.
|
str(file_path))
|
||||||
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)
|
|
||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user