datalight package

Submodules

datalight.common module

This module is common core functions for datalight.

exception datalight.common.DatalightException[source]

Bases: Exception

Class for exception

datalight.common.get_authentication_token(sandbox)[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.

datalight.common.get_files_path(directory_name)[source]

Recursively collect file paths within the given directory.

The function will return a list of file paths relative to directory_name. :param directory_name: (str) The path to a directory :return files_paths: (list of string) Paths of files relative to directory_name. :raises FileNotFoundError: if the directory does not exist.

datalight.common.set_up_logger()[source]

Dictionary with the configuration for the logging.

datalight.common.zip_data(files, zip_name)[source]

Method to zip files which will be uploaded to the data repository.

Parameters:
  • files – (list of string) The paths of the files written to the zip archive.
  • zip_name – (str) Name of the zip file to create.

datalight.main module

Main module for datalight.

datalight.main.main(directory_name, metadata_path, zip_name='data.zip', publish=False, sandbox=True)[source]

Run datalight scripts to upload file to data repository

datalight.zenodo module

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

class datalight.zenodo.Zenodo(token, metadata_path, sandbox=False)[source]

Bases: object

Class to upload and download files on Zenodo The deposit record method should be called and this does all of the steps required to uplad a file.

Variables:
  • token – (str) API token for connection to Zenodo.
  • sandbox – (bool) If True, upload to the Zenodo sandbox. If false, upload to Zenodo.
delete(_id=None)[source]

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

Parameters:_id – (int) Deposition id of the record to delete.

Can be done only if the record was not published.

Raises:ZenodoException – If connection return status >= 400
deposit_record(files, directory, publish)[source]

The main method which calls the many parts of the upload process.

publish()[source]

Method which will publish the deposition linked with the id.

Raises:ZenodoException – Raise if connection return status >= 400
set_metadata()[source]

Method to validate metadata.

upload_metadata()[source]

Upload metadata to Zenodo repository.

After creating the request and uploading the file(s) we need to update the metadata needed by Zenodo related to the record.

exception datalight.zenodo.ZenodoException[source]

Bases: Exception

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

datalight.zenodo_metadata module

This module processes and validates metadata.

class datalight.zenodo_metadata.ZenodoMetadata[source]

Bases: object

Class to manage the Metadata needed for a Zenodo upload.

general schema for usage is: set_schema() set_metadata() validate_metadata()

set_metadata(metadata_path)[source]

Method to set metadata from a file.

Parameters:metadata_path – (path) A path to a file which contains zenodo metadata (yaml format).
set_schema()[source]

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

validate_metadata()[source]

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

exception datalight.zenodo_metadata.ZenodoMetadataException[source]

Bases: Exception

Class for exception

Module contents