Esempio n. 1
0
def read_xconfig_file(xconfig_filename):
    try:
        f = open(xconfig_filename, 'r')
    except Exception as e:
        sys.exit("{0}: error reading xconfig file '{1}'; error was {2}".format(
            sys.argv[0], xconfig_filename, repr(e)))
    all_layers = []
    while True:
        line = f.readline()
        if line == '':
            break
        x = xutils.parse_config_line(line)
        if x is None:
            continue   # line was blank or only comments.
        (first_token, key_to_value) = x
        # the next call will raise an easy-to-understand exception if
        # it fails.
        this_layer = parsed_line_to_xconfig_layer(first_token,
                                                  key_to_value,
                                                  all_layers)
        all_layers.append(this_layer)
    if len(all_layers) == 0:
        raise xparser_error("{0}: xconfig file '{1}' is empty".format(
            sys.argv[0], xconfig_filename))
    f.close()
    return all_layers
Esempio n. 2
0
def read_xconfig_file(xconfig_filename):
    try:
        f = open(xconfig_filename, 'r')
    except Exception as e:
        sys.exit("{0}: error reading xconfig file '{1}'; error was {2}".format(
            sys.argv[0], xconfig_filename, repr(e)))
    all_layers = []
    while True:
        line = f.readline()
        if line == '':
            break
        x = xutils.parse_config_line(line)
        if x is None:
            continue  # line was blank or only comments.
        (first_token, key_to_value) = x
        # the next call will raise an easy-to-understand exception if
        # it fails.
        this_layer = parsed_line_to_xconfig_layer(first_token, key_to_value,
                                                  all_layers)
        all_layers.append(this_layer)
    if len(all_layers) == 0:
        raise xparser_error("{0}: xconfig file '{1}' is empty".format(
            sys.argv[0], xconfig_filename))
    f.close()
    return all_layers
Esempio n. 3
0
def xconfig_line_to_object(config_line, prev_layers = None):
    try:
        x  = xutils.parse_config_line(config_line)
        if x is None:
            return None
        (first_token, key_to_value) = x
        if not config_to_layer.has_key(first_token):
            raise RuntimeError("No such layer type '{0}'".format(first_token))
        return config_to_layer[first_token](first_token, key_to_value, prev_layers)
    except Exception as e:
        print("***Exception caught while parsing the following xconfig line:\n"
              "*** {0}".format(config_line), file=sys.stderr)
        raise e
Esempio n. 4
0
def xconfig_line_to_object(config_line, prev_layers = None):
    try:
        x  = xutils.parse_config_line(config_line)
        if x is None:
            return None
        (first_token, key_to_value) = x
        if not config_to_layer.has_key(first_token):
            raise RuntimeError("No such layer type '{0}'".format(first_token))
        return config_to_layer[first_token](first_token, key_to_value, prev_layers)
    except Exception as e:
        print("***Exception caught while parsing the following xconfig line:\n"
              "*** {0}".format(config_line), file=sys.stderr)
        raise e
Esempio n. 5
0
def xconfig_line_to_object(config_line, prev_layers = None):
    try:
        x  = xutils.parse_config_line(config_line)
        if x is None:
            return None
        (first_token, key_to_value) = x
        if not first_token in config_to_layer:
            raise RuntimeError("No such layer type '{0}'".format(first_token))
        return config_to_layer[first_token](first_token, key_to_value, prev_layers)
    except Exception:
        logging.error(
            "***Exception caught while parsing the following xconfig line:\n"
            "*** {0}".format(config_line))
        raise
Esempio n. 6
0
def xconfig_line_to_object(config_line, prev_layers = None):
    try:
        x  = xutils.parse_config_line(config_line)
        if x is None:
            return None
        (first_token, key_to_value) = x
        if not first_token in config_to_layer:
            raise RuntimeError("No such layer type '{0}'".format(first_token))
        return config_to_layer[first_token](first_token, key_to_value, prev_layers)
    except Exception:
        logging.error(
            "***Exception caught while parsing the following xconfig line:\n"
            "*** {0}".format(config_line))
        raise
Esempio n. 7
0
def xconfig_line_to_object(config_line, prev_layers = None):
    try:
        # print('--- (start) xconfig_line_to_object ---')
        # print(config_line, file=sys.stdout)
        # 去掉注释,将 config_line 变成 (string, dict) 的形式
        x = xutils.parse_config_line(config_line)
        # print(x, file=sys.stdout)
        # print('--- (end) xconfig_line_to_object ---')
        if x is None:
            return None
        (first_token, key_to_value) = x
        if not first_token in config_to_layer:
            raise RuntimeError("No such layer type '{0}'".format(first_token))
        # 在这里加上了其他的 config 项
        return config_to_layer[first_token](first_token, key_to_value, prev_layers)
    except Exception:
        logging.error(
            "***Exception caught while parsing the following xconfig line:\n"
            "*** {0}".format(config_line))
        raise
Esempio n. 8
0
def config_line_to_object(config_line, prev_names=None):
    (first_token, key_to_value) = xutils.parse_config_line(config_line)
    return parsed_line_to_xconfig_layer(first_token, key_to_value, prev_names)
Esempio n. 9
0
def config_line_to_object(config_line, prev_names = None):
    (first_token, key_to_value) = xutils.parse_config_line(config_line)
    return parsed_line_to_xconfig_layer(first_token, key_to_value, prev_names)