dicogis.publishing.geonetwork module¶
Publication of ISO 19139 metadata to a GeoNetwork 4.4 catalog, through its REST API.
UI-agnostic core shared by the dicogis-cli publish command and the GUI’s “Publish” tab: it depends on neither Typer nor Qt.
- exception dicogis.publishing.geonetwork.GeonetworkAuthenticationError¶
Bases:
ExceptionThe catalog can’t be written to with what was given: nothing can be published.
- class dicogis.publishing.geonetwork.GeonetworkCredentials(username, password)¶
Bases:
objectAccount on a GeoNetwork instance. Its profile must be at least Editor.
- __init__(username, password)¶
- class dicogis.publishing.geonetwork.GeonetworkSession(http_client, url_base, portal='srv', credentials=None, timeout=None)¶
Bases:
objectAuthenticated exchanges with a GeoNetwork instance.
GeoNetwork keeps its CSRF token in a cookie: each write must send it back both as this cookie and in the X-XSRF-TOKEN header. Handled here rather than left to the cookie jar of the HTTP clients, which behave differently and may hold the session of something else within QGIS.
- __init__(http_client, url_base, portal='srv', credentials=None, timeout=None)¶
Prepare the session.
- Parameters:
http_client (
HttpClient) – HTTP clienturl_base (
str) – URL of the instance, e.g. https://catalogue.example/geonetworkportal (
str) – portal (sub-catalog) of the instancecredentials (
GeonetworkCredentials|None) – account to log in with. None when the HTTP client handles the authentication itself (authentication configuration of QGIS).
- api_url(route)¶
Build the URL of an API route.
- open()¶
Check the account and retrieve the CSRF token.
- Raises:
GeonetworkAuthenticationError – if the account isn’t logged in, or the instance gives no token
HttpTransportError – if the instance can’t be reached
- Return type:
- request(method, route, *, params=None, headers=None, data=None)¶
Send an authenticated request.
- Parameters:
- Raises:
HttpTransportError – if no response was received
- Return type:
- Returns:
response, whatever its status code
- dicogis.publishing.geonetwork.describe_http_error(error)¶
Tell what went wrong from the response of the catalog, which explains itself.
- Parameters:
error (
HttpStatusError) – error to describe- Return type:
- Returns:
status code and beginning of the response
- dicogis.publishing.geonetwork.publish_metadata_folder(input_folder, url_base, *, group, credentials=None, portal='srv', categories=(), update_mode=GeonetworkUpdateModes.overwrite, publish_to_all=False, reject_if_invalid=False, timeout=None, http_client=None, progress_reporter=None)¶
Publish every ISO 19139 file of a folder to a GeoNetwork 4.4 catalog.
- Parameters:
input_folder (
Path) – folder where the XML files are storedurl_base (
str) – URL of the instance, e.g. https://catalogue.example/geonetworkgroup (
str) – identifier of the group the records are attached to. Mandatory: GeoNetwork 4.4 refuses an insertion without it.credentials (
GeonetworkCredentials|None) – account to log in with. None when the HTTP client handles the authentication itself (authentication configuration of QGIS).portal (
str) – portal (sub-catalog) of the instancecategories (
Sequence[str]) – identifiers of the categories of the recordsupdate_mode (
str) – what to do with a record the catalog already has: overwrite replaces it, complete only fills its empty fields, leaving what was changed by hand in the catalog as is.publish_to_all (
bool) – make the records visible to everyone. Forced to false by GeoNetwork when its workflow is enabled.reject_if_invalid (
bool) – have the catalog refuse the records invalid against its XSD or the Schematron rules it requires (all of them on a fresh GeoNetwork 4.4, DataCite and DCAT-AP HVD included)timeout (
float|None) – seconds to wait for the catalog. Defaults to the DICOGIS_PUBLISH_TIMEOUT environment variable, or 30 seconds.http_client (
HttpClient|None) – HTTP client. Defaults to the one of the running environment.progress_reporter (
ProgressReporter|None) – told about each file examined. Asking it to stop ends the run between two files, with a report of what was done until then.
- Raises:
FileNotFoundError – if input_folder contains no XML file
ValueError – if the URL is missing, the group isn’t an identifier or the update mode is unknown
GeonetworkAuthenticationError – if the account can’t write to the catalog
HttpTransportError – if the catalog can’t be reached
- Return type:
- Returns:
counters and per-file error messages for the run