Storage¶
Interface Storage¶
- class portal.vidispine.istorage.StorageHelper(slug=None, user=None, runas=None, *args, **kwargs)¶
This is just an interface to the helper classes provided by RESTAPI
- addStorageToGroup(group_name, storage_id)¶
Given a storage group name, and a stroage id, add the storage to the group
- Args:
group_name: Name of the storage group
storage_id: The storage id
- Returns:
None
- Signals raised:
Pre modify: sender=self.__class__, instance=(group_name, storage_id), method=”addStorageToGroup”
Post modify: sender=self.__class__, instance=group_name, storage_id), method=”addStorageToGroup”
- copyFileToFile(file_id, destination_storage_id, destination_file_id, priority_of_job=None)¶
Copy file to an existing file on a storage and overwrite the existing file
- Parameters
file_id – The file id for the file that we are copying from
destination_storage_id – Storage if where the file that is going to be overwritten exists
destination_file_id – File id of the file that is being overwritten
priority_of_job – Priority of the vs job should have
- createFileEntity(storageId, filepath, createOnly=True, state='OPEN', return_format='json')¶
Creates a file entity in the database. Does not create any physical files.
- createOnly:
True: Fail if path file already exists
False: Update the existing file if one exists, else create new file entity
- fileUri:
The absolute file URI
- state:
Set the state of the file
- createStorage(storage_document)¶
Given a StorageDocument object, create a storage.
- Args:
storage_document: A VSXMLSchema.StorageDocument to send to Vidispine
- Returns:
Returns a
VidiRest.objects.storage.VSStorage
object representing the newly created storage.
- Signals raised:
Pre create: sender=self.__class__, instance=None, method=”createStorage”
Post modify: sender=self.__class__, instance=storage.getId(), method=”createStorage”
from portal.vidispine.istorage import StorageHelper import VidiRest.schemas.xmlSchema as VSXMLSchema sth = StorageHelper(runas=request.user) # This is the equivalent of the following XML document: """ <StorageDocument xmlns="http://xml.vidispine.com/schema/vidispine"> <type>LOCAL</type> <autoDetect>true</autoDetect> <method> <uri>file:///srv/media/</uri> <read>true</read> <write>true</write> <browse>true</browse> <type>AUTO</type> </method> <metadata> <field> <key>name</key> <value>media</value> </field> </metadata> </StorageDocument> """ storage_method = VSXMLSchema.StorageMethodType(uri = "file:///srv/media/", read = True, write = True, browse = True, type = "AUTO") metadata = VSXMLSchema.SimpleMetadataDocument() name_field = VSXMLSchema.SimpleMetadataTypeField(key="name", value_="media") metadata.field.append(name_field) storage_document = VSXMLSchema.StorageDocument() storage_document.type = "LOCAL" storage_document.metadata = metadata storage_document.method = [storage_method] # Takes a list of storage methods storage_document.autoDetect = True res = sth.createStorage(storage_document) print(res.getId())
- createStorageGroup(group_name, description=None)¶
Given a storage group name, and an optional description, create the storage group
- Args:
group_name: Name of the storage group
description: Optional description of the group
- Returns:
Returns a VStorageGroup object representing the created storage
- Signals raised:
Pre create: sender=self.__class__, instance=None, method=”createStorageGroup”
Post create: sender=self.__class__, instance=group_name, method=”createStorageGroup”
- getAllArchiveStorages()¶
Gets all vidispine archive storages
Use portal.utils.cache.cache_get_vidispine_archive_storages for the cached version
- Returns
A list of VSStorage objects
- getAllFileNotifications()¶
Returns a list of file notifications
- getAllImportables(first=0, number=500, path=None, wildcard=True, sort=None, storage=None, *args)¶
Get a list of all importable files known by the system. By default get the 500 first files.
- Args:
first: From resulting list of items, start return list from file number first
number: Return a maximum of number items
- Returns:
A dictionary object of element list consisting of VSFile and VSSimpleMetadataDocument
- getAllNotifications()¶
Returns a list of storage notifications
- getAllStorages(storage_groups=None, exclude_archive_storages=True, *args)¶
Get all storages in the system.
- Args:
storage_groups: A list of storage groups which defines the domain of the returned storages
exclude_archive_storages: Should we get storages used for archival or not
- Returns:
A list of VSStorage objects
- getAllStoragesPaths()¶
Get all paths for all file methods in all storages and returns it in the following syntax:
- {
‘VX-1’: [‘/srv/media1/’], ‘VX-2’: [‘/srv/media3/’, ‘/srv/media2/’]
}
- getAllWriteAbleStorages(storage_groups=None, *args)¶
Get all writeable and local storages in the system.
- Args:
storage_groups: A list of storage groups which defines the domain of the returned storages
- Returns:
A list of VSStorage objects
- getFilesInStorage(numberoffiles, first, path=None, wildcard=True, sort=None, include_items=True, cursor=None, recursive=True, *args)¶
Get all files in storage set as StorageHelper slug
- Args:
numberoffiles: numberoffiles to get before filtering.
first: the first file to get. When cursor is used this does not affect the output but is still logged
path: Return files under this sub-path to storage
wildcard: If True, Allow the use of wildcards in path
sort: Description of how the files should be sorted
include_items: If True, Return associated items, shapes, and components
- cursor: A cursor to pass to vidispine. See
http://apidoc.vidispine.com/latest/ref/storage/file.html#list-all-files-in-a-storage for more info
recursive: If True, returns all files in the storage tree
- Returns:
A dict containing: hits - the number of hits files - A list of VSFile objects nextCursor - The cursor for the next page if a cursor is used
- getStorage(storage_id=None, *args)¶
Given a storage id, get the storage
- Args:
storage_id: Id of the storage to be fetched
- Returns:
A VSStorage object representing the storage
- getStorageFromFullFileName(path)¶
This function returns a storage id and a path which is relative to the storage root given an absolute path on the portal server. This function caches the list of storages from the server for the life of this StorageHelper object.
- Parameters
path – an absolute path on the portal server
- Returns
A tuple of (storage_id, relative_path)
- getStorageGroup(storagegroup_name)¶
Given a storage group name, get the storage group
- Args:
storagegroup_name: Name of the storage group
- Returns:
A VSStorageGroup object representing the storage group
- moveStorageFileToNewStorage(current_storage_id, file_id, new_storage_id, priority_of_job=None, keep_original=False, new_directory=None, item_id=None, new_filename=None)¶
Given a storage id, file id, and a new storage id, move or copy file to new storage.
- Parameters
current_storage_id – Id of the current storage where the file exists on
file_id – The id of the file on current_storage_id
new_storage_id – The target storage id
priority_of_job – The priority of the move job
keep_original – Do not delete original file, just copy it
new_directory –
New directory relative to the storage root, e.g. ‘finished/’, or ‘’. None means that file path is not modified, empty string is the storage root.
Dots or slashes in the beginning of the path are ignored, as they would cause files disappearing within Vidispine.
new_filename – New name for the file - if not set then current filename is kept
- Returns:
StorageApi return value, or None if action was a no-op (source == destination)
- notifyStorageOfFile(storage_id, filepath, state='CLOSED')¶
Notify a storage that a new file is there, and get a fileID back.
- Args:
storage_id: The id of a storage
filepath: relative path of file.
- Returns:
FileID as string, None on failures
- Exception:
File is already associated, try and get fileID from error message
- removeFileFromStorage(storage_id, file_id, item_id=None, priority_of_job=None)¶
Given a storage id and a file id, remove the file from the storage
- Args:
storage_id: Id of the storage where the file exists on
file_id: The id of the file on current_storage_id
- Returns:
None
- removeFileItemRelationship(storage_id, file_id)¶
Given a storage id and a file id, remove the files association from an item
- Args:
storage_id: Id of the storage where the file exists on
file_id: The id of the file on current_storage_id
- Returns:
None
- removeSpecificStorageRule(shape_tag)¶
Removes a specific storage rule for a given shape tag
- Args:
shape_tag: Shape tag name
- Returns:
None
- removeStorage(storage_id)¶
Given a storage id, remove the storage from system
- Args:
storage_id: The storage id
- Returns:
None
- Signals raised:
Pre delete: sender=self.__class__, instance=storage_id, method=”removeStorage”
Post delete: sender=self.__class__, instance=storage_id, method=”removeStorage”
- removeStorageFromGroup(group_name, storage_id)¶
Given a storage group name, and a stroage id, remove the storage from the group
- Args:
group_name: Name of the storage group
storage_id: The storage id
- Returns:
None
- Signals raised:
Pre modify: sender=self.__class__, instance=(group_name, storage_id), method=”removeStorageFromGroup”
Post modify: sender=self.__class__, instance=group_name, storage_id), method=”removeStorageFromGroup”
- removeStorageGroup(group_name)¶
Given a storage group name, remove it.
- Args:
group_name: Name of the storage group
- Returns:
None
- Signals raised:
Pre delete: sender=self.__class__, instance=group_name, method=”removeStorageGroup”
Post delete: sender=self.__class__, instance=group_name, method=”removeStorageGroup”
- restoreFileFromGlacier(storage_id, file_id, expiration_in_days=1)¶
Trigger a request to glacier to initiate a restore. Once restore is complete the file will be put back in CLOSED state.
- Args:
storage_id: The id of a storage
file_id: id of file
expiration_in_days: How long the restored file should be available.
- setFileState(storage_id, file_id, state='CLOSED')¶
Set file state Args:
storage_id: The id of a storage
file_id: id of file
state: state of file
- setFilenameScript(storage_id, predefinedScriptName)¶
Sets a filename script for a storage
- Args:
storage_id: The id of a storage
predefinedScriptName: Name of a predefined script
- Returns:
Result of setting a script to a storage
- Signals raised:
Pre modify: sender=self.__class__, instance=storage_id, method=”setStorageFilenameScript”, predefinedScriptName=predefinedScriptName
Post modify: sender=self.__class__, instance=storage_id, method=”setStorageFilenameScript”
- updateStorage(storage_id, storage_document)¶
Given a storage id and a StorageDocument object, update the given storage.
- Args:
storage_document: A StorageDocument object
storage_id: The storage id
- Returns:
Returns a VStorage object representing the updated storage
- Signals raised:
Pre modify: sender=self.__class__, instance=storage_id, method=”updateStorage”
Post modify: sender=self.__class__, instance=storage_id, method=”updateStorage”
- updateStoragePriority(storage_id, priority='MEDIUM')¶
Given a storage id and priority, update the given storage
- Args:
storage_id: The storage id
priority: New priority to set
- Returns:
None
- portal.vidispine.istorage.getPredefinedScriptFile(name)¶
Returns the contents of a storage script, located in js/storagescripts
- Args:
name: The name of a shape tag script
- Returns:
The contents of the script