onyo.lib.command_utils module

onyo.lib.command_utils.allowed_config_args(git_config_args)[source]

Check a list of arguments for disallowed git config flags.

git-config stores configuration information in a variety of locations using location flags (e.g. --system). Onyo uses --file to write to onyo.lib.consts.ONYO_CONFIG.

This function makes sure that such flags (and --help) aren’t in the list.

A helper for py:func:onyo.lib.commands.onyo_config.

Parameters:

git_config_args (list[str]) – List of arguments to pass to git config.

Raises:

ValueError – A disallowed flag is detected.

Return type:

bool

onyo.lib.command_utils.iamyourfather(inventory, yaml_stream, base=None)[source]
Return type:

list[Item]

onyo.lib.command_utils.inline_path_diff(source, destination)[source]

Generate an inline diff of two paths.

A rename (i.e. changing the last element) is its own action, and does not group with other changes. A move groups with adjacent changes when possible (e.g. a/b/c/d/one -> a/b/two: “a/{b/c/d -> b}/{one -> two}”).

Parameters:
  • source (str | Path) – Path of source.

  • destination (str | Path) – Path of destination.

Return type:

str

onyo.lib.command_utils.intersect_index(seq1, seq2)[source]

Get the indexes of the first matching value of two sequences.

Returns None as the indexes if no match is found.

Parameters:
Return type:

Tuple[int | None, int | None]

onyo.lib.command_utils.inventory_path_to_yaml(inventory, path, recursive=False, base=None)[source]

Generate Onyo-YAML records of an inventory Path.

Parameters:
  • inventory (Inventory) – The inventory to operate on.

  • path (Path) – Path to generate YAML of.

  • recursive (bool (default: False)) – Descend recursively under path.

  • base (Path | None (default: None)) – Absolute path that onyo.path.parent keys are relative to.

Return type:

str

onyo.lib.command_utils.natural_sort(items, keys)[source]

Sort items according to a list of keys.

Parameters:
  • items (list[Item]) – Items to sort.

  • keys (dict[str, Literal['ascending', 'descending']]) – Keys to sort items by.

  • reverse – Sort in reverse order.

Return type:

list[Item]

onyo.lib.command_utils.print_diff(diffable)[source]

Print colorized diffs.

The lines resulting from the object’s diff() are colorized, with red or green corresponding to whether lines are removed or added.

Parameters:

diffable (Inventory | InventoryOperation) – The object to print the diff of.

Return type:

None