示例#1
0
文件: CfgJson.py 项目: GregAC/ibex
def _load_single_file(target, path, is_first, arg_keys):
    '''Load a single hjson file, merging its keys into target

    Returns a list of further includes that should be loaded.

    '''
    hjson = parse_hjson(path)
    if not isinstance(hjson, dict):
        raise RuntimeError(
            '{!r}: Top-level hjson object is not a dictionary.'.format(path))

    import_cfgs = []
    for key, dict_val in hjson.items():
        # If this key got set at the start of time and we want to ignore any
        # updates: ignore them!
        if key in arg_keys:
            continue

        # If key is 'import_cfgs', this should be a list. Add each item to the
        # list of cfgs to process
        if key == 'import_cfgs':
            if not isinstance(dict_val, list):
                raise RuntimeError('{!r}: import_cfgs value is {!r}, but '
                                   'should be a list.'.format(path, dict_val))
            import_cfgs += dict_val
            continue

        # 'use_cfgs' is a bit like 'import_cfgs', but is only used for primary
        # config files (where it is a list of the child configs). This
        # shouldn't be used except at top-level (the first configuration file
        # to be loaded).
        #
        # If defined, check that it's a list, but then allow it to be set in
        # the target dictionary as usual.
        if key == 'use_cfgs':
            if not is_first:
                raise RuntimeError('{!r}: File is included by another one, '
                                   'but defines "use_cfgs".'.format(path))
            if not isinstance(dict_val, list):
                raise RuntimeError(
                    '{!r}: use_cfgs must be a list. Saw {!r}.'.format(
                        path, dict_val))

        # Otherwise, update target with this attribute
        set_target_attribute(path, target, key, dict_val)

    # Expand the names of imported configuration files as we return them
    return [
        subst_wildcards(cfg_path,
                        target,
                        ignored_wildcards=[],
                        ignore_error=False) for cfg_path in import_cfgs
    ]
示例#2
0
    def _parse_cfg(self, path, is_entry_point):
        '''Load an hjson config file at path and update self accordingly.

        If is_entry_point is true, this is the top-level configuration file, so
        it's possible that this is a primary config.

        '''
        hjson_dict = parse_hjson(path)

        # Check if this is the primary cfg, if this is the entry point cfg file
        if is_entry_point:
            self.is_primary_cfg = self.check_if_primary_cfg(hjson_dict)

            # If not a primary cfg, then register self with self.cfgs
            if self.is_primary_cfg is False:
                self.cfgs.append(self)

        # Resolve the raw hjson dict to build this object
        self.resolve_hjson_raw(path, hjson_dict)
示例#3
0
文件: FlowCfg.py 项目: islengxw/ibex
    def parse_flow_cfg(self, flow_cfg_file, is_entry_point=True):
        '''
        Parse the flow cfg hjson file. This is a private API used within the
        extended class' __init__ function. This parses the hjson cfg (and
        imports / use cfgs) and builds an initial dictionary.

        This method takes 2 args.
        flow_cfg_file: This is the flow cfg file to be parsed.
        is_entry_point: the cfg file that is passed on the command line is
            the entry point cfg. If the cfg file is a part of an inport_cfgs
            or use_cfgs key, then it is not an entry point.
        '''
        hjson_dict = parse_hjson(flow_cfg_file)

        # Check if this is the master cfg, if this is the entry point cfg file
        if is_entry_point:
            self.is_master_cfg = self.check_if_master_cfg(hjson_dict)

            # If not a master cfg, then register self with self.cfgs
            if self.is_master_cfg is False:
                self.cfgs.append(self)

        # Resolve the raw hjson dict to build this object
        self.resolve_hjson_raw(hjson_dict)