autowisp.tests.update_hdf5_contents module

Class Inheritance Diagram

Inheritance diagram of ArgumentParser, Path, UpdateSpec

Bring HDF5 files in one directory closer to matching files in another.

Usage:

python update_hdf5_contents.py source_dir dest_dir spec_file [options]

The spec file lists items to apply, one per line. Each line starts with + to copy from source to destination or - to delete from destination:

# comments and blank lines are ignored + dataset /Group/Subgroup/DatasetName - dataset /Group/StaleDataset + attribute /Group/Subgroup AttributeName - attribute /Group/Subgroup StaleAttribute

The - form only touches the destination; source_dir is not consulted. Operations are applied in spec-file order, so a - followed by a + for the same path replaces it cleanly even with --on-conflict=error.

Path and attribute-name tokens are interpreted as Python re regular expressions, anchored end-to-end (i.e. matched with re.fullmatch()). For + operations the regexes are resolved against the source file; for - operations they are resolved against the destination file. A line that matches zero items is treated like a missing source / destination (governed by --missing-source / --missing-dest). Note that HDF5 paths starting with a literal . will be matched by the regex metacharacter .; escape special characters with \ if a strict literal match is required.

class autowisp.tests.update_hdf5_contents.UpdateSpec[source]

Bases: object

Inheritance diagram of autowisp.tests.update_hdf5_contents.UpdateSpec

Parsed ordered list of HDF5 operations (copy and/or delete).

__init__()[source]

Create an empty spec with no operations.

classmethod from_file(spec_path)[source]

Parse spec_path and return the populated UpdateSpec.

Each non-blank, non-comment line must be either <action> dataset <hdf5_path> or <action> attribute <hdf5_path> <attr_name>, where <action> is + (copy from source) or - (delete from destination). Raises ValueError on malformed lines.

autowisp.tests.update_hdf5_contents._all_dataset_paths(h5_root)[source]

Return every dataset path in h5_root (absolute, /...).

autowisp.tests.update_hdf5_contents._all_object_paths(h5_root)[source]

Return every object path in h5_root (groups + datasets) and /.

autowisp.tests.update_hdf5_contents._apply_operations(spec, src, dst, args)[source]

Apply every operation in spec to the (src, dst) pair.

The path / attribute-name tokens in each op are treated as Python regular expressions and resolved against src for + ops and dst for - ops. If a regex matches zero items, --missing-source / --missing-dest controls whether that is an error or a warning.

autowisp.tests.update_hdf5_contents._copy_attribute(src, dst, obj_path, attr_name, *, on_conflict='error', missing_source='error', dry_run=False)[source]

Copy an attribute attr_name on obj_path from src to dst.

Semantics for on_conflict, missing_source, and dry_run match _copy_dataset(). The destination object is created as a group if it does not yet exist.

autowisp.tests.update_hdf5_contents._copy_dataset(src, dst, dataset_path, *, on_conflict='error', missing_source='error', dry_run=False)[source]

Copy a single dataset from src to dst.

on_conflict ('skip'/'overwrite'/'error') controls behavior when dataset_path already exists in dst; missing_source ('skip'/'error') controls behavior when it is absent from src. If dry_run is true, log the intended action without modifying dst. Missing parent groups in the destination are created on demand.

autowisp.tests.update_hdf5_contents._delete_attribute(dst, obj_path, attr_name, *, missing_dest='skip', dry_run=False)[source]

Delete attribute attr_name on obj_path in dst.

Semantics for missing_dest and dry_run match _delete_dataset().

autowisp.tests.update_hdf5_contents._delete_dataset(dst, dataset_path, *, missing_dest='skip', dry_run=False)[source]

Delete dataset_path from dst.

missing_dest ('skip'/'error') controls behavior when the dataset is absent. If dry_run is true, log the intended action without modifying dst.

autowisp.tests.update_hdf5_contents._report_empty_match(label, missing_policy)[source]

Raise or warn that a regex matched zero items, per missing_policy.

autowisp.tests.update_hdf5_contents._resolve_attribute_targets(h5_root, obj_pattern, attr_pattern)[source]

Return (obj_path, attr_name) pairs in h5_root matching regexes.

Both patterns are matched with re.fullmatch().

autowisp.tests.update_hdf5_contents._resolve_dataset_paths(h5_root, pattern)[source]

Return (dataset_path,) tuples in h5_root matching the regex.

Tuples (rather than bare strings) are returned so callers can unpack the result uniformly with the (obj_path, attr_name) pairs returned by _resolve_attribute_targets(). Matching uses re.fullmatch().

autowisp.tests.update_hdf5_contents.main()[source]

Entry point: apply the spec-listed operations to matching HDF5 files.

Pairs files in source_dir with same-named files in dest_dir (via --pattern), then applies every operation in the spec – in file order – to each pair. + lines copy from source to destination; - lines delete from destination only. Errors are collected and reported at the end; the process exits non-zero if any pair failed.

autowisp.tests.update_hdf5_contents.parse_args()[source]

Return the parsed command-line arguments for the update tool.