Commit 1cadb43e authored by Lukas Riedel's avatar Lukas Riedel

Replace configparser by DUNE inifile parser in parfield module

parent 130c12d4
import h5py import h5py
import os import os
import sys import sys
import configparser
import numpy as np import numpy as np
from dune.testtools.parser import parse_ini_file
from dorie.utilities.text_to_bool import text_to_bool from dorie.utilities.text_to_bool import text_to_bool
class BaseConverter(object): class BaseConverter(object):
...@@ -20,9 +21,7 @@ class BaseConverter(object): ...@@ -20,9 +21,7 @@ class BaseConverter(object):
_dataset = None # The field to be written into the target file _dataset = None # The field to be written into the target file
def __init__(self, param, input_file=None): def __init__(self, param, input_file=None):
self._cp = configparser.ConfigParser(interpolation=None) self._cp = parse_ini_file(param)
with open(param) as file:
self._cp.read_file(file)
outfile = self._read_parameter('general', 'outputFile') outfile = self._read_parameter('general', 'outputFile')
dataset = self._read_parameter('general', 'dataset') dataset = self._read_parameter('general', 'dataset')
......
...@@ -8,7 +8,8 @@ import argparse ...@@ -8,7 +8,8 @@ import argparse
import warnings import warnings
import subprocess import subprocess
import multiprocessing import multiprocessing
import configparser
from dune.testtools.parser import parse_ini_file
from dorie.parfield.converter import BaseConverter, \ from dorie.parfield.converter import BaseConverter, \
BinaryConverter, \ BinaryConverter, \
...@@ -47,14 +48,13 @@ if __name__ == "__main__": ...@@ -47,14 +48,13 @@ if __name__ == "__main__":
parser.add_argument('--debug',help='Display warnings',action='store_true',required=False) parser.add_argument('--debug',help='Display warnings',action='store_true',required=False)
args = vars(parser.parse_args()) args = vars(parser.parse_args())
cp = configparser.ConfigParser(interpolation=None) # retrieve the inifile tree
with open(args["param"]) as file: inifile = parse_ini_file(args["param"])
cp.read_file(file)
params = {} params = {}
for par in ("converter", "outputFile"): for par in ("converter", "outputFile"):
try: try:
params[par] = cp["general"][par] params[par] = inifile["general"][par]
except KeyError: except KeyError:
raise RuntimeError("Missing option general.{} in " raise RuntimeError("Missing option general.{} in "
"parameter file {}".format(par, args["param"])) "parameter file {}".format(par, args["param"]))
...@@ -72,7 +72,7 @@ if __name__ == "__main__": ...@@ -72,7 +72,7 @@ if __name__ == "__main__":
print("FFT Field generator failed") print("FFT Field generator failed")
sys.exit(1) sys.exit(1)
rng_outpath = cp.get("general", "tempDir") rng_outpath = inifile["general"]["tempDir"]
input_file = os.path.join(rng_outpath, "field.stoch.h5") input_file = os.path.join(rng_outpath, "field.stoch.h5")
# CALL CONVERTER # CALL CONVERTER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment