qmenta.core.upload

class qmenta.core.upload.single.FileInfo(project_id: int, name: str = '', date_of_scan: str = '', description: str = '', subject_name: str = '', session_id: str = '', input_data_type: str = '', is_result: bool = False, add_to_container_id: int = 0, split_data: bool = False)

Specifies the metadata of a file that will be uploaded to the platform.

Parameters:
  • project_id (int) – The ID of the project to which the new file will be added

  • name (str) – The name of the file in the platform. It is recommended to use the filename (optional)

  • date_of_scan (str) – The date when the scan was made (optional)

  • description (str) – A description of the data that is uploaded (optional)

  • subject_name (str) – The anonymised ID of the subject (optional)

  • session_id (str) – The ID of the scanning session for the subject (optional). If left blank, the next numerical session ID for the subject will automatically be assigned to the session by the platform.

  • input_data_type (str) – The analysis to be used to process the data (optional). When left blank, the input data type will be set automatically. It is recommended to leave it blank, except for testing specific tools for processing uploaded data.

  • is_result (bool) – Default value: False. Set to True if the uploaded data is the output of an offline analysis.

  • add_to_container_id (int) – ID of the container to which this file should be added (if id > 0). Default value: 0. When the value is 0, the data will be added to a new container.

  • split_data (bool) – If True, the platform will try to split the uploaded file into different sessions. It will be ignored when the session_id is given. Default value: False.

add_to_container_id: int = 0
date_of_scan: str = ''
description: str = ''
input_data_type: str = ''
is_result: bool = False
name: str = ''
project_id: int
session_id: str = ''
split_data: bool = False
subject_name: str = ''
class qmenta.core.upload.single.SingleUpload(auth: Auth, path: str, file_info: FileInfo, anonymise: bool = True, upload_index: int = -1, keep_created_files: bool = True)

Class to upload a single ZIP file to the platform. When there is a failure in initializing the instance, status will be set to FAILED, and a status_message will be set.

Parameters:
  • auth (Auth) – The object used to authenticate to the QMENTA platform.

  • path (str) – The input directory or file that will be zipped (optional), anonymised (optional) and uploaded.

  • file_info (FileInfo) – All the metadata for the file to be stored in the platform.

  • anonymise (bool) – If set, a new zip file will be created with the same name which contains the anonymised version of the data of the original zip file. The new zip file will be uploaded instead of the original one. Default value: True.

  • upload_index (int) – This value will be passed to the ‘upload-status’ and ‘upload-progress’ signals. It is set by MultipleThreadedUploads and used to quickly identify the upload that was updated. Default value: -1.

  • keep_created_files (bool) – Keep the files containing the zipped directory and anonymised data after the upload finished. When set to False, the qm-*.zip files that were created by this SingleUpload will be deleted when the upload if finished. Default value: True.

input_filename

The file that will be anonymised (optional), and uploaded.

Type:

str

upload_filename

The file that will be uploaded. If anonymisation is disabled, this will be the same as filename. With anonymisation enabled, a new file will be created that contains the anonymised data.

Type:

str

upload_id

The upload session ID. This will be automatically generated and depends on the current time and the upload filename.

Type:

str

file_size

The size in bytes of the file to be uploaded. Automatically determined when the SingleUpload object is constructed.

Type:

int

status_message

In case the status becomes FAILED, status_message will contain a message indicating what went wrong.

Type:

str

Raises:

errors.CannotReadFileError – When the input cannot be read

property bytes_uploaded: int

The amount of bytes that has been uploaded so far. When the value is updated, signal(‘upload-progress’) is sent.

Type:

int

start() None

Check that the file was not uploaded yet, anonymise it if needed, and upload the (anonymised) file. When there is a failure in anonymising or uploading, status will be set to FAILED and a status_message is set.

Raises:
property status: UploadStatus

The current status of the upload. Setting the status will trigger signal(‘upload-status’).

Type:

UploadStatus

exception qmenta.core.upload.single.UploadAlreadyDoneError(*args: str)

When calling upload_file() a second time and the upload already finished.

exception qmenta.core.upload.single.UploadAlreadyStartedError(*args: str)

When calling upload_file() a second time and the upload is already in progress.

exception qmenta.core.upload.single.UploadError(*args: str)

When a problem occurs while uploading.

class qmenta.core.upload.single.UploadStatus(value)

The current stage of a SingleUpload in the uploading process.

ANONYMISING = 4
DELETING_TMP_FILES = 8
DONE = 9
FAILED = 10
TO_ANONYMISE = 3
TO_CLEAN = 7
TO_UPLOAD = 5
TO_ZIP = 0
TO_ZIP_AND_ANONYMISE = 1
UPLOADING = 6
ZIPPING = 2
class qmenta.core.upload.multi.MultipleThreadedUploads(auth: Auth)

Multiple uploads that are running in their own threads. signal(‘upload-progress’) is triggered when a SingleUpload progress is changed. signal(‘upload-status’) is triggered when a SingleUpload status is changed. Both signals are triggered with upload_index as a parameter.

Parameters:

auth (platform.Auth) – The Auth object to communicate with QMENTA platform

upload_list

The SingleUpload objects that were added

Type:

list[SingleUpload]

uploads_in_progress

The number of uploads that are currently in progress

Type:

int

add_upload(filename: str, file_info: FileInfo, anonymise: bool = True, keep_created_files: bool = True) None

Add a new upload to the upload list.

Parameters:
  • filename (str) – The full path to the file to be uploaded.

  • file_info (FileInfo) – The metadata of the file to be uploaded.

  • anonymise (bool) – Anonymise the data before uploading. Default value: True

  • keep_created_files (bool) – Keep the files created by zipping and anonymising data. If set to False, the files that were created will be deleted after the upload. Default value: True.

property max_parallel_uploads: int

The maximum number of uploads to be in progress at the same time. When files are added and less uploads are in progress than the maximum allowed parallel uploads, the new file upload is automatically started. If an upload finishes, the next queued file upload will automatically be started. Decreasing the value of max_parallel_uploads will not terminate uploads that are already in progress. Default value: 3.

Type:

int