Пример #1
0
    def _reload_options(self):
        try:
            self.ctime = os.stat(self.cpath).st_mtime
            cfg = ConfigParser()
            cfg.read(self.cpath)
        except OSError:
            raise ConfigFileNotFoundError(self.cpath, source="default config")

        sections = cfg.sections()

        if len(sections) < 1:
            raise ImproperConfigFileError(self.cpath, _(u"%s should have at least one section" % self.cpath))

        options = Struct()
        options.main = mainsect = dict(cfg.items("main"))
        options.sections = sections

        ## 		if not(options.has_key("module") ^ options.has_key("path")):
        ## 			raise ImproperConfigFileError(self.cpath,
        ## 					_(u"%s should have a ``module`` or ``path`` option, but not both" % self.cpath))

        if not (mainsect.has_key("module") ^ mainsect.has_key("path")):
            raise ImproperConfigFileError(
                self.cpath, _(u"%s should have a ``module`` or ``path`` option, but not both" % self.cpath)
            )

        for sectname in sections[1:]:
            options[sectname] = dict(cfg.items(sectname))

        self.hotplug = mainsect.get("hotplug", False)
        self.module = mainsect.get("module", None)
        self.mpath = mainsect.get("path", "")
        self.class_ = mainsect.get("class", "")

        return options