datalight package

Submodules

datalight.common module

This module is common core functions for datalight.

exception datalight.common.DatalightException[source]

Bases: Exception

Class for exception

class datalight.common.UploadStatus(code: int, message: str, error_field: str = None, error_message: str = None)[source]

Bases: object

The status of the upload as it goes through the upload process.

datalight.common.get_authentication_token(credentials_location: pathlib.Path, sandbox: bool) → Optional[str][source]

A method to read the Zenodo authentication token from a local file. This file is not committed to git and so will not appear online. :param credentials_location: The location of the credentials file. :param sandbox: Whether to get the Zenodo sandbox token or a real Zenodo token.

datalight.common.read_yaml(file_path: Union[pathlib.Path, str]) → dict[source]

Read a YAML file and return its contents.

datalight.main module

Main module for datalight.

datalight.main.get_status(config_path: Union[pathlib.Path, str], repository: str = 'Zenodo', **kwargs) → bool[source]

Check whether the selected data repository is set up correctly to do an upload. Return True if it is and False if not. :param config_path: The path to the Datalight config file containing API keys. :param repository: The data repository that will be used. :param kwargs:

See below
Keyword Arguments:
 
  • sandbox (bool) – If Zenodo is selected as the repository. Whether to use the Zenodo sandbox or live Zenodo.
datalight.main.open_gui(root_path: str)[source]

The main function. This opens the DataLight GUI. :param root_path: The path to the root of the RoboTA project metadata descriptions.

datalight.main.upload_record(file_paths: List[str], repository_metadata: Union[dict, str], config_path: Union[pathlib.Path, str], experimental_metadata: Optional[dict] = None, publish: bool = False, sandbox: bool = True, repository: str = 'Zenodo', deposition_ID: int = None)[source]

Upload a new record to a data repository.

datalight.zenodo module

This module is implements high level functions to upload and download data to Zenodo.

class datalight.zenodo.ExperimentalMetadata(metadata: dict)[source]

Bases: object

generate_metadata_summary()[source]

A method to take all of the metadata and write it to a text file which will be uploaded along with the data.

remove_temp_folder()[source]
exception datalight.zenodo.ZenodoException[source]

Bases: Exception

General exception raised when there is some failure to interface with Zenodo.

datalight.zenodo.delete_record(deposition_url: str, deposition_id: int, token: str) → datalight.common.UploadStatus[source]

Method to delete an unpublished deposition. If id not provided, use deposition_id, else use provided id

Parameters:
  • deposition_url – URL to make the Zenodo API request.
  • deposition_id – Deposition id of the record to delete. Record can only be deleted if it was not published.
  • token – API token for connecting to Zenodo.
datalight.zenodo.deposit_record(files: List[str], raw_metadata: dict, deposition_url: str, token: str, publish: bool, deposition_ID: int) → datalight.common.UploadStatus[source]

Method which calls the parts of the upload process. :returns: An UploadStatus object indicating whether there was an error or if the upload

was successful.
datalight.zenodo.get_deposition_url(sandbox: bool)[source]

Get the Zenodo API URL for requesting an upload. The URL depends on whether the sandbox or live version of Zenodo is being used.

datalight.zenodo.load_yaml(metadata_path: str) → dict[source]

Method to read metadata from a file. :param metadata_path: A path to a file which contains zenodo metadata (yaml format).

datalight.zenodo.publish_record(deposition_url: str, deposition_id: int, token: str) → datalight.common.UploadStatus[source]

Method which will publish the deposition linked with the id.

Raises:ZenodoException – Raise if connection return status >= 400
datalight.zenodo.try_connection(deposition_url: str, token: str) → datalight.common.UploadStatus[source]

Method to test that the API token and connection with Zenodo website is working.

datalight.zenodo.upload_record(file_paths: List[str], repository_metadata: Union[dict, str], config_path: Union[pathlib.Path, str], experimental_metadata: dict, publish: bool, sandbox: bool, deposition_ID: int = None) → datalight.common.UploadStatus[source]

Run datalight scripts to upload file to data repository :param file_paths: One or more paths of files to upload. :param repository_metadata: Either a path to load metadata from or a dictionary of metadata

describing the record.
Parameters:
  • config_path – Path to the file containing zenodo API tokens.
  • experimental_metadata – A dictionary of experimental metadata - if not None, this will be written to a text file and added to the upload.
  • publish – Whether to publish this record on Zenodo after uploading.
  • sandbox – Whether to put the record on Zenodo sandbox or the real Zenodo.
  • deposition_ID – If provided, an existing Zenodo deposition to amend.
Returns:

None if upload successful else returns a string describing the error.

datalight.zenodo.validate_metadata(raw_metadata: dict) → Tuple[datalight.common.UploadStatus, dict][source]

Compare the metadata to the schema and remove anything not allowed by Zenodo.

datalight.zenodo_metadata module

This module processes and validates metadata.

exception datalight.zenodo_metadata.ZenodoMetadataException[source]

Bases: Exception

Class for exception

datalight.zenodo_metadata.read_schema_from_file() → dict[source]

Method to read the schema. Reads schema from self.schema_path Stores schema dictionary in self.schema

datalight.zenodo_metadata.remove_extra_properties(metadata: dict) → dict[source]

Method to remove properties which are not allowed by zenodo.

Json-schema has a major limitation, it does not allow the usage of:

additionalProperties: False

when using the “allOf” keyword.

This problem is described as a shortcoming https://json-schema.org/understanding-json-schema/reference/combining.html which implies that we need to deal with this outside the json schema to verify that only Zenodo metadata are provided. This is likely to be resolved in json-schema draft-8 some time in 2019.

datalight.zenodo_metadata.validate_metadata(metadata: dict, schema: dict) → dict[source]

Method which verifies that the metadata have the correct type and that dependencies are respected.

Module contents