Code Reference

The following code reference is extracted from the source code and mainly used for debugging/development. Users of pyaptly can ignore this.

Main

Aptly mirror/snapshot managment automation.

pyaptly.main.main(argv=None)

Define parsers and executes commands.

Parameters:

argv (list) – Arguments usually taken from sys.argv

pyaptly.main.prepare(args)

Set pretend mode, read config and load state.

pyaptly.main.setup_logger(args)

Setup the logger.

Mirror

Create and update mirrors in aptly.

pyaptly.mirror.add_gpg_keys(mirror_config)

Use the gpg to download and add gpg keys needed to create mirrors.

Parameters:

mirror_config (dict) – The configuration toml as dict

pyaptly.mirror.cmd_mirror_create(cfg, mirror_name, mirror_config)

Create a mirror create command to be ordered and executed later.

Parameters:
  • cfg (dict) – The configuration toml as dict

  • mirror_name (str) – Name of the mirror to create

  • mirror_config (dict) – Configuration of the snapshot from the toml file.

pyaptly.mirror.cmd_mirror_update(cfg, mirror_name, mirror_config)

Create a mirror update command to be ordered and executed later.

Parameters:
  • cfg (dict) – pyaptly config

  • mirror_name (str) – Name of the mirror to create

  • mirror_config (dict) – Configuration of the snapshot from the toml file.

pyaptly.mirror.mirror(cfg, args)

Create mirror commands, orders and executes them.

Parameters:
  • cfg (dict) – The configuration toml as dict

  • args (namespace) – The command-line arguments read with argparse

Repo

Create repos in aptly.

pyaptly.repo.repo(cfg, args)

Create repository commands, orders and executes them.

Parameters:
  • cfg (dict) – The configuration toml as dict

  • args (namespace) – The command-line arguments read with argparse

pyaptly.repo.repo_cmd_create(cfg, repo_name, repo_config)

Create a repo create command to be ordered and executed later.

Parameters:
  • cfg (dict) – pyaptly config

  • repo_name (str) – Name of the repo to create

  • repo_config (dict) – Configuration of the repo from the toml file.

Snapshot

Create and update snapshots in aptly.

pyaptly.snapshot.clone_snapshot(origin, destination)

Create a clone snapshot command with dependencies.

To be ordered and executed later.

Parameters:
  • origin (str) – The snapshot to clone

  • destination (str) – The new name of the snapshot

pyaptly.snapshot.cmd_snapshot_create(cfg: dict, snapshot_name: str, snapshot_config: dict, ignore_existing: bool | None = False) list[Command]

Create a snapshot create command to be ordered and executed later.

Parameters:
  • cfg (dict) – pyaptly config

  • snapshot_name (str) – Name of the snapshot to create

  • snapshot_config (dict) – Configuration of the snapshot from the toml file.

  • ignore_existing (dict) – Optional, defaults to False. If set to True, still return a command object even if the requested snapshot already exists

Return type:

command.Command

pyaptly.snapshot.cmd_snapshot_update(cfg: dict, snapshot_name: str, snapshot_config: dict) list[Command]

Create commands to update all rotating snapshots.

Parameters:
  • cfg (dict) – pyaptly config

  • snapshot_name (str) – Name of the snapshot to update/rotate

  • snapshot_config (dict) – Configuration of the snapshot from the toml file.

pyaptly.snapshot.dependents_of_snapshot(snapshot_name)

Yield a flat list of dependents from the current state_reader.state.

Return type:

generator

pyaptly.snapshot.rotate_snapshot(cfg, snapshot_name)

Create a command to rotate a snapshot.

In order to be able to update a current publish.

Parameters:
  • cfg (dict) – pyaptly config

  • snapshot_name (str) – the snapshot to rotate

pyaptly.snapshot.snapshot(cfg, args)

Create snapshot commands, orders and executes them.

Parameters:
  • cfg (dict) – The configuration toml as dict

  • args (namespace) – The command-line arguments read with argparse

pyaptly.snapshot.snapshot_spec_to_name(cfg, snapshot)

Convert a given snapshot short spec to a name.

A short spec is a value that may either be a string or a dict.

If it’s a string, everything is fine and we just use that as a snapshot name.

However if it’s a dict, we assume it has the following keys:

  • name: template for the snapshot

  • timestamp: information on how to generate the timestamp.

For further information regarding the timestamp’s data structure, consult the documentation of expand_timestamped_name().

Parameters:
  • cfg (dict) – Complete yaml config

  • snapshot (dict) – Config of the snapshot

Publish

Publish snapshots in aptly.

pyaptly.publish.publish(cfg, args)

Create publish commands, orders and executes them.

Parameters:
  • cfg (dict) – The configuration toml as dict

  • args (namespace) – The command-line arguments read with argparse

pyaptly.publish.publish_cmd_create(cfg, publish_name, publish_config, ignore_existing=False)

Create a publish command with its dependencies.

To be ordered and executed later.

Parameters:
  • cfg (dict) – pyaptly config

  • publish_name (str) – Name of the publish to create

  • publish_config (dict) – Configuration of the publish from the toml file.

pyaptly.publish.publish_cmd_update(cfg, publish_name, publish_config, ignore_existing=False)

Create a publish command with its dependencies.

To be ordered and executed later.

Parameters:
  • cfg (dict) – pyaptly config

  • publish_name (str) – Name of the publish to update

  • publish_config (dict) – Configuration of the publish from the toml file.

State Reader

The state reader helps to find the delta between current and target state.

class pyaptly.state_reader.SystemStateReader

Reads the state from aptly and gpg.

To find out what operations have to be performed to reach the state defined in the toml config-file. Functions are cached and execution commands clear the cache of functions which need to be rerun

gpg_keys()

Read all trusted keys in gp and cache in lru_cache.

has_dependency(dependency)

Check system state dependencies.

Parameters:

dependency (list) – The dependency to check

mirrors()

Read all available mirror and cache in lru_cache.

publish_map()

Create a publish map. publish -> snapshots. Cached in the lru_cache.

publishes()

Read all available publishes and cache in lru_cache

read_aptly_list(type_)

Read lists from aptly.

Parameters:
  • type (str) – The type of list to read ie. snapshot

  • list – Read into this list

  • list – list

repos()

Read all available repo and cache in lru_cache.

snapshot_map()

Create a snapshot map. snapshot -> snapshots. This is also called merge-tree. Cached in the lru_cache.

snapshots()

Read all available snapshot and cache in lru_cache.

Util

Basic function like running processes and logging.

exception pyaptly.util.PyaptlyCliError
pyaptly.util.format_run_result(result: CompletedProcess, returncode: int, tb: str)

Format a CompletedProcess result log.

pyaptly.util.get_default_keyserver()

Get default keyseerver.

pyaptly.util.indent_out(output: bytes | str) str

Indent command output for nicer logging-messages.

It will convert bytes to strings if need or display the result as bytes if decoding fails.

pyaptly.util.parse_aptly_show_command(show: str) dict[str, str]

Parse an aptly show command.

pyaptly.util.run_command(cmd_args: Sequence[str | Path], *, decode: bool = True, hide_error: bool = False, **kwargs)

Instrumented subprocess.run for easier debugging.

  • By default this run command will add encoding=”UTF-8” to kwargs. Disable with decode=False.

  • Command that often or normally fail can also set hide_error=True to only show them in if the loglevel is INFO (Logging and output in DEVELOPMENT.md)

pyaptly.util.unit_or_list_to_list(thingy)

Ensure that a toml entry is always a list.

Used to allow lists and single units in the toml file.

Parameters:

thingy (list, tuple or other) – The data to ensure it is a list