forked from pettazz/pygooglevoice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconf.py
More file actions
53 lines (42 loc) · 1.48 KB
/
conf.py
File metadata and controls
53 lines (42 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from ConfigParser import ConfigParser, NoOptionError
import os
import settings
class Config(ConfigParser):
"""
``ConfigParser`` subclass that looks into your home folder for a file named
``.gvoice`` and parses configuration data from it.
"""
def __init__(self):
self.fname = os.path.expanduser('~/.gvoice')
if not os.path.exists(self.fname):
try:
with open(self.fname, 'w') as f:
f.write(settings.DEFAULT_CONFIG)
except IOError:
return
ConfigParser.__init__(self)
try:
self.read([self.fname])
except IOError:
return
def get(self, option, section='gvoice'):
try:
return ConfigParser.get(self, section, option).strip() or None
except NoOptionError:
return
def set(self, option, value, section='gvoice'):
return ConfigParser.set(self, section, option, value)
def phoneType(self):
try:
return int(self.get('phoneType'))
except TypeError:
return
def save(self):
with open(self.f, 'w') as f:
f.write(f)
phoneType = property(phoneType)
forwardingNumber = property(lambda self: self.get('forwardingNumber'))
email = property(lambda self: self.get('email', 'auth'))
password = property(lambda self: self.get('password', 'auth'))
MFAKey = property(lambda self: self.get('MFAKey', 'auth'))
config = Config()