This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
config.py
84 lines (64 loc) · 2.26 KB
/
config.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
import ConfigParser
from optparse import OptionParser
import os
import sys
from pyLibrary import convert
from pyLibrary.times.dates import Date
filename = 'config.ini'
db_host = 'database'
db_name = 'alerts'
maildir = '/var/spool/news/mozilla/dev/tree-alerts'
debug = 'true'
parser = OptionParser()
parser.add_option("-u", "--username",
type="string", default="root",
help="username for connecting to the sql server")
parser.add_option("-p", "--password",
type="string", default="",
help="password for connecting to the sql server")
def db_config():
(opts, args) = parser.parse_args()
with open(filename, 'w') as target:
target.write("[alerts]\n")
target.write("host = %s\n" % db_host)
target.write("database = %s\n" % db_name)
target.write("username = %s\n" % opts.username)
target.write("password = %s\n" % opts.password)
target.write("maildir = %s\n" % maildir)
target.write("debug = %s\n" % debug)
def get_config():
op = OptionParser()
op.add_option("--config",
action="store", type="string", dest="config",
default=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.ini'),
help="path to the config file [config.ini]")
options, args = op.parse_args()
if not os.path.exists(options.config):
print "ERROR: %s doesn't exist" % (os.path.abspath(options.config))
sys.exit(1)
parser = ConfigParser.RawConfigParser(defaults={'debug': 'false'})
parser.read(options.config)
def now():
return Date.eod().value
def today():
return Date.today().value
try:
const = CNV.string2datetime(parser.get('alerts', 'now'))
def now():
return const
today = now
except Exception:
pass
return {
'username': parser.get('alerts', 'username'),
'password': parser.get('alerts', 'password'),
'host': parser.get('alerts', 'host'),
'database': parser.get('alerts', 'database'),
'maildir': parser.get('alerts', 'maildir'),
'now': now,
'today': today,
'DEBUG': parser.getboolean('alerts', 'debug'),
}
if __name__ == '__main__':
db_config()