penguin.gen_config module¶
penguin.gen_config¶
Configuration generation utilities for the Penguin emulation environment.
This module provides functions and classes for analyzing extracted filesystems, running static analyses, generating configuration files and patches, and handling config creation via CLI or programmatically.
- class penguin.gen_config.ConfigBuilder(fs_archive, output_dir)[source]¶
Bases:
objectGiven a filesystem and an output directory, create a configuration and initialize the output directory as necessary.
- Parameters:
fs_archive (str)
output_dir (str | Path)
- PATCH_DIR: str = 'static_patches'¶
- create_patches(fs_archive, static_results, extract_dir)[source]¶
Generate a patch that ensures we have all directories in a fixed list.
- Parameters:
fs_archive (str or Path) – Path to filesystem archive.
static_results (dict) – Static analysis results.
extract_dir (str or Path) – Directory containing extracted filesystem.
- Returns:
Dictionary of generated patches.
- Return type:
dict
- generate_initial_config(patches)[source]¶
Generate the initial configuration dictionary.
- Parameters:
patches (dict) – Dictionary of patches.
- Returns:
Initial configuration dictionary.
- Return type:
dict
- render_patches(output_dir, patches)[source]¶
Given a dictionary of patches, render them into output_dir / patches.
- Parameters:
output_dir (str or Path) – Output directory.
patches (dict) – Dictionary of patches.
- Return type:
None
- run_static_analyses(output_dir, extracted_dir, static_dir_name='static')[source]¶
Run static analysis on the extracted filesystem and write results to output_dir/static.
- Parameters:
output_dir (str or Path) – Output directory for results.
extracted_dir (str or Path) – Directory containing extracted filesystem.
static_dir_name (str) – Name of static results subdirectory.
- Returns:
Dictionary of static analysis results.
- Return type:
dict
- penguin.gen_config.fakeroot_gen_config(fs, out, artifacts_dir, verbose)[source]¶
Run config generation under fakeroot.
- Parameters:
fs (str) – Path to filesystem archive.
out (str) – Path to output config file.
artifacts_dir (str) – Path to artifacts directory.
verbose (int) – Verbosity level.
- Returns:
Path to generated config file or None.
- Return type:
str or None
- penguin.gen_config.initialize_and_build_config(fs, out=None, artifacts_dir=None)[source]¶
Given a filesystem as a .tar.gz analyze it to create a configuration file. Out is the path to the config to produce. Use artifacts_dir as scratch space while analyzing.
- Parameters:
fs (str) – Path to filesystem archive (.tar.gz).
out (str or None) – Path to output config file.
artifacts_dir (str or None) – Path to artifacts directory.
- Returns:
Path to generated config file.
- Return type:
str
- Raises:
RuntimeError – If firmware file is not found.
ValueError – If input file is not a .tar.gz archive.