-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
27e200a
commit 5aa3876
Showing
2 changed files
with
21 additions
and
12 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
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,30 @@ | ||
from os import listdir | ||
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")] | ||
|
||
print("{") | ||
jsonConfigs = {} | ||
|
||
for i in nmfiles: | ||
config = configparser.ConfigParser() | ||
config = configparser.ConfigParser(delimiters=('=', )) | ||
config.read(i) | ||
connection_name = i.strip(".nmconnection") | ||
print(f" {connection_name} = {{") | ||
connection_name = i.removesuffix(".nmconnection") | ||
jsonConfigs[connection_name] = {} | ||
for section in config.sections(): | ||
print(f" {section} = {{") | ||
jsonConfigs[connection_name][section] = {} | ||
for key in config[section]: | ||
print(f' {key} = "{config[section][key]}";') | ||
print(" };") | ||
print(" };") | ||
print("};") | ||
jsonConfigs[connection_name][section][key] = config[section][key] | ||
|
||
tf = tempfile.TemporaryFile("w+") | ||
jsonConfigs = json.dump(jsonConfigs, tf) | ||
tf.flush() | ||
|
||
|
||
print(check_output(["nix-instantiate", "--expr", "--eval", f"builtins.fromJSON (builtins.readFile \"/proc/{getpid()}/fd/{tf.fileno()}\")"], text=True)) # noqa: E501 |