Standards Export Extension#
- class metacatalog.ext.standards_export.StandardsExportExtension#
Extension to export Entries in standard format. ISO 19115 and DataCite metadata standard formats are supported. The exported standard is determined by the jinja template passed to the extension functions as parameter
template_path
.Adds the method standards_export to
Entry
which returns the metadata standard as a Python XML ElementTree representation for theImmutableResultSet
of the Entry. The methodcreate_standards_xml
is added to the API (metacatalog.api.catalog), which is used to export Entries / ImmutableResultSets in the database session and write the XML files to the folder location specified inpath
. Additionally, the commandstandards-export
is added to the metacatalog CLI. The command is used to export one or more Entries via the command line.Changed in version 0.8.3.
Support for DataCite export added.
- classmethod cli_create_standards_xml(args)#
Adds functionality to the metacatalog CLI to export metadata of Entries in standard format as .xml files. Export one or more Entries, which are identified by positional argument entries. Entries can be identified by ID or UUID and are exported in standard format. The metadata standard is specified with argument –format. The produced .xml file is saved to the location specified with argument –path. If no path is given, the .xml file is saved to the current working directory. Use the flag –all to export all entries in the given metacatalog connection. Use the flag –strict to only export well-formed and content validated XML files (defaults to False).
New in version 0.8.2.
Example
With the following command, ISO 19115 XML files for the entries with id=10 and id=20 in the default database session are created under the specified path:
$ python -m metacatalog standards-export 10 20 --format iso19115 --path /path/to/store/xmls --connection default
Notes
The content of the xml files will be created using a
ImmutableResultSet
. This will lazy-load sibling Entries and parent groups as needed for a useful Metadata export.
- create_standards_xml() None #
- create_standards_xml() ElementTree
This function can be imported from metacatalog.api.catalog
Create standard metadata XML file for an entry, which is found by its id or uuid. The XML file is saved to the folder given in
path
. Ifpath
does not end with ‘.xml’, the name of the XML file is generated with the uuid of the used ImmutableResultSet, depending on the exported standard: *f"iso19115_{irs_uuid}.xml"
. *f"datacite_{irs_uuid}.xml
” If nopath
is given, theElementTree
XML representation is returned.New in version 0.8.1.
- Parameters:
session (sqlalchemy.Session) – SQLAlchemy session connected to the database.
id_or_uuid (Union[int, str]) – id or uuid of the Entry to be exported.
config_dict (dict) –
Configuration dictionary, containing information about the data provider. The following keys and their values are expected when rendering the jinja template:
dict( contact = dict( organisationName = '', deliveryPoint = '', city = '', administrativeArea = '', postalCode = '', country = '', electronicMailAddress = ['', ''], linkage = '', linkage_name = '', linkage_description = '' ), publisher = dict( organisation_name = '' ))
path (str) – Location where the .xml file is saved to. If path ends with the name of the XML file (i.e. ends with ‘.xml’), the file is named as given. If path is a folder location, the name of the XML file is auto-generated with the uuid of the ImmutableResultSet of the entry and the exported standard. If no path is given, the class:ElementTree <xml.etree.ElementTree.ElementTree> XML object is returned.
template_path (str) – Full path (including the template name) to the jinja2 template for metadata export. This determines the metadata standard for export. Defaults to ISO 19115 template.
strict –
New in version 0.8.3.
If strict is True, only syntactically (well-formed) and content validated XML files are generated. Note that in this version, DataCite XML files are never valid in terms of content, as metacatalog does currently not provice DOIs for its datasets. In the case of ISO 19115, content is currently not validated and a
NotImplementedError
is raised. Defaults to False.
- Returns:
xml_etree – If no path is given, the
ElementTree
object representing the XML ElementTree in Python is returned. If a path is given, the .xml is created andNone
is returned.- Return type:
Union[ElementTree, None]
Notes
The content of the file is created using a
ImmutableResultSet
. This will lazy-load sibling Entries and parent groups as needed for a useful Metadata export.
- classmethod init_cli(subparsers, defaults)#
Add the parser
standards-export
to the metacatalog CLI and register arguments.
- classmethod standards_export(entry_or_resultset: Union[Entry, ImmutableResultSet], config_dict: dict = {}, template_path: str = '/home/runner/work/metacatalog/metacatalog/metacatalog/ext/standards_export/schemas/iso19115/iso19115-2.j2', strict: bool = False) ElementTree #
Export a
Entry
orImmutableResultSet
to XML. The metadata standard is determined by the jinja2 template passed to this function as paramtertemplate_path
. Always returns anElementTree
object.This function is added as a method to
Entry
when the extension is activated.New in version 0.7.7.
- Parameters:
entry_or_resultset (Union[Entry, ImmutableResultSet]) – The entry instance to be exported
config_dict (dict) –
Configuration dictionary, containing information about the data provider. The following keys and their values are expected when rendering the jinja template:
dict( contact = dict( organisationName = '', deliveryPoint = '', city = '', administrativeArea = '', postalCode = '', country = '', electronicMailAddress = ['', ''], linkage = '', linkage_name = '', linkage_description = '' ), publisher = dict( organisation_name = '' ) )
It is also possible to create a .json file
standards_export_contact.json
containing the contact information and add the path to this file to the metacatalog CONFIGFILE under the top level keyextra
:"extra":{ "standards_export_contact": "/path/to/standards_export_contact.json" }
template_path (str) – Full path (including the template name) to the jinja2 template for metadata export. This determines the metadata standard for export. Defaults to ISO 19115 template.
strict (bool) –
New in version 0.8.3.
If strict is True, only syntactically (well-formed) and content validated XML files are generated. Note that in version
v0.8.3
, DataCite XML files are never valid in terms of content, as metacatalog does currently not provice DOIs for its datasets. In the case of ISO 19115, content is currently not validated and aNotImplementedError
is raised. Defaults to False.
- Returns:
xml_etree – The
ElementTree
object representing the XML ElementTree in Python.- Return type:
xml.etree.ElementTree.ElementTree
Notes
The content of the file is created using a
ImmutableResultSet
. This will lazy-load sibling Entries and parent groups as needed for a useful metadata export.