Mercurial > p > roundup > code
comparison demo.py @ 2637:11811b313459
The demo.py script works again using the new configuration system.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 27 Jul 2004 01:59:28 +0000 |
| parents | a9e1fff1e793 |
| children | 75d410d11a20 |
comparison
equal
deleted
inserted
replaced
| 2636:943f9d4592b8 | 2637:11811b313459 |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2003 Richard Jones (richard@mechanicalcat.net) | 3 # Copyright (c) 2003 Richard Jones (richard@mechanicalcat.net) |
| 4 # | 4 # |
| 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 $ |
| 6 | 6 |
| 7 import sys, os, string, re, urlparse | 7 import sys, os, string, re, urlparse |
| 8 import shutil, socket, errno, BaseHTTPServer | 8 import shutil, socket, errno, BaseHTTPServer |
| 9 from glob import glob | 9 from glob import glob |
| 10 | 10 |
| 11 def install_demo(home, backend): | 11 def install_demo(home, backend): |
| 12 # create the instance | 12 from roundup import init, instance, password, backends, configuration |
| 13 if os.path.exists(home): | 13 |
| 14 shutil.rmtree(home) | 14 # set up the config for this tracker |
| 15 from roundup import init, instance, password, backends | 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' | |
| 16 | 24 |
| 17 # see if we have further db nuking to perform | 25 # see if we have further db nuking to perform |
| 18 module = getattr(backends, backend) | 26 module = getattr(backends, backend) |
| 19 if backend == 'mysql': | 27 if module.db_exists(config): |
| 20 class config: | 28 module.db_nuke(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) | |
| 34 | 29 |
| 35 init.install(home, os.path.join('templates', 'classic')) | 30 init.install(home, os.path.join('templates', 'classic')) |
| 36 # don't have email flying around | 31 # don't have email flying around |
| 37 os.remove(os.path.join(home, 'detectors', 'nosyreaction.py')) | 32 os.remove(os.path.join(home, 'detectors', 'nosyreaction.py')) |
| 38 try: | 33 try: |
| 59 break | 54 break |
| 60 else: | 55 else: |
| 61 s.close() | 56 s.close() |
| 62 print 'already in use.' | 57 print 'already in use.' |
| 63 port += 100 | 58 port += 100 |
| 64 url = 'http://%s:%s/demo/'%(hostname, port) | 59 config['TRACKER_WEB'] = 'http://%s:%s/demo/'%(hostname, port) |
| 65 | 60 |
| 66 # write the config | 61 # write the config |
| 67 f = open(os.path.join(home, 'config.py'), 'r') | 62 config.save() |
| 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() | |
| 83 | 63 |
| 84 # initialise the database | 64 # open the tracker and initialise |
| 85 init.initialise(home, 'admin') | 65 tracker = instance.open(home) |
| 66 tracker.init(password.Password('admin')) | |
| 86 | 67 |
| 87 # add the "demo" user | 68 # add the "demo" user |
| 88 tracker = instance.open(home) | |
| 89 db = tracker.open('admin') | 69 db = tracker.open('admin') |
| 90 db.user.create(username='demo', password=password.Password('demo'), | 70 db.user.create(username='demo', password=password.Password('demo'), |
| 91 realname='Demo User', roles='User') | 71 realname='Demo User', roles='User') |
| 92 db.commit() | 72 db.commit() |
| 93 db.close() | 73 db.close() |
| 102 if not os.path.exists(home) or sys.argv[-1] == 'nuke': | 82 if not os.path.exists(home) or sys.argv[-1] == 'nuke': |
| 103 if len(sys.argv) > 2: | 83 if len(sys.argv) > 2: |
| 104 backend = sys.argv[1] | 84 backend = sys.argv[1] |
| 105 install_demo(home, backend) | 85 install_demo(home, backend) |
| 106 | 86 |
| 107 f = open(os.path.join(home, 'config.py'), 'r') | 87 f = open(os.path.join(home, 'config.ini'), 'r') |
| 108 url = re.search(r'^TRACKER_WEB\s*=\s*[\'"](http.+/)[\'"]$', f.read(), | 88 url = re.search(r'^web\s*=\s*(http.+/)$', f.read(), |
| 109 re.M|re.I).group(1) | 89 re.M|re.I).group(1) |
| 110 f.close() | 90 f.close() |
| 111 hostname, port = urlparse.urlparse(url)[1].split(':') | 91 hostname, port = urlparse.urlparse(url)[1].split(':') |
| 112 port = int(port) | 92 port = int(port) |
| 113 | 93 |
