Last active
December 4, 2024 15:10
-
-
Save winebarrel/0c702fc80a9475855ee14fd5cdf14911 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
import configparser | |
import json | |
import sys | |
def print_json(f): | |
config = configparser.ConfigParser() | |
config.read_file(f) | |
d = dict() | |
for sec in config.sections(): | |
items = config.items(sec) | |
d[sec] = dict(items) | |
out = json.dumps(d) | |
print(out) | |
args = sys.argv | |
args.pop(0) | |
if len(args) == 0: | |
print_json(sys.stdin) | |
else: | |
for fn in args: | |
with open(fn) as f: | |
print_json(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment