def i3status_config_reader(self, i3status_config_path):
        """
        Parse i3status.conf so we can adapt our code to the i3status config.
        """
        config = {
            'general': {
                'color_bad': '#FF0000',
                'color_degraded': '#FFFF00',
                'color_good': '#00FF00',
                'color_separator': '#333333',
                'colors': False,
                'interval': 5,
                'output_format': 'i3bar'
            },
            'i3s_modules': [],
            'on_click': {},
            'order': [],
            '.group_extras': [],  # extra i3status modules needed by groups
            '.module_groups': {},  # record groups that modules are in
            'py3_modules': []
        }

        # some ugly parsing
        in_section = False
        section_name = ''
        group_name = None

        for line in open(i3status_config_path, 'r'):
            line = line.strip(' \t\n\r')

            if not line or line.startswith('#'):
                continue

            if line.startswith('order'):
                in_section = True
                section_name = 'order'

            if not in_section and line.startswith('group'):
                group_name = line.split('{')[0].strip()
                config[group_name] = {'items': []}
                continue

            if not in_section and group_name and line == '}':
                group_name = None
                continue

            if group_name and not in_section and '=' in line:
                # check this is not a section definition
                if '{' not in line or line.index('{') > line.index('='):
                    key = line.split('=', 1)[0].strip()
                    key = self.eval_config_parameter(key)
                    value = line.split('=', 1)[1].strip()
                    value = self.eval_config_value(value)
                    if not key.startswith('on_click'):
                        config[group_name][key] = value
                    else:
                        # on_click special parameters
                        try:
                            button = int(key.split()[1])
                            if button not in range(1, 6):
                                raise ValueError('should be 1, 2, 3, 4 or 5')
                        except IndexError as e:
                            raise IndexError(
                                'missing "button id" for "on_click" '
                                'parameter in group {}'.format(group_name))
                        except ValueError as e:
                            raise ValueError('invalid "button id" '
                                             'for "on_click" parameter '
                                             'in group {} ({})'.format(
                                                 group_name, e))
                        on_c = config['on_click']
                        on_c[group_name] = on_c.get(group_name, {})
                        on_c[group_name][button] = value
                    continue

            if not in_section:
                section_name = line.split('{')[0].strip()
                section_name = self.eval_config_parameter(section_name)
                if not section_name:
                    continue
                else:
                    in_section = True
                    if section_name not in config:
                        config[section_name] = {}
                    if group_name:
                        # update the items in the group
                        config[group_name]['items'].append(section_name)
                        section = config['.module_groups'].setdefault(section_name, [])
                        if group_name not in section:
                            section.append(group_name)
                        if not self.valid_config_param(section_name):
                            # py3status module add a reference to the group and
                            # make sure we have it in the list of modules to
                            # run
                            if section_name not in config['py3_modules']:
                                config['py3_modules'].append(section_name)
                        else:
                            # i3status module.  Add to the list of needed
                            # modules and add to the `.group-extras` config to
                            # ensure that it gets run even though not in
                            # `order` config
                            if section_name not in config['i3s_modules']:
                                config['i3s_modules'].append(section_name)
                            if section_name not in config['.group_extras']:
                                config['.group_extras'].append(section_name)

            if '{' in line:
                in_section = True

            if section_name and '=' in line:
                section_line = line

                # one liner cases
                if line.endswith('}'):
                    section_line = section_line.split('}', -1)[0].strip()
                if line.startswith(section_name + ' {'):
                    section_line = section_line.split(section_name + ' {')[
                        1].strip()

                key = section_line.split('=', 1)[0].strip()
                key = self.eval_config_parameter(key)

                value = section_line.split('=', 1)[1].strip()
                value = self.eval_config_value(value)

                if section_name == 'order':
                    config[section_name].append(value)
                    line = '}'

                    # create an empty config for this module
                    if value not in config:
                        config[value] = {}

                    # detect internal modules to be loaded dynamically
                    if not self.valid_config_param(value):
                        config['py3_modules'].append(value)
                    else:
                        config['i3s_modules'].append(value)
                else:
                    if not key.startswith('on_click'):
                        config[section_name][key] = value
                    else:
                        # on_click special parameters
                        try:
                            button = int(key.split()[1])
                            if button not in range(1, 6):
                                raise ValueError('should be 1, 2, 3, 4 or 5')
                        except IndexError as e:
                            raise IndexError(
                                'missing "button id" for "on_click" '
                                'parameter in section {}'.format(section_name))
                        except __HOLE__ as e:
                            raise ValueError('invalid "button id" '
                                             'for "on_click" parameter '
                                             'in section {} ({})'.format(
                                                 section_name, e))
                        on_c = config['on_click']
                        on_c[section_name] = on_c.get(section_name, {})
                        on_c[section_name][button] = value

            if line.endswith('}'):
                in_section = False
                section_name = ''

        # py3status only uses the i3bar protocol because it needs JSON output
        if config['general']['output_format'] != 'i3bar':
            raise RuntimeError('i3status output_format should be set' +
                               ' to "i3bar" on {}'.format(
                                   i3status_config_path,
                                   ' or on your own {}/.i3status.conf'.format(
                                       os.path.expanduser(
                                           '~')) if i3status_config_path ==
                                   '/etc/i3status.conf' else ''))

        # time and tztime modules need a format for correct processing
        for name in config:
            if name.split()[0] in TIME_MODULES and 'format' not in config[
                    name]:
                if name.split()[0] == 'time':
                    config[name]['format'] = TIME_FORMAT
                else:
                    config[name]['format'] = TZTIME_FORMAT

        def clean_i3status_modules(key):
            # cleanup unconfigured i3status modules that have no default
            for module_name in deepcopy(config[key]):
                if (self.valid_config_param(module_name,
                                            cleanup=True) and
                        not config.get(module_name)):
                    config.pop(module_name)
                    if module_name in config['i3s_modules']:
                        config['i3s_modules'].remove(module_name)
                    config[key].remove(module_name)

        clean_i3status_modules('order')
        clean_i3status_modules('.group_extras')
        return config
dataset/ETHPy150Open ultrabug/py3status/py3status/i3status.py/I3status.i3status_config_reader