Parse and emit OpenWRT uci-format files
Project description
UCI Parse Library
Python 3 library and command line tools to parse, diff, and normalize OpenWRT UCI configuration files.
These tools were written to ease OpenWRT upgrades, making it easier to see the
differences between two config files. As of this writing (mid-2020), OpenWRT
upgrades often don't normalize upgraded config files in the same way from
version to version. For instance, the new version from opkg upgrade (saved
off with a -opkg filename) might use single quotes on all lines, while the
original version on disk might not use quotes at all. This makes it very
difficult understand the often-minimal differences between an upgraded file and
the original file.
Installing the Package
Installing this package on your OpenWRT router is not as simple as it could be.
A lot of routers do not have enough space available to install a full version
of Python including pip or setuptools. If yours does have lots of space,
it's as simple as this:
$ opkg update
$ opkg install python3-pip
$ pip3 install uciparse
If not, it gets a little ugly. First, install wget with support for HTTPS:
$ opkg update
$ opkg install wget ca-bundle ca-certificates
Then, go to PyPI and copy the
URL for the source package .tar.gz file. Retrieve the source package
with wget and then manually extract it:
$ wget https://files.pythonhosted.org/.../uciparse-0.1.2.tar.gz
$ tar zxvf uciparse-0.1.2.tar.gz
$ cd uciparse-0.1.2
Finally, run the custom install script provided with the source package:
$ sh ./scripts/install
This installs the OpenWRT python3-light package, then copies the Python
packages into the right site-packages directory and the uciparse and
ucidiff scripts to /usr/bin.
Using the Tools
Once you have installed the package as described above, the uciparse and
ucidiff tools will be available in your path.
ucidiff
The ucidiff tool is probably the tool you'll use most often when updating
your router. It reads two UCI configuration files from disk, normalizes both in
memory (without making changes on disk), and then compares them. The result is
a unified diff, like diff -Naur. This gives you a way to understand the real
differences between two files without ever having to change anything on disk.
$ ucidiff --help
usage: ucidiff [-h] a b
Diff two UCI configuration files.
positional arguments:
a Path to the first UCI file to compare
b Path to the second UCI file to compare
optional arguments:
-h, --help show this help message and exit
The comparison is equivalent to a 'diff -Naur' between the normalized versions
of the files. If either file can't be parsed, then an error will be returned
and no diff will be shown.
uciparse
If you would prefer to clean up and normalize your configuration files on disk,
then you can use the uciparse tool. It reads a UCI config file from disk or
from stdin, parses it, and prints normalized output to stdout.
$ uciparse --help
usage: uciparse [-h] uci
Parse and normalize a UCI configuration file.
positional arguments:
uci Path to the UCI file to normalize, or '-' for stdin
optional arguments:
-h, --help show this help message and exit
Results will be printed to stdout. If the file can't be parsed then an error
will be returned and no output will be generated.
Before using uciparse, you should make a backup of any config file that you
are going to normalized.
Project details
Release history Release notifications | RSS feed
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 uciparse-0.3.0.tar.gz.
File metadata
- Download URL: uciparse-0.3.0.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffd4ef3381ce9b43f57ea41b66f81f151108e1d223e77fa2da899e71528125f0
|
|
| MD5 |
18eb7507711def418d321c4f26207fb1
|
|
| BLAKE2b-256 |
206a5e62bea0230c4a01761badfdf6618f32dbf942151f7789bf1283d0aecb1f
|
File details
Details for the file uciparse-0.3.0-py3-none-any.whl.
File metadata
- Download URL: uciparse-0.3.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a7d966e5f6bf97312d4582a693a0de46ded7e7adc6b464d5c02d216a5bc7851
|
|
| MD5 |
c4f0d7519f6b0b4e943fce9a836b1200
|
|
| BLAKE2b-256 |
d7854af4c8e5203645520d324cbc70fa9bf1b485de4ca76088ae60b17d4388e8
|