pharmaship.core.import_data

Import package utilities.

class pharmaship.core.import_data.Importer

Class used to import a data file in Pharmaship.

The modules available for importation must have:
  • an import_data.py file (ie: pharmaship.inventory.import_data)

  • inside this file, a DataImport class

  • this class must have an update method

The package to import must:
  • be an armored GPG-signed file

  • be a tar file

  • a package.yaml file conform to the schemas/package.json schema

  • a MANIFEST file with sha256 checksums of all files inside the package

DataImport class must have the follwing arguments:
  • tar - the tar file of the package

  • conf - the configuration of the package (from package.yaml)

  • key - for the GPG key ID used to sign the package

Example

>>> from pharmaship.core.import_data import Importer
>>> my_importer = Importer()
>>> my_importer.read_package("my/path/archive.tar.asc")
True
>>> my_importer.check_signature()
True
>>> my_importer.check_conformity()
True
>>> my_importer.deploy()
True
check_conformity()

Check the package is importable in Pharmaship.

What is checked:
  • The package is a valid tar file

  • The package has a package.yaml file

  • The package.yaml file is conform to the schema

  • The modules concerned by the update are installed in Pharmaship

Tar file is stored in self.archive property.

Configuration from package.yaml is stored in self.conf property.

Returns

True if the package is conform, False otherwise.

Return type

bool

check_signature()

Check the signature of the package.

Decoded data is stored in self.data property.

Returns

True if the signature is correct, False otherwise.

Return type

bool

deploy()

Propagate the import to concerned modules.

For each module listed in the configuration, the import class update() method is called.

Returns

True if all updates are applied correctly, False otherwise

Return type

bool

read_package(filename)

Read the package content.

It is normally an armored PGP file with signature. The signed file contains a Tar file.

Content is stored in self.content property.

Parameters

filename (path-like or str or bytes) – path of the file to read.

Returns

True if file is read properly, False otherwise

Return type

bool

pharmaship.core.import_data.check_integrity(tar_file)

Check the files listed in the MANIFEST and their checksum.

Parameters

tar_file (tarfile.Tarfile) – The tar file to check

Returns

True if the content is conform to the MANIFEST.

Return type

bool

pharmaship.core.import_data.check_tarfile(data)

Check that the data input is a valid Tar file.

Parameters

data (bytes) – binary string issued from GPG armor decoding containing a tar file.

Returns

A Tarfile object.

Return type

tarfile.TarFile

pharmaship.core.import_data.extract_manifest(manifest_descriptor)

Extract the MANIFEST information and put it into a list of dict.

Parameters

manifest_descriptor (file-object) – File object containing MANIFEST data. Must be opened in “read binary”.

Returns

List of dictionary (hash, filename).

Return type

list(dict)

pharmaship.core.import_data.load_module(module)

Load import_data submodule if existing.

Parameters

module (str) – parent module for importing import_data.

Returns

The DataImport class of the selected module if any, False otherwise.

Return type

DataImport or bool