def delete_unmanaged_file(unmanaged_file, client=None): """ Delete an Unmanaged File from Viz One Args: unmanaged_file (vizone.payload.media.UnmanagedFile): The Unmanaged File to delete client (Optional[vizone.client.Instance]): A Viz One client to use (None means the default) """ logging.info(u'Deleting file %s.', unmanaged_file.title) (client or get_default_instance()).DELETE(unmanaged_file.delete_link)
def create_or_update_asset( id=None, metadata=None, acl=None, mediaacl=None, tags=None, materialtype=None, category=None, rightscode=None, client=None): """ Creates or Updates an Item with a given ``id``. Metadata updates will be retried three times if there are conflicts. Args: id (Optional[unicode]): An asset id or "site identity" metadata (Optional[vizone.vdf.Payload]): The metadata to update to. Can be a dict with a 'form' field too. acl (Optional[vizone.vizone.payload.user_group.Acl]): Specify a ACL when creating the Asset mediaacl (Optional[vizone.vizone.payload.user_group.Acl]): Specify a Media ACL when creating the Asset tags (Optional[dict]): scheme => term dictionary for custom tags when creating the Asset materialtype (Optional[unicode]): Set the Material Type to this when creating the Asset category (Optional[unicode]): Set the Category to this when creating the Asset rightscode (Optional[unicode]): Set the Rights Code to this when creating the Asset client (Optional[vizone.client.Instance]): A Viz One client to use (None means the default) Returns: vizone.payload.asset.Item: The updated or created Asset Entry """ old_payload = None client = client or get_default_instance() # Create or Update Placeholder try: asset = get_asset_by_id(id, headers={'X-Inline': 'describedby'}, client=client) old_payload = asset.describedby_link.metadata except HTTPClientError: try: logging.info(u'Item %s does not exist, creating.', id) asset = Item(id=id) if acl: asset.acl = acl if mediaacl: asset.mediaacl = mediaacl if materialtype: asset.materialtype = materialtype if category: asset.category = category if rightscode: asset.rightscode = rightscode if tags: for scheme, term in sorted(tags.items()): asset.keywords.append( AtomCategory(scheme=scheme, term=term) ) asset = create_asset(asset, client=client) except (HTTPClientError, HTTPServerError): logging.error(u'Could not create asset %s, skipping.', id) return # Create payload if metadata is a dict if type(metadata) is dict: form = metadata.pop('form') if old_payload is None: models = MetadataFormCollection(client.GET(asset.models_link)) model_link = [model.self_link for model in models.entries if model.name == form][0] model = Model(client.GET(model_link)) payload = model.to_payload() else: payload = old_payload for name, value in metadata.items(): payload.set(name, value) else: payload = metadata # Update Metadata if needed if payload is not None and payload != old_payload: logging.info(u'Updating metadata for asset %s.', asset.id) for _ in range(3): try: asset.describedby_link.metadata = Payload(client.PUT(asset.describedby_link, payload)) break except HTTPServerError: logging.error(u'Could not update metadata for asset %s.', asset.id) return except HTTPClientError as e: logging.info(u'Asset Metadata update failed %s', str(e)) if e.responstatus_code == 412: logging.warn(u'Retrying...') asset.parse(client.GET(asset.self_link)) else: break else: logging.info(u'Updating metadata for asset %s not needed.', asset.id) return asset