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: Exception

The catalog can’t be written to with what was given: nothing can be published.

class dicogis.publishing.geonetwork.GeonetworkCredentials(username, password)

Bases: object

Account on a GeoNetwork instance. Its profile must be at least Editor.

__init__(username, password)
password: str
username: str
class dicogis.publishing.geonetwork.GeonetworkSession(http_client, url_base, portal='srv', credentials=None, timeout=None)

Bases: object

Authenticated 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:
api_url(route)

Build the URL of an API route.

Parameters:

route (str) – path of the route, from the API root

Return type:

str

Returns:

full URL

cookies: dict[str, str]
open()

Check the account and retrieve the CSRF token.

Raises:
Return type:

None

request(method, route, *, params=None, headers=None, data=None)

Send an authenticated request.

Parameters:
Raises:

HttpTransportError – if no response was received

Return type:

HttpResponse

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:

str

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 stored

  • url_base (str) – URL of the instance, e.g. https://catalogue.example/geonetwork

  • group (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 instance

  • categories (Sequence[str]) – identifiers of the categories of the records

  • update_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:
Return type:

PublishReport

Returns:

counters and per-file error messages for the run