in gnm_deliverables/models.py [0:0]
def create_asset_from_vs_item(self, item_id, user):
"""
tries to "adopt" the given existing vidispine item onto this deliverable bundle.
if the item is already associated with this deliverable bundle then it is returned without re-import.
can raise NoShapeError if either the item has no original shape, or VSNotFound if the item does not exist.
can also raise other VSException from gnmvidispine if server communication fails.
:param item_id: item id to adopt
:param user: name of the user carrying out the operation, it will be done as this user in VS
:return: a tuple of (DeliverableAsset, Boolean) where the boolean value indicates whether a new DeliverableAsset
was created or not
"""
created = False
try:
asset = DeliverableAsset.objects.get(online_item_id=item_id, deliverable=self)
logger.info(
'Asset for item "{item_id}" already existed: {asset}'.format(item_id=item_id,
asset=asset))
except DeliverableAsset.DoesNotExist:
asset = DeliverableAsset(
online_item_id=item_id,
deliverable=self
)
item = asset.item(user)
try:
shape = item.get_shape("master")
except VSNotFound:
##we can tidy the re-raise up later
raise NoShapeError('No original shape attached to item')
asset.filename = item.get("originalFilename", allowArray=False)
asset.absolute_path = item.get("originalUri", allowArray=False)
files = [x for x in shape.files()]
if len(files) == 0:
raise NoShapeError("Original shape had no files on it")
asset.size = files[0].size
mtime = None ##FIXME: sort this out
asset.ingest_complete_dt = now()
asset.created_from_existing_item = True
asset.save()
created = True
logger.info(
'Asset for item "{item_id}" created: {asset}'.format(item_id=item_id, asset=asset))
return asset, created