コード例 #1
0
def generate():
    # Read configs
    cfg_files = glob(CFGFILES)
    parser = RawConfigParser()

    for cfg_file in cfg_files:
        subsystem = os.path.basename(os.path.dirname(cfg_file))
        if not subsystem:
            subsystem = 'Unknown'

        inner_parser = RawConfigParser()
        inner_parser.read(unicode(cfg_file))
        for section in inner_parser.sections():
            parser[section] = inner_parser[section]
            parser[section]['subsystem'] = subsystem

    # Generate JS configuration
    with open(
            '/afs/cern.ch/user/b/battilan/public/forAndrius/collections_2017.json'
    ) as json_file:
        data = json.load(json_file)

        # Filter out non Muon keys
        keys = [x for x in data.keys() if 'muon' in x.lower()]

        parser_keys = parser.keys()
        parser_keys_lower = [k.lower() for k in parser.keys()]

        for key in keys:
            for config in data[key]:
                if len(config['files']) > 1:
                    section_title = ('plot:%s' % config['files'][0]).lower()
                    if section_title in parser_keys_lower:
                        # ConfigParser is case sensitive so we have to arrays.
                        # In first one we search and we use the value of the original
                        # section to get it
                        key_index = parser_keys_lower.index(section_title)
                        original_key = parser_keys[key_index]
                        section = parser[original_key]

                        print('\t\t{')
                        print('\t\t\tname: "%s",' % config['name'])
                        print('\t\t\tplot_title: "%s",' % config['name'])
                        print('\t\t\ty_title: "%s",' % section['yTitle'])
                        print('\t\t\tsubsystem: "%s",' % section['subsystem'])
                        print('\t\t\tcorrelation: %s,' %
                              str(config['corr']).lower())
                        print('\t\t\tseries: [%s],' %
                              ', '.join(['"%s"' % x for x in config['files']]))
                        print('\t\t},')
コード例 #2
0
ファイル: build_site.py プロジェクト: ryanvilbrandt/comic_git
def read_info(filepath, to_dict=False):
    with open(filepath, "rb") as f:
        info_string = f.read().decode("utf-8")
    if not re.search(r"^\[.*?]", info_string):
        # print(filepath + " has no section")
        info_string = "[DEFAULT]\n" + info_string
    info = RawConfigParser()
    info.optionxform = str
    info.read_string(info_string)
    if to_dict:
        # TODO: Support multiple sections
        if not list(info.keys()) == ["DEFAULT"]:
            raise NotImplementedError("Configs with multiple sections not yet supported")
        return dict(info["DEFAULT"])
    return info
コード例 #3
0
ファイル: build_site.py プロジェクト: inkybird/solid-doodle
def read_info(filepath, to_dict=False, might_be_scheduled=True):
    if might_be_scheduled and not isfile(filepath):
        scheduled_files = glob(filepath + ".*")
        if not scheduled_files:
            raise FileNotFoundError(filepath)
        filepath = scheduled_files[0]
    with open(filepath) as f:
        info_string = f.read()
    if not re.search(r"^\[.*?\]", info_string):
        # print(filepath + " has no section")
        info_string = "[DEFAULT]\n" + info_string
    info = RawConfigParser()
    info.optionxform = str
    info.read_string(info_string)
    if to_dict:
        # TODO: Support multiple sections
        if not list(info.keys()) == ["DEFAULT"]:
            raise NotImplementedError(
                "Configs with multiple sections not yet supported")
        return dict(info["DEFAULT"])
    return info