Collection of command line tools to work with properties files (diff-like, patch-like)
Project description
properties-tools
properties-tools is a collection of command line tools to work with properties files: comparing like wdiff
, updating like patch
...
The idea is to work with the content (key/value
pairs) instead of the text, to ignore order or format and deal with the data.
properties-diff
can compare and print differences between 2 properties files, with fancy colors as if you were usingwdiff
ordiff
tools. It does not compare the text files.properties-patch
can update a properties file using values from others, you can choose to add new keys and/or update existing and/or remove others.
Install
Install the latest release from PyPI
$ pip3 install properties-diff
$ properties-diff --help
Install from the sources
$ pip3 install poetry
$ pip3 install git+https://github.com/essembeh/properties-tools
$ properties-diff --help
properties-diff
Usage
$ properties-diff --help
usage: properties-diff [-h] [--version] [-q] [--quote] [--color | --nocolor] [--sep SEP] [-m {simple,diff,wdiff} | --diff | --wdiff | --simple] [-A] [-D] [-U] left.properties right.properties
positional arguments:
left.properties left file to compare
right.properties right file to compare
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-q, --quiet print less information
--quote use double quotes for values, example: foo="bar"
--color force colors
--nocolor disable colors
--sep SEP key/value separator, default is '='
-m {simple,diff,wdiff}, --mode {simple,diff,wdiff}
select a format to show differences: using colors only (simple), using diff-like format (diff) or wdiff-like (wdiff) format. Default is 'wdiff'
--diff use diff-like format to show differences
--wdiff use wdiff-like format to show differences
--simple use simple format to show differences
-A, --added print added properties
-D, --deleted print deleted properties
-U, --updated print updated properties
Examples
Comparing properties files like wdiff
$ properties-diff tests/sample1.properties tests/sample2.properties
--- tests/sample1.properties (left) 2022-04-07 12:48:44
+++ tests/sample2.properties (right) 2022-04-07 12:49:02
# Only in tests/sample1.properties (left)
[-database.host=localhost-]
# Only in tests/sample2.properties (right)
{+database.version=12+}
# Updated from tests/sample1.properties (left) to tests/sample2.properties (right)
database.type=[-postgresql-]{+mysql+}
database.user=[-test-]{+dbuser+}
Comparing properties files like diff
$ properties-diff tests/sample1.properties tests/sample2.properties --diff
--- tests/sample1.properties (left) 2022-04-07 12:48:44
+++ tests/sample2.properties (right) 2022-04-07 12:49:02
# Only in tests/sample1.properties (left)
- database.host=localhost
# Only in tests/sample2.properties (right)
+ database.version=12
# Updated from tests/sample1.properties (left) to tests/sample2.properties (right)
- database.type=postgresql
+ database.type=mysql
- database.user=test
+ database.user=dbuser
Compare files, but only show updateed
and added
values
$ properties-diff tests/sample1.properties tests/sample2.properties --add --update
--- tests/sample1.properties (left) 2022-04-07 12:48:44
+++ tests/sample2.properties (right) 2022-04-07 12:49:02
# Only in tests/sample2.properties (right)
{+database.version=12+}
# Updated from tests/sample1.properties (left) to tests/sample2.properties (right)
database.type=[-postgresql-]{+mysql+}
database.user=[-test-]{+dbuser+}
Viewing modes
You can see differences between the properties files using 3 modes using --mode <MODE>
or -m <MODE>
wdiff
, prints the changes likewdiff
tool would do (this is the default mode)diff
, prints the changes likediff
tool would dosimple
, based on colors, red for removed lines, green for added lines
properties-patch
Usage
$ properties-patch --help
usage: properties-patch [-h] [--version] [--color | --nocolor] [-c] [-i] [--quote] [--sep SEP] [-A] [-D] [-U] -p patch.properties [-o output.properties | -w] [-f] source.properties
positional arguments:
source.properties file to modify
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
--color force colors
--nocolor disable colors
-c, --comments insert comment when property is added, updated or deleted
-i, --interactive ask for confirmation to add, update or delete a property
--quote use double quotes for values, example: foo="bar"
--sep SEP key/value separator, default is '='
-p patch.properties, --patch patch.properties
patch file
-o output.properties, --output output.properties
modified file
-w, --overwrite update input properties file in place
-f, --force force output file (--output) overwrite if it already exists
-A, --add add new properties from patches
-D, --delete delete properties not in patches
-U, --update update properties from patches
Examples
Build a properties file from tests/sample1.properties
and add missing keys from tests/sample2.properties
$ properties-patch tests/sample1.properties --patch tests/sample2.properties --add
# just a comment
database.type=postgresql
database.host=localhost
database.port=5432
# and another comment
database.user=test
database.password=foobar
database.version=12
You can use multiple patch files, if a value is present in multiple patch files, the latest value will be used.
$ properties-patch tests/sample1.properties --patch tests/sample2.properties --patch tests/sample3.properties -A
# just a comment
database.type=postgresql
database.host=localhost
database.port=5432
# and another comment
database.user=test
database.password=foobar
database.version=42
You can choose to add missing values and update values that are different in the patch files
$ properties-patch tests/sample1.properties --patch tests/sample2.properties -AU
# just a comment
database.type=mysql
database.host=localhost
database.port=5432
# and another comment
database.user=dbuser
database.password=foobar
database.version=12
There is an interactive mode, which ask for confirmation before every change (usefull to take only some changes, equivalent to git add --interactive
)
$ properties-patch tests/sample1.properties --patch tests/sample2.properties -AU --interactive
# just a comment
💬 Update database.type=postgresql,mysql ? [Y/n]
database.type=mysql
database.host=localhost
database.port=5432
# and another comment
💬 Update database.user=test,dbuser ? [Y/n]
database.user=dbuser
database.password=foobar
💬 Add database.version=12 ? [Y/n]
database.version=12
To track changes, you can add comments for every change applied
$ properties-patch tests/sample1.properties --patch tests/sample2.properties -ADU --comments
# just a comment
# 2022-04-07 23:12:11 update: database.type=postgresql
database.type=mysql
# 2022-04-07 23:12:11 remove: database.host=localhost
database.port=5432
# and another comment
# 2022-04-07 23:12:11 update: database.user=test
database.user=dbuser
database.password=foobar
# 2022-04-07 23:12:11 add: database.version
database.version=12
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
File details
Details for the file properties_tools-0.7.2.tar.gz
.
File metadata
- Download URL: properties_tools-0.7.2.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.15 Linux/5.15.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c2eea46f0b86dc3de5c7fcc4c80dab778e0f5f2e81ef0cc83255c310e153d7d |
|
MD5 | 0be8306ecc85080aba274b8a8a740742 |
|
BLAKE2b-256 | 43b3693da4159cdb012f7cf8fe790a5c586e0d72dc2098b4e1e979da675c4a76 |
File details
Details for the file properties_tools-0.7.2-py3-none-any.whl
.
File metadata
- Download URL: properties_tools-0.7.2-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.15 Linux/5.15.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8619b4107e9c3626fc435672140326f812a509042e39a23143593660f6f627c |
|
MD5 | 3f0d4e48b71ab3dc2f394ea02d25c2fa |
|
BLAKE2b-256 | e66fca89676a2c7b71bfcde137f401a6eb3d30e351e116a873e817be8cf84347 |