diff options
author | Ian Weller <ianweller@gmail.com> | 2008-11-06 20:02:32 -0600 |
---|---|---|
committer | Ian Weller <ianweller@gmail.com> | 2008-11-06 20:02:32 -0600 |
commit | 7160f64fd2d506d5f9021ed6639805e9af7ce357 (patch) | |
tree | 3b0007b10c54db5dc10c8100ce279671f5bc473f /fedora_business_cards/config.py | |
parent | 6a3752bf45daead85162f4b1469f8de1747f7ae2 (diff) | |
download | fedora-business-cards-7160f64fd2d506d5f9021ed6639805e9af7ce357.tar.gz fedora-business-cards-7160f64fd2d506d5f9021ed6639805e9af7ce357.tar.xz fedora-business-cards-7160f64fd2d506d5f9021ed6639805e9af7ce357.zip |
Use configuration file to determine templates
Diffstat (limited to 'fedora_business_cards/config.py')
-rw-r--r-- | fedora_business_cards/config.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/fedora_business_cards/config.py b/fedora_business_cards/config.py index 61b1a32..b88d6f2 100644 --- a/fedora_business_cards/config.py +++ b/fedora_business_cards/config.py @@ -22,9 +22,34 @@ Controls the locations of configuration files, and imports configurations from all those files in a specific order. """ -import iniparse +from iniparse import ConfigParser import os + +def available_templates(config): + """ + Takes the main ConfigParser as the argument. + """ + templates_dir = config.get('location', 'templates') + templates = ConfigParser() + templates.read(templates_dir+"/templates.ini") + filelist = os.listdir(templates_dir) + for section in templates.sections(): + if templates.options(section) == ["humandesc", "front", "back", "type"]: + if templates.get(section, "front") in filelist: + if templates.get(section, "back") in filelist: + # only SVG templates are currently supported + if templates.get(section, "type") == "svg": + continue + elif templates.options(section) == ["humandesc", "front", "type"]: + if templates.get(section, "front") in filelist: + # only SVG templates are currently supported + if templates.get(section, "type") == "svg": + continue + templates.remove_section(section) + return templates + + # locations, in reverse-order of priority LOCATIONS = ['/'.join(__file__.split('/')[:-1]+['config.ini']), 'config.ini', # in current working directory @@ -32,10 +57,9 @@ LOCATIONS = ['/'.join(__file__.split('/')[:-1]+['config.ini']), '/etc/fedora-business-cards.ini', os.getenv('HOME')+'/.fedora-business-cards.ini'] -parser = iniparse.ConfigParser() - -# import the configs +parser = ConfigParser() for i in LOCATIONS: parser.read(i) -__all__ = ('parser') + +__all__ = ('parser', 'available_templates') |