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.

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-0.1.2.tar.gz (15.7 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-0.1.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file py_uboot_env-0.1.2.tar.gz.

File metadata

  • Download URL: py_uboot_env-0.1.2.tar.gz
  • Upload date:
  • Size: 15.7 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-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1b54c0c1891e8bd8e406cb1fba62d544e9d229aaf95e5bda0a86742964b34c97
MD5 f6d86ccd88dea6fe7236f4041807625d
BLAKE2b-256 80e6c5f743ebd3233a3a867e4aa7dfa562e2173171c3138e824bf6c114bdd5e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_uboot_env-0.1.2.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-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: py_uboot_env-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.5 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-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0dd2a80d1960138278e55d803665a6af21a3f9b31096bab1779069010f4db086
MD5 8d3eedc36e1cdb92825d3750ea7af84c
BLAKE2b-256 9bc231cafda4c27df098804fa3c9815b0968a6a827d5cc08eba0047d5a8bab4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_uboot_env-0.1.2-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