1 |
eulisse |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
from Framework import BonsaiServer
|
3 |
eulisse |
1.2 |
from Framework import Context
|
4 |
|
|
from optparse import OptionParser
|
5 |
|
|
from Framework import CmdLineArgs
|
6 |
eulisse |
1.1 |
|
7 |
eulisse |
1.3 |
class Cfg:
|
8 |
|
|
def __init__ (self):
|
9 |
|
|
# TODO: make it a property.
|
10 |
|
|
self.installRoot = __file__.rsplit ("/", 1)[0]
|
11 |
|
|
|
12 |
eulisse |
1.1 |
if __name__ == '__main__':
|
13 |
eulisse |
1.2 |
context = Context ()
|
14 |
|
|
context.addService (OptionParser ())
|
15 |
|
|
context.OptionParser ().add_option ("--profile",
|
16 |
|
|
help="start server in profiler mode",
|
17 |
|
|
default=False,
|
18 |
|
|
action="store_true",
|
19 |
|
|
dest="profile")
|
20 |
|
|
|
21 |
|
|
context.OptionParser ().add_option ("--base-url",
|
22 |
|
|
help="Base URL for the server (for usage behind a proxy).",
|
23 |
|
|
default="http://localhost:8030",
|
24 |
|
|
dest="baseUrl")
|
25 |
|
|
|
26 |
|
|
app = BonsaiServer (context)
|
27 |
|
|
|
28 |
|
|
opts, args = context.OptionParser ().parse_args ()
|
29 |
|
|
context.addService (CmdLineArgs (context.OptionParser ()))
|
30 |
eulisse |
1.3 |
context.addService (Cfg ())
|
31 |
eulisse |
1.2 |
|
32 |
|
|
if opts.profile:
|
33 |
|
|
import pstats
|
34 |
|
|
try:
|
35 |
|
|
import cProfile as profile
|
36 |
|
|
except ImportError:
|
37 |
|
|
import profile
|
38 |
|
|
profile.run ('app.start ()', 'bonsaiProfiler')
|
39 |
|
|
|
40 |
|
|
p = pstats.Stats('bonsaiProfiler')
|
41 |
|
|
p.strip_dirs().sort_stats(-1).print_stats()
|
42 |
|
|
else:
|
43 |
|
|
app.start ()
|