Skip to main content

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.

PyPI version License

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 UBootEnv class 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:

  1. Update the version number in pyproject.toml
  2. Merge your changes to the main branch
  3. Create a new GitHub Release with a tag that matches the version (e.g., v1.1.3)

Important Notes:

  • The version in pyproject.toml MUST 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

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

License

This project is licensed under The Unlicense - see the LICENSE file for details.

Acknowledgments

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

py_uboot_env-1.0.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_uboot_env-1.0.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

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

Hashes for py_uboot_env-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5bedcb4f7d230f1b0cf291d1402cb3aa62b9f1f2a40ac98496625a135c05ba14
MD5 9d50216137ebb24bfe4b90ccceb4be17
BLAKE2b-256 faf9e68a555aadf2f2d3cb2231603b5a6dc08b4044ac72aca819af9f1687a604

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for py_uboot_env-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5df4aaa21bfcee175c275d634f321c504409c631485979de9ca5d113fb57b9f2
MD5 6dca8e93509a355839fcdbad0799776d
BLAKE2b-256 9e2caec3211815ebf959aa65e0077e901492bd16308891bab9edafe10a2377b6

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page