repoman.config_io#
Save and load .repoman state files (pure JSON, no GTK, fully unit-testable).
File format v2: JSON with version (2), saved_at, saved_codename, and a repos list. Each repo entry captures enough to reconstruct it and adapt suites for a different Ubuntu release. GPG key file bytes are embedded as base64 so the file is fully self-contained for cross-machine migration.
Version 1 files (no saved_codename, no signed_by_content_b64) are accepted; the cross-machine adaptation flow is skipped when saved_codename is absent.
- save_config(repos, current_codename='')[source]#
Serialise repo list to a JSON string for writing to a .repoman file.
- Parameters:
repos (list[Repository]) – Repositories to serialise.
current_codename (str) – Running Ubuntu codename (e.g.
'noble'). Stored in the file so cross-machine restores can adapt suites automatically.
- Return type:
- load_config(path)[source]#
Parse a .repoman JSON file and return repo entries plus the saved codename.
- Parameters:
path (Path) – Path to the .repoman file to read.
- Returns:
(repos, saved_codename)wheresaved_codenameisNonefor v1 files.- Raises:
json.JSONDecodeError – File is not valid JSON.
ValueError –
versionfield is missing or not 1 or 2.KeyError – Required top-level key is absent.
- Return type:
- classify_restore_entry(entry, saved_codename, current_codename, all_known, agnostic_names=None)[source]#
Classify what action to take for a saved entry during cross-machine restore.
- Parameters:
entry (dict) – A raw repo dict from a loaded .repoman file.
saved_codename (str) – Codename the file was saved on.
current_codename (str) – Codename of the current machine.
all_known (list[str]) – All Ubuntu codenames in release-date order (oldest first).
agnostic_names (frozenset[str] | None) – Suite names treated as version-agnostic. Defaults to built-ins.
- Returns:
"restore_as_is"— write unchanged;"update_suite"— swap suite tocurrent_codename;"add_disabled"— write withenabled=False; or"ppa_check"— need a network check before deciding.- Return type:
Literal[‘restore_as_is’, ‘update_suite’, ‘add_disabled’, ‘ppa_check’]
- match_repos(saved, live)[source]#
Match saved config entries to live repos by primary URI.
- Parameters:
saved (list[dict]) – List of raw repo dicts from a loaded .repoman file.
live (list[Repository]) – Currently loaded repositories from the system.
- Returns:
A 2-tuple of
(matched, missing), wherematchedis a list of(saved_entry, live_repo)pairs for repos found on the system, andmissingis a list of saved entries whose URI was not found.- Return type:
- entry_to_repository(entry)[source]#
Reconstruct a Repository from a saved config entry.
Used when creating repos that exist in the config but not on the system. Always produces DEB822 format; source_file is taken from the saved entry. .list paths are normalised to .sources so the parser picks them up correctly.
- Parameters:
entry (dict)
- Return type: