datalight package

Submodules

datalight.common module

exception datalight.common.DatalightException[source]

Bases: Exception

Class for exception

datalight.common.get_files_path(fname)[source]

Function to get the path(s) of the file(s)

Parameters:fname (str) – Name of the file to get the path or the directory to list
datalight.common.unzip(self)[source]
datalight.common.zipdata(files, zipname='data.zip')[source]

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

Parameters:
  • files (list) – a list of string which contains the path of the files which will be part of the zip archive. Path will be conserved.
  • zipname (str, optional) – Name of the zip file to create. Default: data.zip

datalight.conf module

Module to contains the configuration of the zenoligth software

Authors:Nicolas Gruel <nicolas.gruel@manchester.ac.uk>
Copyright:IT Services, The University of Manchester

datalight.datalight module

Main module for datalight

Authors:Nicolas Gruel <nicolas.gruel@manchester.ac.uk>
Copyright:IT Services, The University of Manchester
datalight.datalight.main(args=None)[source]

Run datalight scripts to upload file on data repository

Command line:

Usage: datalight [-h | --help] <files>... (-m <metadata> | --metadata=<metadata>) [options]

Options:

-m FILE --metadata=FILE        File which contains the metadata information
-z zipname --zipname=FILE      Name of the zip file which will be uploaded [default: data.zip]
--nozip                        Do not create zip file containing the data to upload
-r NAME --repository=NAME      Name of a data repository [default: zenodo]
-p --publish                    If present publish the data
-s --sandbox                   If present, datalight will use the sandbox data repository
-k --keep                      Keep zip file created
-h --help                      Print this help
-v --version                   Print version of the software

Examples:
    datalight file1 file2
    datalight directory --metadata=metadata.yml --repository=zenodo
    datalight file -m metadata.yml
Raises:
  • SystemExit – if the file or the folder to treat is not available.
  • KeyError – if no key found for the data repository wanted
  • ImportError – if the not possible to import the data repository wanted

datalight.main module

datalight.token_tmp module

Manage the token creation. modification and reading

datalight.zenodo module

This module is implementing high level function to upload and download data on Zenodo.

Authors:Nicolas Gruel <nicolas.gruel@manchester.ac.uk>
Copyright:IT Services, The University of Manchester
class datalight.zenodo.Zenodo(token, metadata=None, sandbox=False)[source]

Bases: object

Class to upload and download files on Zenodo

token

Token that need to be provided to Zenodo to be able to upload. The attribute is optional.

Type:str, optional
sandbox

Default False, if True, the record is created on the Zenodo sandbox version which is provided for test purpose.

Type:bool
connection()[source]

Method to test that connection with Zenodo website is working.

delete(_id=None)[source]

Method to delete deposition.

Parameters:
  • _id (int) – deposition id of the record to delete. Can be done only if the record was not publish.
  • Exception
  • ---------
  • ZenodoException – raise if token not define (token = None) or if connection return status >= 400
download_files(id=None, doi=None)[source]

Method to download file present in a specific record

get_deposition_id()[source]

Method to obtain the deposition id need to upload documents to Zenodo

deposition_id

Deposition id gave by Zenodo deposition api to be used to upload files and metadata.

Type:int
Exception
---------
ZenodoException

raise if token not define (token = None) or if connection return status >= 400

publish()[source]

Method which will publish the deposition linked with the id.

set_metadata(metadata=None)[source]

Method to read and validate metadata.

Returns:metadata – dictionary with one key ‘metadata’ associated to Zenodo metadata, ready to be use for uploading.
Return type:dict
upload_files(filenames, path=None, _id=None)[source]

Method to upload a file to Zenodo

Parameters:
  • filenames (str) – Name of the file(s) to upload
  • path (str, optional) – Path of where the file(s) is.
  • _id (int) – deposition id of the record where the file(s) will be updated
  • Exception
  • ---------
  • ZenodoException – raise if token not define (token = None) or if connection return status >= 400
upload_metadata(metadata=None, _id=None)[source]

Upload metadata to Zenodo repository.

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

Parameters:
  • metadata (dict) – dictionary which contains zenodo metadata. It should be a dictionary with one key ‘metadata’ associated to another dictionary which contains the Zenodo metadata.
  • _id (int) – deposition id of the record where the metadata will be updated
exception datalight.zenodo.ZenodoException[source]

Bases: Exception

Class for exception

datalight.zenodo_metadata module

This module is implementing high level function to upload and download Lightform data.

Note

There are no verification of the validity of the schema used to validate the metadata which will be uploaded to Zenodo. This part should be done somewhere else. In a perfect world, the schema should be provided by Zenodo but it is not (yet) the case.

Authors:Nicolas Gruel <nicolas.gruel@manchester.ac.uk>
Copyright:IT Services, The University of Manchester
class datalight.zenodo_metadata.ZenodoMetadata(metadata, schema='/home/gruel/PycharmProjects/datalight/datalight/schemas/zenodo/metadata-1.0.0.yml')[source]

Bases: object

Class to manage the Metadata needed for Zenodo.

get_metadata()[source]

Method which will return Zenodo metadata

This method will return a dictionary which contains Zenodo metadata.

Returns:metadata – Dictionary which contains Zenodo metadata.
Return type:dict
set_metadata(metadata)[source]

Method to set metadata from a file or a dictionary.

set_schema(schema)[source]
validate()[source]

Method which is verifying that the metadata does have the correct type and if the dependencies are respected.

The dependencies have to be check because the value of a metadata can implied the presence of another one. For example, if upload_type (which is a necessary metadata) has the value publication that implied the presence of the metadata publication_type.

exception datalight.zenodo_metadata.ZenodoMetadataException[source]

Bases: Exception

Class for exception

Module contents