conf.py
Go to the documentation of this file.
00001 from ConfigParser import ConfigParser, NoOptionError
00002 import os
00003 import settings
00004 
00005 
00006 class Config(ConfigParser):
00007     """
00008     ``ConfigParser`` subclass that looks into your home folder for a file named
00009     ``.gvoice`` and parses configuration data from it.
00010     """
00011     def __init__(self):
00012         self.fname = os.path.expanduser('~/.gvoice')
00013 
00014         if not os.path.exists(self.fname):
00015             try:
00016                 f = open(self.fname, 'w')
00017             except IOError:
00018                 return
00019             f.write(settings.DEFAULT_CONFIG)
00020             f.close()
00021             
00022         ConfigParser.__init__(self)
00023         try:
00024             self.read([self.fname])
00025         except IOError:
00026             return
00027 
00028     def get(self, option, section='gvoice'):
00029         try:
00030             return ConfigParser.get(self, section, option).strip() or None
00031         except NoOptionError:
00032             return
00033         
00034     def set(self, option, value, section='gvoice'):
00035         return ConfigParser.set(self, section, option, value)
00036 
00037     def phoneType(self):
00038         try:
00039             return int(self.get('phoneType'))
00040         except TypeError:
00041             return
00042         
00043     def save(self):
00044         f = open(self.fname, 'w')
00045         self.write(f)
00046         f.close()
00047         
00048 
00049     phoneType = property(phoneType)
00050     forwardingNumber = property(lambda self: self.get('forwardingNumber'))
00051     email = property(lambda self: self.get('email','auth'))
00052     password = property(lambda self: self.get('password','auth'))
00053     secret = property(lambda self: self.get('secret'))
00054     
00055 config = Config()


continuous_ops_alerts
Author(s): Eitan Marder-Eppstein
autogenerated on Fri Dec 6 2013 19:59:13