Python API
passthrough.Template
The Template
class manages the creation of a data product from a type template.
After instantiation, the partial label is available through the label
attribute.
For convenience, the document root
is also exposed, together with its nsmap
(the namespace prefix->uri dictionary of the partial label).
Attributes:
Name | Type | Description |
---|---|---|
label |
lxml.etree._ElementTree |
The partial label represented as an lxml element tree, which allows access to its classes and attributes via the XML DOM. |
root |
lxml.etree._Element |
The partial label's root element (e.g.
|
nsmap |
dict |
The partial label's namespace map |
__init__(self, template, source_map, context_map=None, template_source_entry=True, keep_template_comments=False, skip_structure_check=False, quiet=False)
special
Instantiate a partial label from the provided type template.
Run the provided template
through a series of pre-processing steps resulting
in a partial label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template |
Union[lxml.etree._ElementTree, pds4_tools.reader.general_objects.StructureList, pds4_tools.reader.label_objects.Label, pathlib.Path, str] |
|
required |
source_map |
Dict[str, Union[lxml.etree._ElementTree, pds4_tools.reader.general_objects.StructureList, pds4_tools.reader.label_objects.Label, pathlib.Path, str, Sequence[Union[lxml.etree._ElementTree, pds4_tools.reader.general_objects.StructureList, pds4_tools.reader.label_objects.Label, pathlib.Path, str]]]] |
A dictionary which maps string monikers used by the
|
required |
context_map |
Optional[dict] |
If called for by the template, a dictionary of key-value pairs
which can be looked up using the |
None |
template_source_entry |
bool |
Add a "template"-> |
True |
keep_template_comments |
bool |
If enabled, propagate XML comments from |
False |
skip_structure_check |
bool |
If enabled, share a few milliseconds off the export
process (and some kilobytes of memory) by not sanity-checking the
structure of the partial label to that of the original |
False |
quiet |
int |
If set to True, suppress |
False |
export(self, directory, filename=None)
Export the partial label to the filesystem.
Run the partial label through a series of post-processing steps before exporting
the completed label to filename
in `directory.
If filename
is not provided, the product ID part of the post-processed label's
logical identifier (LID) will be used. Please note that this behaviour is
likely to change in an upcoming release!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory |
Union[pathlib.Path, str] |
Path to the desired output directory. |
required |
filename |
Optional[str] |
Filename override to use for the output label. |
None |