Package fliesclient :: Module parseconfig
[hide private]
[frames] | no frames]

Source Code for Module fliesclient.parseconfig

 1  #  
 2  # Flies Python Client 
 3  # 
 4  # Copyright (c) 2010 Jian Ni <jni@redhat.com> 
 5  # Copyright (c) 2010 Red Hat, Inc. 
 6  # 
 7  # This library is free software; you can redistribute it and/or 
 8  # modify it under the terms of the GNU Lesser General Public 
 9  # License as published by the Free Software Foundation; either 
10  # version 2 of the License, or (at your option) any later version. 
11  # 
12  # This library is distributed in the hope that it will be useful, 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
15  # GNU Lesser General Public License for more details. 
16  # 
17  # You should have received a copy of the GNU Lesser General Public 
18  # License along with this program; if not, write to the 
19  # Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
20  # Boston, MA  02111-1307  USA 
21   
22  __all__ = ( 
23          "FliesConfig", 
24      ) 
25   
26  import ConfigParser 
27  import os.path 
28   
29 -class FliesConfig:
30 - def __init__(self):
31 projectconfig = "./.fliesrc" 32 userconfig = "~/.fliesrc" 33 self.configparser = ConfigParser.ConfigParser() 34 self._config = self.configparser.read([projectconfig, os.path.expanduser(userconfig)])
35
36 - def get_value(self, name, section, default_value = None):
37 if self._config: 38 try: 39 value = self.configparser.get(section, name) 40 return value 41 except ConfigParser.NoOptionError, NoSectionError: 42 return default_value 43 else: 44 return default_value
45
46 - def get_config_value(self, name, default_value = None):
47 return self.get_value(name, 'Config', default_value)
48