| 1 | #!/usr/bin/python |
|---|
| 2 | # -*- coding: UTF-8 -*- |
|---|
| 3 | # |
|---|
| 4 | # Copyright (c) 2006 Tarek Ziadé <tarek@ziade.org> |
|---|
| 5 | # |
|---|
| 6 | # This program is free software; you can redistribute it and/or |
|---|
| 7 | # modify it under the terms of the GNU General Public License |
|---|
| 8 | # as published by the Free Software Foundation; either version 2 |
|---|
| 9 | # of the License, or (at your option) any later version. |
|---|
| 10 | # |
|---|
| 11 | # This program is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | # GNU General Public License for more details. |
|---|
| 15 | # |
|---|
| 16 | # You should have received a copy of the GNU General Public License |
|---|
| 17 | # along with this program; if not, write to the Free Software |
|---|
| 18 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | # $Id: $ |
|---|
| 20 | """ Configuration reader |
|---|
| 21 | """ |
|---|
| 22 | import os |
|---|
| 23 | from ConfigParser import ConfigParser |
|---|
| 24 | |
|---|
| 25 | class Configuration(object): |
|---|
| 26 | """loads a config file""" |
|---|
| 27 | |
|---|
| 28 | def __init__(self, filename): |
|---|
| 29 | self._filename = filename |
|---|
| 30 | self._config = ConfigParser() |
|---|
| 31 | self._config.read([filename]) |
|---|
| 32 | |
|---|
| 33 | def _getItems(self, name): |
|---|
| 34 | """return a mapping for a given section""" |
|---|
| 35 | result = {} |
|---|
| 36 | for name, value in self._config.items(name): |
|---|
| 37 | result[name] = value |
|---|
| 38 | return result |
|---|
| 39 | |
|---|
| 40 | def _getRecipes(self): |
|---|
| 41 | """returns recipe list""" |
|---|
| 42 | return self._getItems('recipes') |
|---|
| 43 | recipes = property(_getRecipes) |
|---|
| 44 | |
|---|
| 45 | def _getPackages(self): |
|---|
| 46 | """returns packages list""" |
|---|
| 47 | return self._getItems('packages') |
|---|
| 48 | packages = property(_getPackages) |
|---|
| 49 | |
|---|
| 50 | def _getTutorials(self): |
|---|
| 51 | """returns tutorial list""" |
|---|
| 52 | return self._getItems('tutorials') |
|---|
| 53 | tutorials = property(_getTutorials) |
|---|
| 54 | |
|---|
| 55 | def _getGlossary(self): |
|---|
| 56 | """returns glossary""" |
|---|
| 57 | return self._getItems('options')['glossary'] |
|---|
| 58 | glossary = property(_getGlossary) |
|---|
| 59 | |
|---|
| 60 | def _getMedia(self): |
|---|
| 61 | """returns media""" |
|---|
| 62 | return self._getItems('options')['media'] |
|---|
| 63 | media = property(_getMedia) |
|---|
| 64 | |
|---|
| 65 | def _getTargets(self): |
|---|
| 66 | """returns targets""" |
|---|
| 67 | return self._getItems('targets') |
|---|
| 68 | targets = property(_getTargets) |
|---|
| 69 | |
|---|
| 70 | def _getTemplates(self): |
|---|
| 71 | """returns templates""" |
|---|
| 72 | return self._getItems('templates') |
|---|
| 73 | templates = property(_getTemplates) |
|---|
| 74 | |
|---|
| 75 | def _getOptions(self): |
|---|
| 76 | """returns options""" |
|---|
| 77 | return self._getItems('options') |
|---|
| 78 | options = property(_getOptions) |
|---|