Skip to content

Commit 4e39cc9

Browse files
author
Alexander Smishlajev
committed
rearranged to use the code in roundup-demo script.
fix install_demo: config.ini was written in current directory, not in the tracker home
1 parent 39c81a2 commit 4e39cc9

File tree

1 file changed

+41
-29
lines changed

1 file changed

+41
-29
lines changed

demo.py

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@
22
#
33
# Copyright (c) 2003 Richard Jones ([email protected])
44
#
5-
# $Id: demo.py,v 1.18 2004-10-08 00:18:27 richard Exp $
5+
# $Id: demo.py,v 1.19 2004-10-18 07:46:59 a1s Exp $
66

77
import sys, os, string, re, urlparse, ConfigParser
88
import shutil, socket, errno, BaseHTTPServer
99
from glob import glob
1010

11-
def install_demo(home, backend):
12-
from roundup import init, instance, password, backends, configuration
11+
from roundup import configuration
12+
from roundup.scripts import roundup_server
13+
14+
def install_demo(home, backend, template):
15+
"""Install a demo tracker
16+
17+
Parameters:
18+
home:
19+
tracker home directory path
20+
backend:
21+
database backend name
22+
template:
23+
full path to the tracker template directory
24+
25+
"""
26+
from roundup import init, instance, password, backends
1327

1428
# set up the config for this tracker
1529
config = configuration.CoreConfig()
@@ -27,7 +41,7 @@ def install_demo(home, backend):
2741
if module.db_exists(config):
2842
module.db_nuke(config)
2943

30-
init.install(home, os.path.join('templates', 'classic'))
44+
init.install(home, template)
3145
# don't have email flying around
3246
os.remove(os.path.join(home, 'detectors', 'nosyreaction.py'))
3347
try:
@@ -60,7 +74,7 @@ def install_demo(home, backend):
6074

6175
# write the config
6276
config['INSTANT_REGISTRATION'] = 1
63-
config.save()
77+
config.save(os.path.join(home, config.INI_FILE))
6478

6579
# open the tracker and initialise
6680
tracker = instance.open(home)
@@ -73,39 +87,37 @@ def install_demo(home, backend):
7387
db.commit()
7488
db.close()
7589

76-
def run_demo():
77-
''' Run a demo server for users to play with for instant gratification.
78-
79-
Sets up the web service on localhost. Disables nosy lists.
80-
'''
81-
home = os.path.abspath('demo')
82-
backend = 'anydbm'
83-
if not os.path.exists(home) or sys.argv[-1] == 'nuke':
84-
if len(sys.argv) > 2:
85-
backend = sys.argv[-2]
86-
install_demo(home, backend)
87-
88-
cfg = ConfigParser.ConfigParser()
89-
cfg.read(os.path.join(home, 'config.ini'))
90-
url = cfg.get('tracker', 'web')
91-
hostname, port = urlparse.urlparse(url)[1].split(':')
92-
port = int(port)
93-
94-
# ok, so start up the server
95-
from roundup.scripts import roundup_server
90+
def run_demo(home):
91+
"""Run the demo tracker installed in ``home``"""
9692
roundup_server.RoundupRequestHandler.TRACKER_HOMES = {'demo': home}
97-
93+
cfg = configuration.CoreConfig(home)
9894
success_message = '''Server running - connect to:
9995
%s
10096
1. Log in as "demo"/"demo" or "admin"/"admin".
10197
2. Hit Control-C to stop the server.
10298
3. Re-start the server by running "python demo.py" again.
103-
4. Re-initialise the server by running "python demo.py nuke".''' % url
99+
4. Re-initialise the server by running "python demo.py nuke".
100+
''' % cfg["TRACKER_WEB"]
104101

102+
# disable command line processing in roundup_server
105103
sys.argv = sys.argv[:1]
106-
roundup_server.run(port, success_message)
104+
roundup_server.run(success_message=success_message)
105+
106+
def demo_main():
107+
"""Run a demo server for users to play with for instant gratification.
108+
109+
Sets up the web service on localhost. Disables nosy lists.
110+
"""
111+
home = os.path.abspath('demo')
112+
if not os.path.exists(home) or (sys.argv[-1] == 'nuke'):
113+
if len(sys.argv) > 2:
114+
backend = sys.argv[-2]
115+
else:
116+
backend = 'anydbm'
117+
install_demo(home, backend, os.path.join('templates', 'classic'))
118+
run_demo(home)
107119

108120
if __name__ == '__main__':
109-
run_demo()
121+
demo_main()
110122

111123
# vim: set filetype=python sts=4 sw=4 et si :

0 commit comments

Comments
 (0)