stratified_packager.processing.bundling

Auxiliary file bundling: data/ payloads and resources/ style assets (SPEC §14).

Runs on the algorithm thread during Phase A. Whole-export local file-based raster, mesh and point-cloud layers contribute their source file plus sidecars (or the whole directory for directory-based sources) under data/<table name>/; files referenced by included layers’ symbology land under resources/ — keeping their project-relative subtree, or resources/_ext/<hash8>_<name> for files outside the project home. Paths inside QGIS-builtin resource locations are never bundled (they resolve on any install).

Module Attributes

DATA_PREFIX

Zip-root directory of layer payloads (SPEC §10).

RESOURCES_PREFIX

Zip-root directory of style assets (SPEC §10).

Functions

container_sharers(layer, project)

Name the other project layers backed by the same container file (SPEC §14 caveat).

data_payload_members(layer, table, feedback)

Collect one whole-export layer's data/ zip members (SPEC §14).

local_source_path(layer)

Return the layer's local source path, when its provider exposes one.

payload_source_arcname(layer, table)

Return the zip-internal path an embedded project re-points this payload layer at (§13).

rewrite_asset_paths(document, mapping, to_root)

Rewrite bundled asset paths inside a QML (or project XML) document (SPEC §14).

style_asset_mapping(layers, project_home, ...)

Map every bundleable style-asset path to its resources/ arcname (SPEC §14).

class stratified_packager.processing.bundling._SymbolPathCollector[source]

Collects file paths referenced by a layer’s style entities (SPEC §14).

__init__()[source]

Initialize with an empty path set.

_harvest_text_format(owner)[source]

Harvest the background SVG of a text format (or of label settings).

Parameters:

owner (object) – A QgsTextFormat or QgsPalLayerSettings-like object.

Return type:

None

_walk_symbol(symbol)[source]

Recurse through a symbol’s layers (and sub-symbols), harvesting paths.

Parameters:

symbol (QgsSymbol) – The symbol to walk.

Return type:

None

visit(entity)[source]

Visit one style entity, harvesting symbol-layer file paths.

Parameters:

entity (StyleLeaf) – The visited style leaf.

Return type:

bool

Returns:

True to continue visiting.

paths: set[str]
stratified_packager.processing.bundling.container_sharers(layer, project)[source]

Name the other project layers backed by the same container file (SPEC §14 caveat).

Copying a container (e.g. a GeoPackage) under data/ drags every layer it holds; the caller warns when this list is non-empty.

Parameters:
  • layer (QgsMapLayer) – The whole-export layer about to be copied.

  • project (QgsProject) – The project to scan.

Return type:

list[str]

Returns:

Names of other layers sharing the source file, sorted.

stratified_packager.processing.bundling.data_payload_members(layer, table, feedback)[source]

Collect one whole-export layer’s data/ zip members (SPEC §14).

File sources contribute the file plus its sidecars (sidecarFilesForPath()); directory-based sources (e.g. ESRI grid) are copied whole.

Parameters:
  • layer (QgsMapLayer) – The raster/mesh/point-cloud layer.

  • table (str) – The layer’s table name (the data/<table>/ subdirectory).

  • feedback (QgsProcessingFeedback) – Execution feedback channel.

Return type:

list[tuple[Path, str]]

Returns:

(source file, arcname) pairs; empty when the source is not a local file (such layers ride only in the embedded project).

stratified_packager.processing.bundling.local_source_path(layer)[source]

Return the layer’s local source path, when its provider exposes one.

Also the payload-classification test: a raster/mesh/point-cloud layer is a data/ payload (SPEC §14) iff this returns a path.

Parameters:

layer (QgsMapLayer) – Any map layer.

Return type:

Path | None

Returns:

The decoded path component, or None for non-file sources.

stratified_packager.processing.bundling.payload_source_arcname(layer, table)[source]

Return the zip-internal path an embedded project re-points this payload layer at (§13).

For a plain file source this is the copied main file’s arcname; for a directory-based source (e.g. an ESRI grid) it is the copied directory — never one of the files inside it, which GDAL may not open as the dataset.

Parameters:
  • layer (QgsMapLayer) – The raster/mesh/point-cloud layer.

  • table (str) – The layer’s table name (the data/<table>/ subdirectory).

Return type:

str

Returns:

The data/<table>/<source name> arcname, or empty for non-file sources.

stratified_packager.processing.bundling.rewrite_asset_paths(document, mapping, to_root)[source]

Rewrite bundled asset paths inside a QML (or project XML) document (SPEC §14).

Each original path is replaced by its bundled location, made relative to the document’s directory inside the zip via to_root (empty at the zip root, ../ per directory level below it). Both the original spelling and its slash-normalized variant are replaced.

Parameters:
  • document (str) – The QML/XML text.

  • mapping (Mapping[str, str]) – original path -> arcname from style_asset_mapping().

  • to_root (str) – Prefix walking from the document’s directory up to the zip root.

Return type:

str

Returns:

The rewritten document.

stratified_packager.processing.bundling.style_asset_mapping(layers, project_home, feedback)[source]

Map every bundleable style-asset path to its resources/ arcname (SPEC §14).

Files under the project home keep their project-relative subtree; foreign files land in resources/_ext/<hash8>_<name> (hash of the absolute source path). Paths under the QGIS-builtin resource locations (svgPaths() and the application prefix) are skipped.

Parameters:
Return type:

dict[str, str]

Returns:

original path -> arcname for every existing, non-builtin asset.

stratified_packager.processing.bundling.DATA_PREFIX: Final = 'data'

Zip-root directory of layer payloads (SPEC §10).

stratified_packager.processing.bundling.RESOURCES_PREFIX: Final = 'resources'

Zip-root directory of style assets (SPEC §10).

stratified_packager.processing.bundling._PATH_ACCESSORS: Final[tuple[str, ...]] = ('path', 'imageFilePath', 'svgFilePath')

File-path accessors across the file-referencing symbol-layer classes (SPEC §14).