Pacifica Uploader
Project description
Pacifica Python Uploader
Pacifica Python Uploader, PacificaUploader
, is a Python programming language
library for managing, serializing and transporting (over a network) archives of
files (referred to as "bundles"), managing both the data and the metadata of the
bundle, and interacting with
Pacifica Ingest and
Pacifica Policy servers.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
API reference
This section gives an overview of the modules, classes and methods that are
exported by the Pacifica Python Uploader library: PacificaUploader
.
uploader.metadata
module
The uploader.metadata
module exports classes and methods for manipulating and
serializing the metadata for bundles of files.
Encoding and decoding to the JSON data format is supported for compatible
objects (see uploader.metadata.Json
module for more information).
uploader.metadata.MetaData(list)
class
Instances of the uploader.metadata.MetaData
class are upper-level objects that
provide the metadata for interacting with the designated
Pacifica Ingest server.
The uploader.metadata.MetaData
class is a sub-class of list
that implements
the index protocol (__getitem__
, __setitem__
and __delitem__
) as a proxy
to the indices of the value of the metaID
field of the associated instance of
the uploader.metadata.MetaObj
class.
uploader.metadata.MetaObj(collections.namedtuple)
class
Instances of the uploader.metadata.MetaObj
class represent units of metadata
whose representation is disjoint to a file, i.e., units of metadata that are
describe but are not stored as part of a file.
The uploader.metadata.MetaObj
class is a sub-class of the
collections.namedtuple
class with the following named fields:
sourceTable
destinationTable
metaID
displayType
displayTitle
queryDependency
valueField
queryFields
displayFormat
key
value
directoryOrder
query_results
uploader.metadata.FileObj(collections.namedtuple)
class
Instances of the uploader.metadata.FileObj
class represent individual files,
including both the data and metadata for the file. During a file upload,
instances of the uploader.metadata.FileObj
class are automatically associated
with new instances of the uploader.metadata.MetaData
class.
The uploader.metadata.FileObj
class is a sub-class of the
collections.namedtuple
class with the following named fields:
destinationTable
name
subdir
size
hashtype
hashsum
mimetype
ctime
mtime
The above named fields are identical to those of the metadata.orm.Files
class,
provided by the
Pacifica Metadata library.
uploader.metadata.metadata_decode(json_str)
method
The uploader.metadata.metadata_decode()
method deserializes the given
JSON source, json_str
, and then returns a new instance of the
uploader.metadata.MetaData
class.
The new instance is automatically associated with new instances of the
uploader.metadata.MetaObj
and uploader.metadata.FileObj
classes.
uploader.metadata.metadata_encode(md_obj)
method
The uploader.metadata.metadata_encode()
method encodes the given
instance of the uploader.metadata.MetaData
class, md_obj
, as a JSON object,
and then returns its JSON serialization.
Associated instances of the uploader.metadata.MetaObj
and
uploader.metadata.FileObj
classes are automatically included in the JSON
object and the resulting JSON serialization.
uploader.metadata.Json
module
The uploader.metadata.Json
module exports generators for encoding and decoding
instances of the collections.namedtuple
class using the JSON data format.
The uploader.metadata.Json.generate_namedtuple_encoder()
and
uploader.metadata.Json.generate_namedtuple_decoder()
methods return
sub-classes of the given super-class, which delegate to instances of the
json.JSONEncoder
and json.JSONDecoder
classes, respectively.
uploader.metadata.PolicyQuery
module
The uploader.metadata.PolicyQuery
module exports classes and methods for
interacting with the designated
Pacifica Policy server.
uploader.metadata.PolicyQuery.PolicyQuery(uploader.common.CommonBase)
class
Instances of the uploader.metadata.PolicyQuery.PolicyQuery
class represent
queries to the designated
Pacifica Policy server.
The HTTP end-point for the designated
Pacifica Policy server is
automatically pulled either from the system environment or from the keyword
arguments, **kwargs
, for the
uploader.metadata.PolicyQuery.PolicyQuery(user, *args, **kwargs)
constructor.
The uploader.metadata.PolicyQuery.PolicyQuery.valid_metadata(md_obj)
method
validates the given instance of the uploader.metadata.MetaData
class,
md_obj
, with respect to the capabilities of the designated
Pacifica Policy server.
The uploader.metadata.PolicyQuery.PolicyQuery.get_results()
method returns a
JSON object that represents the result set for a query to the designated
Pacifica Policy server, i.e., the
entities that match the criteria that is represented by the associated instance
of the uploader.metadata.PolicyQuery.PolicyQueryData
class.
The success or failure of the query to the designated Pacifica Policy server is indicated by the HTTP status code of the query response.
uploader.metadata.PolicyQuery.PolicyQueryData(collections.namedtuple)
class
Instances of the uploader.metadata.PolicyQuery.PolicyQueryData
class represent
the data for the generation of a query to a designated
Pacifica Policy server.
The uploader.metadata.PolicyQuery.PolicyQueryData
class is a sub-class of the
collections.namedtuple
class with the following named fields:
user
columns
from_table
where
uploader.metadata.MetaUpdate
module
The uploader.metadata.MetaUpdate
module exports classes and methods for
constructing and executing the strategy for modifying the values, including the
parents and children, of instances of the uploader.metadata.MetaData
class.
uploader.metadata.MetaUpdate.MetaUpdate(uploader.metadata.MetaData)
class
The uploader.metadata.MetaUpdate.MetaUpdate
class is a sub-class of the
uploader.metadata.MetaData
class that is specialized to issue and handle
queries to Pacifica Policy
servers.
uploader.bundler
module
The uploader.bundler
module exports classes and methods for constructing and
streaming bundles of files to a designated file descriptor. The file descriptor
is opened once, and the stream is generated by a single pass over the specified
files.
uploader.bundler.Bundler(object)
class
The uploader.bundler.Bundler.stream()
method streams a bundle of files to a designated file descriptor. The
uploader.bundler.Bundler
class is created by providing a list
of dict
s
that specifies the arguments to the tarfile.TarFile.gettarinfo()
method.
Note: The
arcname
keyword argument MUST be provided when calling thetarfile.TarFile.gettarinfo()
method.
The uploader.bundler.Bundler.stream()
method is a blocking I/O operation.
An asynchronous callback method MAY be provided via the optional callback
keyword argument. Periodically, the callback method is provided with the current
percentage of completion.
Note: File handles are opened for reading in binary mode.
uploader.Uploader
module
The uploader.Uploader
module exports classes and methods for interacting with
Pacifica Ingest servers.
uploader.Uploader.Uploader(uploader.common.CommonBase)
class
The uploader.Uploader.Uploader
class exports methods that provide an API for
connecting to and handling connections to
Pacifica Ingest servers.
The uploader.Uploader.Uploader.upload()
method takes a file-like object as
input that has been opened for reading in binary mode, and returns a job_id
for the upload.
The uploader.Uploader.Uploader.getstate()
method takes a job_id
as input,
and returns a JSON object, as defined by the
Pacifica Ingest API for
obtaining the status of the current job.
Uploader Expectations and Application Flows
This section describes how an end-user of Pacifica Python Uploader is expected to interact with the modules, classes and methods above, and, by extension, Pacifica Ingest and Pacifica Policy servers.
Uploader Program Flow
-
The uploader program MUST construct a new instance of the
uploader.metadata.MetaUpdate
class. The new instance of theuploader.metadata.MetaUpdate
class MAY be associated with zero or more of instances of theuploader.metadata.MetaObj
class. Theuploader.metadata.MetaObj.value
field MAY beNone
. The new instance of theuploader.metadata.MetaUpdate
class MUST NOT be associated with any instances of theuploader.metadata.FileObj
class. -
To determine completeness, the new instance of the
uploader.metadata.MetaUpdate
class SHOULD be validated using theuploader.metadata.MetaData.is_valid()
method (inherited by theuploader.metadata.MetaUpdate
sub-class). Then, the uploader program MUST call theuploader.metadata.PolicyQuery.PolicyQuery.valid_metadata()
method. The new instance of theuploader.metadata.MetaUpdate
class MUST be valid prior to bundling. -
The uploader program MUST dereference the
uploader.metadata.MetaObj.displayType
field to determine the mode of selection for theuploader.metadata.MetaObj.value
field. The value of theuploader.metadata.MetaObj.displayType
field is uploader-program-specific, i.e., the value MUST be defined by the uploader program. -
The uploader program MUST assign a non-
None
value to eachuploader.metadata.MetaData.query_results
field by calling theuploader.metadata.MetaUpdate.query_results()
method. Theuploader.metadata.MetaData.query_results
field is alist
. -
The value of the
uploader.metadata.MetaData.query_results
field MUST be rendered according to the uploader-program-specific definition that is interpreted from the value of theuploader.metadata.MetaObj.displayFormat
field, e.g., in the Python programming language, by calling thestr.format
method or by leveraging a template engine, such as Cheetah or Jinja2. -
The uploader program MAY call the
uploader.metadata.MetaUpdate.query_results()
method for instances of theuploader.metadata.MetaObj
class whosevalue
field is non-None
. -
The uploader program MUST handle all instances
uploader.metadata.MetaUpdate
class, regardless of validity, i.e., the uploader program MUST NOT reject an instance of theuploader.metadata.MetaUpdate
class under any circumstances, e.g., if there are unsatisfied dependencies between instances of theuploader.metadata.MetaData
class. -
When the uploader program is ready for a given
uploader.metadata.MetaObj.value
field to be selected, the uploader program MUST assign to theuploader.metadata.MetaObj.value
field the value of theuploader.metadata.MetaObj.valueField
field, and then call theuploader.metadata.MetaObj.update_parents()
method. The effect of this operation is to update theuploader.metadata.MetaObj.value
fields of associated and dependent instances of theuploader.metadata.MetaObj
class. After modification, the new state of the instance of theuploader.metadata.MetaUpdate.MetaUpdate
class SHOULD be displayed to the end-user, as previously discussed. -
The uploader program MUST verify that
uploader.metadata.MetaUpdate.MetaUpdate.is_valid() == True
. If the instance of theuploader.metadata.MetaUpdate.MetaUpdate
class is not valid, then the uploader program MUST repeat the instructions in the paragraph 8. -
The uploader program MUST call the
uploader.metadata.PolicyQuery.PolicyQueryData.valid_metadata()
method to validate the instance of theuploader.metadata.MetaUpdate.MetaUpdate
class prior to upload. This prevents the uploader program from uploading metadata that is invalid with respect to the policy of the Pacifica Ingest server. -
When the uploader program is ready to bundle the data, the uploader program MUST construct a
list
of objects, representing the fields of the corresponding instance of thetar.TarInfo
class. Each object MUST export afileobj
field whose value implements the file protocol, i.e., exports aread()
method. -
The uploader program MUST construct a new instance of the
metadata.bundler.Bundler
class using the instances of theuploader.metadata.MetaUpdate.MetaUpdate
andtar.TarInfo
classes, as previously stated in paragraph 11. Then, the uploader program MUST construct a file-like object that can be written to in binary mode, and then call theuploader.bundler.Bundler.stream()
method. -
The uploader program MUST construct a new instance of the
metadata.Uploader.Uploader
class. Then, the uploader program MUST construct a file-like object that can be read in binary mode, and then call theuploader.bundler.Bundler.upload()
method. -
Finally, the uploader program MUST verify the result of the ingest by calling the
uploader.Uploader.Uploader.getstate()
method. If an ingest-related error occurs, then the uploader program MAY repeat the ingest operation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pacifica-uploader-0.1.5.tar.gz
.
File metadata
- Download URL: pacifica-uploader-0.1.5.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65a1587e14745e067dbaaba9c928cbf327be449828031d31773007bb9a77343e |
|
MD5 | 60ddeffc5b6bf0ec38dff3865d0be93f |
|
BLAKE2b-256 | e2042f4d480c71fb59c077178a2f86190108fc5d3e2cfefe467fede81a96a946 |
File details
Details for the file pacifica_uploader-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: pacifica_uploader-0.1.5-py3-none-any.whl
- Upload date:
- Size: 31.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d931260f962a4357373ce3a06fe319d1d289866f9c3df410652e4c2662a167e |
|
MD5 | 7308d8807a98a399a56293e86fe2c155 |
|
BLAKE2b-256 | 87ed207e68f882ded1ccfc02607699330ca04b61c8dc7a082e09d0e1e19b91f9 |
File details
Details for the file pacifica_uploader-0.1.5-py2-none-any.whl
.
File metadata
- Download URL: pacifica_uploader-0.1.5-py2-none-any.whl
- Upload date:
- Size: 31.0 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e76cbce32d7748587913088e4d2889b58c64727620113f6a2928e0110fa712f9 |
|
MD5 | d7e1b1a329987c1ff0771d3f33269527 |
|
BLAKE2b-256 | 39e3ca1ddcfa2ce191c822e70587969180684d04530a1e8643e0dcf1a44e75d7 |