Example #1
0
def read_path(filename=PN.IFILE3):
    lines, status = file2lines(filename)
    # Get info for lines
    dpath = {}
    ctc_lines = None
    bool_mep = False
    bool_drp = False
    saveline = False
    for line in lines:
        #-- MEP --#
        if line.startswith("end_mep"):
            bool_mep = False
            saveline = False
            dpath[ctc] = ("mep", pathlines)
            continue
        #-- DRP --#
        if line.startswith("end_drp"):
            bool_drp = False
            saveline = False
            dpath[ctc] = ("drp", pathlines)
            continue
        # save line
        if saveline: pathlines.append(line)
        #-- MEP --#
        if line.startswith("start_mep"):
            bool_mep = True
            saveline = True
            ctc = line.split()[1]
            pathlines = []
            continue
        #-- DRP --#
        if line.startswith("start_drp"):
            bool_drp = True
            saveline = True
            ctc = line.split()[1]
            pathlines = []
            continue
    # Read data for each ctc
    for ctc, (pathtype, lines) in dpath.items():
        pathvars = PathVars(pathtype)
        # Read info in lines
        for line in lines:
            line = line.lower()
            key = line.split()[0]
            value = " ".join(line.split()[1:]).lower()
            try:
                pathvars.setvar(key, value)
            except:
                exception = Exc.ReadProblem(Exception)
                exception._file = filename
                exception._var = line.split("\n")[0]
                raise exception
        dpath[ctc] = pathvars
    return dpath, (filename, status)
Example #2
0
def prepare_dpath(dpath):
    # Read data for each ctc
    for ctc, (pathtype, lines) in dpath.items():
        pathvars = PathVars(pathtype)
        # Read info in lines
        for line in lines:
            line = line.lower()
            key = line.split()[0]
            value = " ".join(line.split()[1:]).lower()
            try:
                pathvars.setvar(key, value)
            except:
                exception = Exc.ReadProblem(Exception)
                exception._file = filename
                exception._var = line.split("\n")[0]
                raise exception
        dpath[ctc] = pathvars
    return dpath