Last active
October 4, 2023 15:20
-
-
Save Sunderlandkyl/f6b5fbf365a4cbf0935e4a89f4f38130 to your computer and use it in GitHub Desktop.
Generate a combined AdditionalLauncherSettings file from multiple extensions
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
import configparser | |
import logging | |
logging.basicConfig() | |
logging.root.setLevel(logging.NOTSET) | |
logging.basicConfig(level=logging.NOTSET) | |
relWithDebugInputFileNames = [ | |
"C:/d/s/SIGSIOW/inner-build/AdditionalLauncherSettings.ini", # SlicerIGSIO | |
"C:/d/s/SIGTW/AdditionalLauncherSettings.ini", # SlicerIGT | |
"C:/d/s/SOIGTLW/inner-build/AdditionalLauncherSettings.ini", # SlicerOpenIGTLink | |
] | |
relWithDebugOutputFileName = "C:/d/s/GeneratedSuperAdditionalLauncherSettings.ini" | |
debugInputFileNames = [ | |
"C:/d/s/SIGSIOD/inner-build/AdditionalLauncherSettings.ini", # SlicerIGSIO | |
"C:/d/s/SIGTD/AdditionalLauncherSettings.ini", # SlicerIGT | |
"C:/d/s/SOIGTLD/inner-build/AdditionalLauncherSettings.ini", # SlicerOpenIGTLink | |
] | |
debugOutputFileName = "C:/d/s/D_GeneratedSuperAdditionalLauncherSettings.ini" | |
sizedSections = [ | |
"LibraryPaths", | |
"Paths", | |
"PYTHONPATH", | |
] | |
outputConfig = configparser.ConfigParser() | |
outputConfig.add_section("General") | |
inputFileNames = relWithDebugInputFileNames | |
outputFileName = relWithDebugOutputFileName | |
for fileName in inputFileNames: | |
logging.info(f"Processing {fileName}") | |
inputConfig = configparser.ConfigParser() | |
inputConfig.read(fileName) | |
sections = inputConfig.sections() | |
for section in sections: | |
if not outputConfig.has_section(section): | |
outputConfig.add_section(section) | |
keyValuePairs = inputConfig.items(section) | |
for key, value in keyValuePairs: | |
if key == "size": | |
continue | |
if not section in sizedSections: | |
outputConfig.set(section, key, value) | |
else: | |
count = len(outputConfig.items(section)) | |
outputConfig.set(section, f"{count+1}/path", value) | |
for section in sizedSections: | |
count = len(outputConfig.items(section)) | |
outputConfig.set(section, "size", str(count)) | |
with open(outputFileName, 'w') as configfile: | |
outputConfig.write(configfile) | |
logging.info(f"Complete -- Processed {len(inputFileNames)} files. Output written to {outputFileName}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment