-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
151 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,41 @@ | ||
# sdkconfig-differ | ||
sdkconfig differ for esp-idf config files | ||
# esp-config-diff | ||
|
||
`esp-config-diff` is a Python command-line tool for comparing two configuration | ||
files and displaying differences. It highlights added, removed, and modified | ||
configuration values, making it easy to track changes between versions. | ||
|
||
## Features | ||
|
||
- Compare two configuration files and output the differences. | ||
- Color-coded output to distinguish between added, removed, and modified entries. | ||
- Option to disable colors for plain-text output. | ||
- Can be used as a standalone command-line tool or within a Python script. | ||
|
||
--- | ||
|
||
## Installation | ||
|
||
## Install requirements | ||
``` | ||
python3 -m pip install -r requirements.txt | ||
python3 -m pip install esp-config-diff | ||
``` | ||
|
||
## How to use eg | ||
## Usage | ||
|
||
### Basic Usage | ||
``` | ||
./sdkconfig-differ.py --conf sdkconfig --old-conf sdkconfig.old | ||
esp-config-diff --conf sdkconfig --old-conf sdkconfig.old | ||
``` | ||
|
||
## Example Output | ||
### Disabling Color Output | ||
``` | ||
esp-config-diff --conf sdkconfig --old-conf sdkconfig.old --no-color | ||
``` | ||
|
||
### Example output | ||
``` | ||
CONFIG Old Value New Value | ||
=================================================== | ||
CONFIG_FEATURE_ENABLED ABSENT true | ||
CONFIG_MAX_CONNECTIONS 10 20 | ||
CONFIG_TIMEOUT 300 ABSENT | ||
``` | ||
CONFIG Old Value New Value | ||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT ABSENT n | ||
CONFIG_LWIP_IPV6_NUM_ADDRESSES ABSENT 6 | ||
CONFIG_BSP_LED_RGB_GPIO 8 48 | ||
CONFIG_IDF_TARGET "esp32c6" ABSENT | ||
`` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import click | ||
|
||
# ANSI color codes for styling | ||
RED = '\033[91m' | ||
GREEN = '\033[92m' | ||
YELLOW = '\033[93m' | ||
RESET = '\033[0m' | ||
BOLD = '\033[1m' | ||
|
||
# array to json | ||
def to_json(config): | ||
json_data = {} | ||
for line in config: | ||
parts = line.strip().split('=') | ||
if len(parts) == 2: | ||
json_data[parts[0]] = parts[1] | ||
return json_data | ||
|
||
# file to json | ||
def make_config(sdkconfig): | ||
with open(sdkconfig, 'r') as f: | ||
conf_lines = f.readlines() | ||
config = [line.strip() for line in conf_lines if not line.startswith('#')] | ||
return config | ||
|
||
@click.command() | ||
@click.option('--conf', help='Current config file') | ||
@click.option('--old-conf', help='Older config file') | ||
@click.option('--no-color', is_flag=True, help='Disable colored output') | ||
def main(conf, old_conf, no_color): | ||
# Determine if colors should be used | ||
use_color = not no_color | ||
|
||
# Read the config into lists | ||
new_conf = make_config(conf) | ||
old_conf = make_config(old_conf) | ||
|
||
# Remove common config | ||
for item in new_conf[:]: # Copy to modify in-place | ||
if item in old_conf: | ||
new_conf.remove(item) | ||
old_conf.remove(item) | ||
|
||
new_conf_json = to_json(new_conf) | ||
old_conf_json = to_json(old_conf) | ||
|
||
# Generate diff list | ||
diff_list = [] | ||
|
||
# Process new configuration items | ||
for key, val in new_conf_json.items(): | ||
j = {key: {'old': 'ABSENT', 'new': val}} | ||
if key in old_conf_json: | ||
j[key]['old'] = old_conf_json[key] | ||
old_conf_json.pop(key) | ||
diff_list.append(j) | ||
|
||
# Process remaining old configuration items | ||
for key, val in old_conf_json.items(): | ||
j = {key: {'old': val, 'new': 'ABSENT'}} | ||
diff_list.append(j) | ||
|
||
# Display formatted output | ||
header = f"{BOLD}{'CONFIG':<60}{'Old Value':<60}{'New Value'}{RESET}" if use_color else f"{'CONFIG':<60}{'Old Value':<60}{'New Value'}" | ||
print(header) | ||
print(f"{'='*140}") | ||
|
||
for item in diff_list: | ||
key = list(item.keys())[0] | ||
old_val = item[key]['old'] | ||
new_val = item[key]['new'] | ||
|
||
# Set color based on value status | ||
if use_color: | ||
if old_val == 'ABSENT': | ||
color = GREEN # New addition | ||
elif new_val == 'ABSENT': | ||
color = RED # Removed | ||
else: | ||
color = YELLOW # Modified | ||
reset_color = RESET | ||
else: | ||
color = "" | ||
reset_color = "" | ||
|
||
print(f"{color}{key:<60}{old_val:<60}{new_val}{reset_color}") | ||
|
||
if __name__ == '__main__': | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# setup.py | ||
|
||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='esp_config_diff', | ||
version='0.1.0', | ||
packages=find_packages(), | ||
install_requires=[ | ||
'Click', | ||
], | ||
entry_points={ | ||
'console_scripts': [ | ||
'esp-config-diff=diff.cli:main', | ||
], | ||
}, | ||
description='A tool for comparing esp idf sdkconfigs', | ||
author='shubhamdp', | ||
url='https://github.com/shubhamdp/esp-config-diff', | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
], | ||
python_requires='>=3.6', | ||
) |