archivant package

class archivant.Archivant(conf={})[source]

Implementation of a Data Access Layer

Archivant handles both an fsdb instance and a libreantdb one and exposes an high-level API to operate on ‘volumes’.

A ‘volume’ represents a physical/digital object stored within archivant. Volumes are structured as described in normalize_volume(); shortly, they have language, metadata and attachments. An attachment is an URL plus some metadata.

If you won’t configure the FSDB_PATH parameter, fsdb will not be initialized and archivant will start in metadata-only mode. In metdata-only mode all file related functions will raise FileOpNotSupported.

dangling_files()[source]

iterate over fsdb files no more attached to any volume

delete_attachments(volumeID, attachmentsID)[source]

delete attachments from a volume

delete_volume(volumeID)[source]
static denormalize_attachment(attachment)[source]

convert attachment metadata from archivant to es format

static denormalize_volume(volume)[source]

convert volume metadata from archivant to es format

get_all_volumes()[source]

iterate over all stored volumes

get_attachment(volumeID, attachmentID)[source]
get_file(volumeID, attachmentID)[source]
get_volume(volumeID)[source]
insert_attachments(volumeID, attachments)[source]

add attachments to an already existing volume

insert_volume(metadata, attachments=[])[source]

Insert a new volume

Returns the ID of the added volume

metadata must be a dict containg metadata of the volume:

{
  "_language" : "it",  # language of the metadata
  "key1" : "value1",   # attribute
  "key2" : "value2",
  ...
  "keyN" : "valueN"
}

The only required key is `_language`

attachments must be an array of dict:

{
  "file"  : "/prova/una/path/a/caso" # path or fp
  "name"  : "nome_buffo.ext"         # name of the file (extension included) [optional if a path was given]
  "mime"  : "application/json"       # mime type of the file [optional]
  "notes" : "this file is awesome"   # notes that will be attached to this file [optional]
}
is_file_op_supported()[source]
static normalize_attachment(attachment)[source]

Convert attachment metadata from es to archivant format

This function makes side effect on input attachment

static normalize_volume(volume)[source]

convert volume metadata from es to archivant format

This function makes side effect on input volume

output example:

{
    'id': 'AU0paPZOMZchuDv1iDv8',
    'type': 'volume',
    'metadata': {'_language': 'en',
                'key1': 'value1',
                'key2': 'value2',
                'key3': 'value3'},
    'attachments': [{'id': 'a910e1kjdo2d192d1dko1p2kd1209d',
                    'type' : 'attachment',
                    'url': 'fsdb:///624bffa8a6f90813b7982d0e5b4c1475ebec40e3',
                    'metadata': {'download_count': 0,
                                'mime': 'application/json',
                                'name': 'tmp9fyat_',
                                'notes': 'this file is awsome',
                                'sha1': '624bffa8a6f90813b7982d0e5b4c1475ebec40e3',
                                'size': 10}
                }]
}
shrink_local_fsdb(dangling=True, corrupted=True, dryrun=False)[source]

shrink local fsdb by removing dangling and/or corrupted files

return number of deleted files

update_attachment(volumeID, attachmentID, metadata)[source]

update an existing attachment

the given metadata dict will be merged with the old one. only the following fields could be updated: [name, mime, notes, download_count]

update_volume(volumeID, metadata)[source]

update existing volume metadata the given metadata will substitute the old one

Submodules

class archivant.archivant.Archivant(conf={})[source]

Implementation of a Data Access Layer

Archivant handles both an fsdb instance and a libreantdb one and exposes an high-level API to operate on ‘volumes’.

A ‘volume’ represents a physical/digital object stored within archivant. Volumes are structured as described in normalize_volume(); shortly, they have language, metadata and attachments. An attachment is an URL plus some metadata.

If you won’t configure the FSDB_PATH parameter, fsdb will not be initialized and archivant will start in metadata-only mode. In metdata-only mode all file related functions will raise FileOpNotSupported.

dangling_files()[source]

iterate over fsdb files no more attached to any volume

delete_attachments(volumeID, attachmentsID)[source]

delete attachments from a volume

delete_volume(volumeID)[source]
static denormalize_attachment(attachment)[source]

convert attachment metadata from archivant to es format

static denormalize_volume(volume)[source]

convert volume metadata from archivant to es format

get_all_volumes()[source]

iterate over all stored volumes

get_attachment(volumeID, attachmentID)[source]
get_file(volumeID, attachmentID)[source]
get_volume(volumeID)[source]
insert_attachments(volumeID, attachments)[source]

add attachments to an already existing volume

insert_volume(metadata, attachments=[])[source]

Insert a new volume

Returns the ID of the added volume

metadata must be a dict containg metadata of the volume:

{
  "_language" : "it",  # language of the metadata
  "key1" : "value1",   # attribute
  "key2" : "value2",
  ...
  "keyN" : "valueN"
}

The only required key is `_language`

attachments must be an array of dict:

{
  "file"  : "/prova/una/path/a/caso" # path or fp
  "name"  : "nome_buffo.ext"         # name of the file (extension included) [optional if a path was given]
  "mime"  : "application/json"       # mime type of the file [optional]
  "notes" : "this file is awesome"   # notes that will be attached to this file [optional]
}
is_file_op_supported()[source]
static normalize_attachment(attachment)[source]

Convert attachment metadata from es to archivant format

This function makes side effect on input attachment

static normalize_volume(volume)[source]

convert volume metadata from es to archivant format

This function makes side effect on input volume

output example:

{
    'id': 'AU0paPZOMZchuDv1iDv8',
    'type': 'volume',
    'metadata': {'_language': 'en',
                'key1': 'value1',
                'key2': 'value2',
                'key3': 'value3'},
    'attachments': [{'id': 'a910e1kjdo2d192d1dko1p2kd1209d',
                    'type' : 'attachment',
                    'url': 'fsdb:///624bffa8a6f90813b7982d0e5b4c1475ebec40e3',
                    'metadata': {'download_count': 0,
                                'mime': 'application/json',
                                'name': 'tmp9fyat_',
                                'notes': 'this file is awsome',
                                'sha1': '624bffa8a6f90813b7982d0e5b4c1475ebec40e3',
                                'size': 10}
                }]
}
shrink_local_fsdb(dangling=True, corrupted=True, dryrun=False)[source]

shrink local fsdb by removing dangling and/or corrupted files

return number of deleted files

update_attachment(volumeID, attachmentID, metadata)[source]

update an existing attachment

the given metadata dict will be merged with the old one. only the following fields could be updated: [name, mime, notes, download_count]

update_volume(volumeID, metadata)[source]

update existing volume metadata the given metadata will substitute the old one

exception archivant.exceptions.FileOpNotSupported[source]

Bases: exceptions.Exception

exception archivant.exceptions.NotFoundException[source]

Bases: exceptions.Exception