Skip to content

Instantly share code, notes, and snippets.

@YellowOnion
Created March 11, 2025 09:02
Show Gist options
  • Save YellowOnion/6c0fe2cef751fa595b23949e50e36bfd to your computer and use it in GitHub Desktop.
Save YellowOnion/6c0fe2cef751fa595b23949e50e36bfd to your computer and use it in GitHub Desktop.
from os import listdir, getpid
from subprocess import check_output
from os.path import isfile, join
import configparser
import tempfile
import json
path = "./"
files = [f for f in listdir(path) if isfile(join(path, f))]
nmfiles = [f for f in files if f.endswith(".nmconnection")]
jsonConfigs = {}
for i in nmfiles:
config = configparser.ConfigParser(delimiters=('=', ))
config.read(i)
connection_name = i.removesuffix(".nmconnection")
jsonConfigs[connection_name] = {}
for section in config.sections():
jsonConfigs[connection_name][section] = {}
for key in config[section]:
jsonConfigs[connection_name][section][key] = config[section][key]
print(json.dumps(jsonConfigs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment