A package for reading, modifying, and writing U-Boot environment files
Project description
py-uboot-env
A Python package for manipulating U-Boot environment files with a modern API and convenient CLI tools.
Overview
py-uboot-env provides functionality to read, modify, and write U-Boot environment files. It features both a programmer-friendly API and a versatile command-line interface.
Features
- Command-line interface for common operations
- Support for both file paths and file handles
- Environment variable dependency analysis and visualization
- Built-in environment editor with your system's default text editor
Installation
Install from PyPI:
pip install py-uboot-env
API Usage
Basic Usage
from py_uboot_env import load_env
# Load an environment file
env = load_env('/path/to/uboot.env')
# Read values
bootcmd = env.get('bootcmd')
bootdelay = env.get('bootdelay', '3') # With default value
# Modify values
env.set('bootdelay', '5')
env.delete('unused_var')
# Save changes
env.save('/path/to/uboot.env')
Working with File Handles
from py_uboot_env import load_env, dump_env
import io
# Create an in-memory file-like object
buffer = io.BytesIO()
# Create a new environment and save it to the buffer
env = load_env(existing_env_file)
env.set('new_variable', 'value')
dump_env(env, buffer)
# Rewind the buffer and read it back
buffer.seek(0)
updated_env = load_env(buffer)
Command-Line Interface
py-uboot-env provides a single uboot-env command with multiple actions:
Viewing Environment Variables
# Dump the entire environment
uboot-env dump /path/to/uboot.env
# Get a specific variable
uboot-env get /path/to/uboot.env bootcmd
Modifying Environment Variables
# Set a variable
uboot-env set /path/to/uboot.env bootdelay 5
# Delete a variable
uboot-env delete /path/to/uboot.env unused_var
Interactive Editing
Open the environment file in your default text editor:
uboot-env edit /path/to/uboot.env
Dependency Analysis
Generate a GraphViz DOT representation of variable dependencies:
# Generate DOT output
uboot-env graph /path/to/uboot.env > uboot-deps.dot
# Generate a PDF using GraphViz (if installed)
uboot-env graph /path/to/uboot.env | dot -Tpdf -o uboot-deps.pdf
This analyzes which environment variables are read from, written to, or which commands are run by each variable, creating a visual dependency graph.
Environment File Format
The package handles U-Boot environment files in their standard binary format, including:
- CRC32 checksums in the header
- Support for different environment sizes
- Proper handling of redundant environment blocks
Development
Testing
The package includes a comprehensive test suite to ensure functionality and reliability.
Running Tests
To run the test suite, first install pytest:
pip install pytest
Then run the tests:
python -m pytest
For more detailed output, use the verbose flag:
python -m pytest -v
Test Coverage
The test suite covers:
- Core Functionality: Tests for the
UBootEnvclass methods (get,set,delete,save) and utility functions (load_env,dump_env,format_env). - Error Handling: Tests for handling invalid environment sizes and CRC errors.
- CLI Commands: Tests for all environment manipulation commands (
dump,get,set,delete,edit). - Integration Tests: End-to-end workflows for both API and CLI usage patterns.
Publishing to PyPI
This package uses GitHub Actions to automatically publish to PyPI when a new release is created. To publish a new version:
- Update the version number in
pyproject.toml - Merge your changes to the
mainbranch - Create a new GitHub Release with a tag that matches the version (e.g.,
v1.1.3)
Important Notes:
- The version in
pyproject.tomlMUST be updated before creating a release tag, or PyPI will reject the publication. - The GitHub Action workflow will only publish to PyPI when a tag is pushed, not on regular commits.
- The version tag should match the version in
pyproject.toml.
Contributing
- Fork the repository
- Create a feature branch
- Submit a pull request
License
This project is licensed under The Unlicense - see the LICENSE file for details.
Acknowledgments
- U-Boot Project
- Original code by Dave Jones which served as the foundation for this package
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_uboot_env-1.0.0.tar.gz.
File metadata
- Download URL: py_uboot_env-1.0.0.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bedcb4f7d230f1b0cf291d1402cb3aa62b9f1f2a40ac98496625a135c05ba14
|
|
| MD5 |
9d50216137ebb24bfe4b90ccceb4be17
|
|
| BLAKE2b-256 |
faf9e68a555aadf2f2d3cb2231603b5a6dc08b4044ac72aca819af9f1687a604
|
Provenance
The following attestation bundles were made for py_uboot_env-1.0.0.tar.gz:
Publisher:
publish-to-test-pypi.yml on cubix-mx/py-uboot-env
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_uboot_env-1.0.0.tar.gz -
Subject digest:
5bedcb4f7d230f1b0cf291d1402cb3aa62b9f1f2a40ac98496625a135c05ba14 - Sigstore transparency entry: 194525955
- Sigstore integration time:
-
Permalink:
cubix-mx/py-uboot-env@f0228ba17f6c60e8f96851ad8e8b1386b2efc986 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/cubix-mx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-test-pypi.yml@f0228ba17f6c60e8f96851ad8e8b1386b2efc986 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_uboot_env-1.0.0-py3-none-any.whl.
File metadata
- Download URL: py_uboot_env-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5df4aaa21bfcee175c275d634f321c504409c631485979de9ca5d113fb57b9f2
|
|
| MD5 |
6dca8e93509a355839fcdbad0799776d
|
|
| BLAKE2b-256 |
9e2caec3211815ebf959aa65e0077e901492bd16308891bab9edafe10a2377b6
|
Provenance
The following attestation bundles were made for py_uboot_env-1.0.0-py3-none-any.whl:
Publisher:
publish-to-test-pypi.yml on cubix-mx/py-uboot-env
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_uboot_env-1.0.0-py3-none-any.whl -
Subject digest:
5df4aaa21bfcee175c275d634f321c504409c631485979de9ca5d113fb57b9f2 - Sigstore transparency entry: 194525957
- Sigstore integration time:
-
Permalink:
cubix-mx/py-uboot-env@f0228ba17f6c60e8f96851ad8e8b1386b2efc986 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/cubix-mx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-test-pypi.yml@f0228ba17f6c60e8f96851ad8e8b1386b2efc986 -
Trigger Event:
push
-
Statement type: