10.3. Module cargador¶
The cerebro.cargador module provides access to the Cargador file storage.
Functions
download_file()
download_thumbnail()
file_name_form_hash()
is_connected()
is_local()
storage_host()
storage_path()
-
cerebro.cargador.
download_file
(hash, project_id)[source]¶ Parameters: Enqueues the file to be downloaded from a remote file storage.
# 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 attach.is_link() != True: # checking if the attachment is a file, not a link file_name = cerebro.cargador.file_name_form_hash(attach.file_hash()) # trying to get filename by the hash sum if file_name == '' or file_name == None: # if the file is absent, 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 thecerebro.cargador.download_thumbnail()
function to download the file’s thumbnails.See also
-
cerebro.cargador.
download_thumbnail
(hash, project_id)[source]¶ Parameters: Enqueues the thumbnail to be downloaded from a remote file storage.
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 != None: # if a file has a thumbnail file_name = cerebro.cargador.file_name_form_hash(hash) # trying to get the thumbnail name by the hash sum if file_name == '' or file_name == None: # 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)[source]¶ 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
()[source]¶ Returns: True, if connection to the Cargador service is established. Return type: bool
-
cerebro.cargador.
is_local
()[source]¶ Returns: True, if local Cargador service is connected. False, if network Cargador is connected. Return type: bool