22#
33# Copyright (c) 2003 Richard Jones ([email protected] ) 44#
5- # $Id: demo.py,v 1.12 2004-07-27 00:57:17 richard Exp $
5+ # $Id: demo.py,v 1.13 2004-07-27 01:59:27 richard Exp $
66
77import sys , os , string , re , urlparse
88import shutil , socket , errno , BaseHTTPServer
99from glob import glob
1010
1111def install_demo (home , backend ):
12- # create the instance
13- if os .path .exists (home ):
14- shutil .rmtree (home )
15- from roundup import init , instance , password , backends
12+ from roundup import init , instance , password , backends , configuration
13+
14+ # set up the config for this tracker
15+ config = configuration .Config ()
16+ config ['TRACKER_HOME' ] = home
17+ config ['MAIL_DOMAIN' ] = 'localhost'
18+ config ['DATABASE' ] = 'db'
19+ if backend in ('mysql' , 'postgresql' ):
20+ config ['RDBMS_HOST' ] = 'localhost'
21+ config ['RDBMS_USER' ] = 'rounduptest'
22+ config ['RDBMS_PASSWORD' ] = 'rounduptest'
23+ config ['RDBMS_NAME' ] = 'rounduptest'
1624
1725 # see if we have further db nuking to perform
1826 module = getattr (backends , backend )
19- if backend == 'mysql' :
20- class config :
21- MYSQL_DBHOST = 'localhost'
22- MYSQL_DBUSER = 'rounduptest'
23- MYSQL_DBPASSWORD = 'rounduptest'
24- MYSQL_DBNAME = 'rounduptest'
25- DATABASE = 'home'
26- if module .db_exists (config ):
27- module .db_nuke (config )
28- elif backend == 'postgresql' :
29- class config :
30- POSTGRESQL_DATABASE = 'rounduptest'
31- DATABASE = 'home'
32- if module .db_exists (config ):
33- module .db_nuke (config )
27+ if module .db_exists (config ):
28+ module .db_nuke (config )
3429
3530 init .install (home , os .path .join ('templates' , 'classic' ))
3631 # don't have email flying around
@@ -61,31 +56,16 @@ class config:
6156 s .close ()
6257 print 'already in use.'
6358 port += 100
64- url = 'http://%s:%s/demo/' % (hostname , port )
59+ config [ 'TRACKER_WEB' ] = 'http://%s:%s/demo/' % (hostname , port )
6560
6661 # write the config
67- f = open (os .path .join (home , 'config.py' ), 'r' )
68- s = f .read ().replace ('http://tracker.example/cgi-bin/roundup.cgi/bugs/' ,
69- url )
70- f .close ()
71- # DB connection stuff for mysql and postgresql
72- s = s + """
73- MYSQL_DBHOST = 'localhost'
74- MYSQL_DBUSER = 'rounduptest'
75- MYSQL_DBPASSWORD = 'rounduptest'
76- MYSQL_DBNAME = 'rounduptest'
77- MYSQL_DATABASE = (MYSQL_DBHOST, MYSQL_DBUSER, MYSQL_DBPASSWORD, MYSQL_DBNAME)
78- POSTGRESQL_DATABASE = {'database': 'rounduptest'}
79- """
80- f = open (os .path .join (home , 'config.py' ), 'w' )
81- f .write (s )
82- f .close ()
62+ config .save ()
8363
84- # initialise the database
85- init .initialise (home , 'admin' )
64+ # open the tracker and initialise
65+ tracker = instance .open (home )
66+ tracker .init (password .Password ('admin' ))
8667
8768 # add the "demo" user
88- tracker = instance .open (home )
8969 db = tracker .open ('admin' )
9070 db .user .create (username = 'demo' , password = password .Password ('demo' ),
9171 realname = 'Demo User' , roles = 'User' )
@@ -104,8 +84,8 @@ def run_demo():
10484 backend = sys .argv [1 ]
10585 install_demo (home , backend )
10686
107- f = open (os .path .join (home , 'config.py ' ), 'r' )
108- url = re .search (r'^TRACKER_WEB \s*=\s*[\'"] (http.+/)[\'"] $' , f .read (),
87+ f = open (os .path .join (home , 'config.ini ' ), 'r' )
88+ url = re .search (r'^web \s*=\s*(http.+/)$' , f .read (),
10989 re .M | re .I ).group (1 )
11090 f .close ()
11191 hostname , port = urlparse .urlparse (url )[1 ].split (':' )
0 commit comments