Utils

The utils module contains general utility functions used throughout oduit.

oduit.utils.infer_error_code(error_type: str | None, error: str | None) str | None[source]

Infer a stable machine-facing error code from the payload error fields.

oduit.utils.build_json_payload(payload_type: str, data: dict[str, Any] | None = None, success: bool | None = None, include_null_values: bool = False, *, flatten_data: bool = True, flatten_meta_aliases: bool = True, include_generated_at: bool = True) dict[str, Any][source]

Build a versioned JSON payload envelope.

oduit.utils.output_result_to_json(output: dict[str, Any], additional_fields: dict[str, Any] | None = None, exclude_fields: list[str] | None = None, include_null_values: bool = False, result_type: str = 'result', *, flatten_data: bool = True, flatten_meta_aliases: bool = True, include_generated_at: bool = True) dict[str, Any][source]

Generate JSON output for the operation result

Parameters:
  • additional_fields – Extra fields to include in the output

  • exclude_fields – Fields to exclude from the output

  • include_null_values – Whether to include fields with None values

Returns:

Dictionary suitable for JSON output

oduit.utils.validate_addon_name(addon_name: str) bool[source]

Validate addon name follows basic Odoo conventions

oduit.utils.format_dependency_tree(module_name: str, tree: dict[str, Any], module_manager: Any, prefix: str = '', is_last: bool = True, seen: set[str] | None = None, odoo_series: Any | None = None, is_root: bool = False) list[tuple[str, str]][source]

Format a dependency tree for display.

Parameters:
  • module_name – Name of the module to format

  • tree – Dependency tree structure from get_dependency_tree()

  • module_manager – ModuleManager instance to get manifest info

  • prefix – Current line prefix for indentation

  • is_last – Whether this is the last item at this level

  • seen – Set of already seen modules to detect cycles

  • odoo_series – Optional OdooSeries for enhanced version display

  • is_root – Whether this is the root module (no connector)

Returns:

List of tuples (module_part, version_part) for each line

Usage Examples

File and Path Utilities

from oduit import utils

# Check if path exists and is accessible
if utils.path_exists('/path/to/odoo'):
    print("Odoo path is valid")

# Ensure directory exists
utils.ensure_directory('/path/to/logs')

# Get absolute path
abs_path = utils.get_absolute_path('relative/path')

Process Utilities

# Check if process is running
if utils.is_process_running(1234):
    print("Process is running")

# Kill process safely
utils.kill_process(1234)

# Execute command and get output
output = utils.execute_command(['ls', '-la'])

Configuration Utilities

# Merge configuration dictionaries
base_config = {'database': {'host': 'localhost'}}
override_config = {'database': {'port': 5432}}
merged = utils.merge_configs(base_config, override_config)

# Validate configuration structure
is_valid = utils.validate_config_structure(config_dict)

# Get environment variable with default
db_host = utils.get_env_var('DB_HOST', 'localhost')