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