pharmaship.inventory.export

Export methods for Inventory application.

pharmaship.inventory.export.create_archive(allowance, file_obj)

Create an archive from the given Allowance instance.

The response is a tar.gz file containing YAML files generated by the function serialize_allowance.

Pictures are added if any.

The package description file (package.yaml) and the MANIFEST file are created at the end.

Parameters
Returns

True if success

Return type

bool

pharmaship.inventory.export.create_manifest(items)

Create the data to write into the MANIFEST file.

Parameters

items (list(tuple)) – list of files with their hash.

Returns

Formatted string

Return type

str

pharmaship.inventory.export.create_package_yaml(allowance)

Export package info in YAML string.

Parameters

allowance (pharmaship.inventory.models.Allowance) – Allowance instance to export

Returns

YAML string containing Allowance data.

Return type

str

pharmaship.inventory.export.create_tarinfo(name, content)

Return a the TarInfo for a virtual file.

Parameters
  • name (str) – Name of the file

  • content (bytes or str) – Content of the file to add to the tar file.

Returns

tarfile.TarInfo and io.BytesIO instance of the file content.

Return type

tuple

pharmaship.inventory.export.get_hash(name, content=None, filename=None)

Return sha256 hash and filename for MANIFEST file.

Parameters
  • name (str) – Name of the file to hash.

  • content (bytes or str) – Content of the file to hash.

  • filename (str) – Path to the file to hash.

Returns

Name and file hash in hexadecimal string.

Return type

tuple(str, str)

pharmaship.inventory.export.get_pictures(equipment_list)

Return a list of picture paths to include in the archive.

Parameters

equipment_list (django.db.models.query.QuerySet) – List of equipment for serialized allowance.

Returns

List of pictures filenames.

Return type

list

pharmaship.inventory.export.serialize_allowance(allowance, content_types)

Export an allowance using the YAML format.

To have an usable export, the user needs:

And related to this instance:

This function grabs all these together in a list of tuples:

[('filename.yaml', <yaml content string>)]

In addition, it returns the Equipment list for getting pictures if any.

Parameters

allowance (pharmaship.inventory.models.Allowance) – Allowance to serialize.

Returns

List of tuples filenames and streams

Return type

tuple(list(tuple(str, str)), django.db.models.query.QuerySet)