-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpybit_web.py
executable file
·68 lines (60 loc) · 2.69 KB
/
pybit_web.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
#!/usr/bin/python
# pybit-web
# Copyright 2012:
#
# Nick Davidson <[email protected]>,
# Simon Haswell <[email protected]>,
# Neil Williams <[email protected]>,
# James Bennet <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
from pybitweb.db import Database
from pybitweb.controller import Controller
import optparse
import pybitweb
import bottle
import pybit
import logging
import sys
META="PYBIT_WEB_"
if __name__ == '__main__':
parser = optparse.OptionParser()
#options we can override in the config file.
groupConfigFile = optparse.OptionGroup(parser,
"Config File Defaults","All the options which have defaults read from a config file.")
parser.add_option_group(groupConfigFile)
parser.add_option_group(groupConfigFile)
parser.add_option("--config", dest="config", default="web/web.conf",
help="Config file to read settings from, defaults to web.conf which will be read from configs/ and /etc/pybit/ in turn.",
metavar=META + "CONF_FILE")
parser.add_option("-v", dest="verbose", action="store_true", default=False,
help="Turn on verbose messages.", metavar=META+"VERBOSE")
(options, args) = parser.parse_args()
(settings, opened_file) = pybit.load_settings(options.config)
settings = pybit.merge_options(settings, groupConfigFile, options)
FORMAT = '%(asctime)s %(filename)s:%(lineno)d %(msg)s'
logging.basicConfig( stream=sys.stderr, level=logging.WARN)
logging.basicConfig( format=FORMAT )
myDb = Database(settings['db']) # singleton instance
buildController = Controller(settings, myDb) # singleton instance - Needs access to both controller and web settings
# try:
app = pybitweb.get_app(settings, myDb, buildController)
bottle.debug(options.verbose)
bottle.run(app=app,
server=settings['web']['app'],
host=settings['web']['interface'],
port=settings['web']['port'],
reloader=settings['web']['reloader'])