The cerebro.cargador module provides access to the Cargador file storage.
cerebro.cargador.download_file(hash, project_id)
Parameters: | |
# Attachment download
attach = cerebro.core.current_attachment() # getting current attachment
task = cerebro.core.current_task() # getting the current task to get the project ID
if not attach.is_link(): # checking if the attachment is not a link
file_name = cerebro.cargador.file_name_form_hash(attach.file_hash()) # trying to get filename by the hash sum
if not file_name or file_name == '': # if there is no file, trying to download it
cerebro.cargador.download_file(attach.file_hash(), task.project_id())
Note
You can download a review on the file using the same method, but getting the review hash sum instead of the source file hash sum - ,attach.review_hash(). Use the cerebro.cargador.download_thumbnail() function to download the file’s thumbnails.
See also
cerebro.cargador.download_thumbnail(hash, project_id)
Parameters: | |
Note
Thumbnails downloaded with the download_thumbnail function, are saved into a special folder for thumbnails, in order to keep clean folders with source files.
# Downloading a thumbnail of an attachment
attach = cerebro.core.current_attachment() # resolving current attachment
task = cerebro.core.current_task() # resolving current attachment to get the project ID
hashs = attach.thumbnail_hashs() # resolving the list of thumbnail hash sums
for hash in hashs: # sorting out the thumbnails
if hash and hash != '': # if a file has a thumbnail
file_name = cerebro.cargador.file_name_form_hash(hash) # trying to get the thumbnail name by the hash
if not file_name or file_name == '': # if the thumbnail is absent, trying to download it
cerebro.cargador.download_thumbnail(hash, project_id)
See also
cerebro.cargador.file_name_form_hash(hash)
Parameters: | hash (string) – file hash sum. |
Returns: | absolute file path. If the file is absent in the file storage, None is returned. |
Return type: | string |
attach = cerebro.core.current_attachment() # resolving current attachment
file_name = cerebro.cargador.file_name_form_hash(attach.file_hash()) # trying to resolve file name by the hash sum
print('File name', file_name)
cerebro.cargador.is_connected()
Returns: | True, if connection to the Cargador service is established. |
Return type: | bool |
cerebro.cargador.is_local()
Returns: | True, if local Cargador service is connected. False, if network Cargador is connected. |
Return type: | bool |
cerebro.cargador.storage_host()
Returns: | Address of the host with the Cargador service connected. |
Return type: | string |
cerebro.cargador.storage_path()
Returns: | Path to the file storage. |
Return type: | string |