usr bin env python enable demandloading to reduce startup time from me

 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
#!/usr/bin/env python
# enable demandloading to reduce startup time
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb.hgwebdir_mod import hgwebdir
from mercurial.hgweb.hgweb_mod import hgweb
import sys
from optparse import OptionParser
def main():
usage = 'usage: %prog [options] repo'
parser = OptionParser(usage)
parser.add_option('-c', '--config', default='',
help='name of the webdir config file')
parser.add_option('-a', '--address', default='0.0.0.0',
help='address to listen on (default: all interfaces)')
parser.add_option('-p', '--port', default=8000,
help='port to listen on (default: 8000)')
parser.add_option('-t', '--threads', default=2,
help='number of threads for server to use (default: 2)')
parser.add_option('', '--server_name', default='',
help='CherryPy\'s SERVER_NAME environ entry')
opts, args = parser.parse_args()
if not len(args) and not opts.config:
print "Either path to config or path to repository should be supplied"
sys.exit(1)
try:
from cherrypy.wsgiserver import CherryPyWSGIServer as Server
except ImportError:
try:
from wsgiserver import CherryPyWSGIServer as Server
except ImportError:
print "CherryPy's wsgiserver module not found"
sys.exit(1)
if opts.config:
app = hgwebdir(opts.config)
else:
app = hgweb(args[0])
server = Server((opts.address, int(opts.port)), app,
int(opts.threads), opts.server_name)
try:
server.start()
except KeyboardInterrupt:
server.stop()
if __name__ == '__main__':
main()