def get_home_currency(): if Globals.HOME_CURRENCY is None: config = SafeConfigParser() config.read(Globals.INI_FILE) if config.has_section("defaults") and config.has_option( "defaults", "home_currency"): hc = config.get("defaults", "home_currency") else: hc = guess_home_currency() if hc: set_home_currency(hc) Globals.HOME_CURRENCY = hc return Globals.HOME_CURRENCY
def get(self, section, prop): """get a value from rhsm config Args: section: config file section prop: what config propery to find, he config item name Returns: The string value of the config item. If config item exists, but is not set, an empty string is return. """ if not self.has_section(section): self.add_section(section) return SafeConfigParser.get(self, section, prop)
def __generate(self): if not os.path.exists(self.repofile): return [] config = SafeConfigParser() config.read(self.repofile) enabled_sections = [section for section in config.sections() if config.getboolean(section, "enabled")] enabled_repos = [] for section in enabled_sections: try: enabled_repos.append( { "repositoryid": section, "baseurl": [self._replace_vars(config.get(section, "baseurl"))] } ) except ImportError: break return enabled_repos
def get(self, section, prop): """Get a value from rhsm config. :param section: config file section :type section: str :param prop: what config propery to find, the config item name :type prop: str :return: The string value of the config item. :rtype: str If config item exists, but is not set, an empty string is return. """ try: return SafeConfigParser.get(self, section, prop) except InterpolationMissingOptionError: # if there is an interpolation error, resolve it raw_val = super(RhsmConfigParser, self).get(section, prop, True) interpolations = re.findall("%\((.*?)\)s", raw_val) changed = False for interp in interpolations: # Defaults aren't interpolated by default, so bake them in as necessary # has_option throws an exception if the section doesn't exist, but at this point we know it does if self.has_option(section, interp): super(RhsmConfigParser, self).set(section, interp, self.get(section, interp)) changed = True if changed: # Now that we have the required values, we can interpolate return self.get(section, prop) # If nothing has been changed (we couldn't fix it) re-raise the exception raise except (NoOptionError, NoSectionError) as er: try: return DEFAULTS[section][prop.lower()] except KeyError: # re-raise the NoOptionError, not the key error raise er
def get(self, section, prop): """Get a value from rhsm config. :param section: config file section :type section: str :param prop: what config propery to find, the config item name :type prop: str :return: The string value of the config item. :rtype: str If config item exists, but is not set, an empty string is return. """ try: return SafeConfigParser.get(self, section, prop) except InterpolationMissingOptionError: # if there is an interpolation error, resolve it raw_val = super(RhsmConfigParser, self).get(section, prop, True) interpolations = re.findall("%\((.*?)\)s", raw_val) changed = False for interp in interpolations: # Defaults aren't interpolated by default, so bake them in as necessary # has_option throws an exception if the section doesn't exist, but at this point we know it does if self.has_option(section, interp): super(RhsmConfigParser, self).set(section, interp, self.get(section, interp)) changed = True if changed: # Now that we have the required values, we can interpolate return self.get(section, prop) # If nothing has been changed (we couldn't fix it) re-raise the exception raise except (NoOptionError, NoSectionError), er: try: return DEFAULTS[section][prop.lower()] except KeyError: # re-raise the NoOptionError, not the key error raise er
def get(self, section, prop): if not self.has_section(section): self.add_section(section) return SafeConfigParser.get(self, section, prop)