Skip to content

Commit 88fe769

Browse files
committed
Allow command-line arguments for more flexible demo setup.
1 parent 29bd88d commit 88fe769

File tree

1 file changed

+51
-11
lines changed

1 file changed

+51
-11
lines changed

demo.py

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#
33
# Copyright (c) 2003 Richard Jones ([email protected])
44
#
5-
# $Id: demo.py,v 1.26 2007-08-28 22:37:45 jpend Exp $
65

76
import errno
87
import os
98
import socket
109
import sys
1110
import urlparse
1211
from glob import glob
12+
import getopt
1313

1414
from roundup import configuration
1515
from roundup.scripts import roundup_server
@@ -23,9 +23,10 @@ def install_demo(home, backend, template):
2323
backend:
2424
database backend name
2525
template:
26-
full path to the tracker template directory
26+
tracker template
2727
2828
"""
29+
2930
from roundup import init, instance, password, backends
3031

3132
# set up the config for this tracker
@@ -45,7 +46,8 @@ def install_demo(home, backend, template):
4546
if module.db_exists(config):
4647
module.db_nuke(config)
4748

48-
init.install(home, template)
49+
template_dir = os.path.join('share', 'roundup', 'templates', template)
50+
init.install(home, template_dir)
4951
# don't have email flying around
5052
os.remove(os.path.join(home, 'detectors', 'nosyreaction.py'))
5153
try:
@@ -116,21 +118,59 @@ def run_demo(home):
116118
sys.argv = sys.argv[:1] + ['-p', str(port), 'demo=' + home]
117119
roundup_server.run(success_message=success_message)
118120

119-
def demo_main():
121+
122+
def usage(msg = ''):
123+
124+
if msg: print msg
125+
print 'Usage: %s [options] [nuke]'%sys.argv[0]
126+
print """
127+
Options:
128+
-h -- print this help message
129+
-t template -- specify the tracker template to use
130+
-b backend -- specify the database backend to use
131+
"""
132+
133+
134+
def main():
120135
"""Run a demo server for users to play with for instant gratification.
121136
122137
Sets up the web service on localhost. Disables nosy lists.
123138
"""
139+
140+
try:
141+
opts, args = getopt.getopt(sys.argv[1:], 't:b:h')
142+
except getopt.GetoptError, e:
143+
usage(str(e))
144+
return 1
145+
124146
home = os.path.abspath('demo')
125-
if not os.path.exists(home) or (sys.argv[-1] == 'nuke'):
126-
if len(sys.argv) > 2:
127-
backend = sys.argv[-2]
128-
else:
129-
backend = 'anydbm'
130-
install_demo(home, backend, os.path.join('share', 'roundup', 'templates', 'classic'))
147+
nuke = args and args[0] == 'nuke'
148+
if not os.path.exists(home) or nuke:
149+
backend = 'anydbm'
150+
template = 'classic'
151+
for opt, arg in opts:
152+
if opt == '-h':
153+
usage()
154+
return 0
155+
elif opt == '-t':
156+
template = arg
157+
elif opt == '-b':
158+
backend = arg
159+
if (len(args) > 1 or
160+
(len(args) == 1 and args[0] != 'nuke')):
161+
usage()
162+
return 1
163+
164+
install_demo(home, backend, template)
165+
elif opts:
166+
print "Error: Arguments are not allowed when running an existing demo."
167+
print " Use the 'nuke' command to start over."
168+
sys.exit(1)
169+
131170
run_demo(home)
132171

172+
133173
if __name__ == '__main__':
134-
demo_main()
174+
sys.exit(main())
135175

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

0 commit comments

Comments
 (0)