directory.cli
Imports directories scraped by ogi-scraper into onegov directories.
Attributes
Classes
A minimal upload object for a directory file field. |
Functions
|
Turn a record's file-field value into an upload, or '' if there is none. |
|
Imports a directory from a self-describing ogi-scraper JSON export. |
Module Contents
- class directory.cli._FileUpload(file: BinaryIO, filename: str)[source]
A minimal upload object for a directory file field.
DirectoryCollection.updatehandles afileinputfield by reading.file(a binary stream) and.filenameoff the submitted value and building the stored file itself (sniffing the content type from the bytes). This stands in for the web form’sFieldStorageso the CLI can attach a file straight from disk.
- 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.pdforimages/abc.jpg). A missing value, a URL (not a local file) or a path that does not exist yields'', whichupdatetreats 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