directory.cli

Imports directories scraped by ogi-scraper into onegov directories.

Attributes

cli

Classes

_FileUpload

A minimal upload object for a directory file field.

Functions

_file_upload(value, base_dir) → _FileUpload | str

Turn a record's file-field value into an upload, or '' if there is none.

import_directory_from_ogi_scraper(file, dry_run, recreate) → collections.abc.Callable[[onegov.core.request.CoreRequest, onegov.core.framework.Framework], None]

Imports a directory from a self-describing ogi-scraper JSON export.

Module Contents

directory.cli.cli[source]
class directory.cli._FileUpload(file: BinaryIO, filename: str)[source]

A minimal upload object for a directory file field.

DirectoryCollection.update handles a fileinput field by reading .file (a binary stream) and .filename off the submitted value and building the stored file itself (sniffing the content type from the bytes). This stands in for the web form’s FieldStorage so the CLI can attach a file straight from disk.

file[source]
filename[source]
data[source]
directory.cli._file_upload(value: object, base_dir: str) → _FileUpload | str[source]

Turn a record’s file-field value into an upload, or ‘’ if there is none.

The value is a path to the file relative to the export JSON (as the scraper writes it, e.g. documents/123.pdf or images/abc.jpg). A missing value, a URL (not a local file) or a path that does not exist yields '', which update treats as “no file”.

directory.cli.import_directory_from_ogi_scraper(file: str, dry_run: bool, recreate: bool) → collections.abc.Callable[[onegov.core.request.CoreRequest, onegov.core.framework.Framework], None][source]

Imports a directory from a self-describing ogi-scraper JSON export.

The file carries both the directory spec and its entries:

{
  "directory": {
    "title": "Vereine",
    "structure": "Name *= ___\\n...",       # onegov formcode
    "configuration": { ... },                # DirectoryConfiguration
    "fields": { "<field_id>": "<record_key>", ... }
  },
  "entries": [ { ...record... }, ... ]
}

The scraper is the source that knows the target shape, so this command needs no per-directory knowledge. The directory is created if missing and entries are matched by name and updated in place, so the import is idempotent.

Example:

onegov-directory –select /onegov_town6/malters \

import-from-ogi-scraper vereinsliste.json