def loadTemplates(injectSection = None): global TEMPLATES TEMPLATES = {} parser = ConfigParser() parser.read('templates.conf') for sectionName in parser.sections(): TEMPLATES[sectionName] = Configlet(sectionName, dict(parser.items(sectionName)), injectSection)
def config(filename='database.ini', section='postgresql'): # create a parser parser = ConfigParser() # read config file parser.read(filename) # get section, default to postgresql db = {} if parser.has_section(section): params = parser.items(section) for param in params: db[param[0]] = param[1] else: raise Exception('Section {0} not found in the {1} file'.format( section, filename)) return db
class Config(object): """ Base config class definuje zakladni metody pro praci s konfiguracnim souborem. """ def __init__(self, config_name="flexipy/flexipy.conf"): self.conf = ConfigParser() #use resource management api to find flexipy.conf, see docs filename = resource_filename(Requirement.parse("flexipy"), config_name) # Open the file with the correct encoding try: with codecs.open(filename, 'r', encoding='utf-8') as f: self.conf.readfp(f) except IOError: raise ValueError('Konfiguracni soubor ' + config_name + ' neexistuje nebo jste uvedli spatnou cestu.') def get_section_list(self, section_name): """ Tato privatni metoda spracuje vsechny sekce v config filu na zaklade jmena sekce a vrati list obsahujici vsechny polozky. """ result_list = [] try: section_content = self.conf.items(section_name) for key, val in section_content: result_list.append(val) except NoSectionError: raise ValueError("Config file neobsahuje sekci " + section_name) return result_list def get_server_config(self): """ Tato metoda vrati dict obsahujici vsechna nastaveni tykajici se serveru. """ result = {} try: section_content = self.conf.items("server") for key, val in section_content: result[key] = val except NoSectionError: raise ValueError("Config file neobsahuje sekci server") return result def get_evidence_list(self): return self.get_section_list('evidence') def get_typy_faktury_prijate(self): return self.get_section_list('typ_faktury_prijate') def get_typy_faktury_vydane(self): return self.get_section_list('typ_faktury_vydane') def get_typ_bank_dokladu(self): return self.get_section_list('typ_bank_dokladu') def get_typ_pohybu(self): return self.get_section_list('typ_pohybu') def get_bankovni_ucty(self): return self.get_section_list('bankovni_ucty') def get_typ_polozky_vydane(self): return self.get_section_list('typ_polozky_vydane') def get_typ_ucetni_operace(self): return self.get_section_list('typ_ucetni_operace') def get_typ_pokladni_pohyb(self): return self.get_section_list('typ_pokladni_pohyb') def get_typ_pokladna(self): return self.get_section_list('typ_pokladna')