Skip to content

Commit be7659d

Browse files
author
Richard Jones
committed
The demo.py script works again using the new configuration system.
1 parent 784839b commit be7659d

File tree

7 files changed

+58
-63
lines changed

7 files changed

+58
-63
lines changed

demo.py

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,30 @@
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

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

1111
def 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(':')

roundup/backends/back_anydbm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.167 2004-07-27 00:57:18 richard Exp $
18+
#$Id: back_anydbm.py,v 1.168 2004-07-27 01:59:28 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -33,7 +33,7 @@
3333
except AssertionError:
3434
print "WARNING: you should upgrade to python 2.1.3"
3535

36-
import whichdb, os, marshal, re, weakref, string, copy, time
36+
import whichdb, os, marshal, re, weakref, string, copy, time, shutil
3737
from roundup import hyperdb, date, password, roundupdb, security
3838
from blobfiles import FileStorage
3939
from sessions_dbm import Sessions, OneTimeKeys
@@ -45,7 +45,7 @@
4545

4646
def db_exists(config):
4747
# check for the user db
48-
for db in 'user user.db'.split():
48+
for db in 'nodes.user nodes.user.db'.split():
4949
if os.path.exists(os.path.join(config.TRACKER_HOME, 'db', db)):
5050
return 1
5151
return 0

roundup/backends/back_bsddb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_bsddb.py,v 1.31 2004-07-27 00:57:18 richard Exp $
18+
#$Id: back_bsddb.py,v 1.32 2004-07-27 01:59:28 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in BSDDB.
2020
'''
2121
__docformat__ = 'restructuredtext'
@@ -27,7 +27,7 @@
2727
from back_anydbm import Database, Class, FileClass, IssueClass
2828

2929
def db_exists(config):
30-
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'user'))
30+
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'nodes.user'))
3131

3232
def db_nuke(config):
3333
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))

roundup/backends/back_bsddb3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_bsddb3.py,v 1.25 2004-07-27 00:57:18 richard Exp $
18+
#$Id: back_bsddb3.py,v 1.26 2004-07-27 01:59:28 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in BSDDB3.
2020
'''
2121
__docformat__ = 'restructuredtext'
@@ -27,7 +27,7 @@
2727
from back_anydbm import Database, Class, FileClass, IssueClass
2828

2929
def db_exists(config):
30-
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'user'))
30+
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'nodes.user'))
3131

3232
def db_nuke(config):
3333
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))

roundup/cgi/templating.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ class in this file. If the tracker interfaces module defines a
231231
"""
232232
# construct the TemplatingUtils class
233233
utils = TemplatingUtils
234-
if hasattr(client.instance.interfaces, 'TemplatingUtils'):
234+
if (hasattr(client.instance, 'interfaces') and
235+
hasattr(client.instance.interfaces, 'TemplatingUtils')):
235236
class utils(client.instance.interfaces.TemplatingUtils, utils):
236237
pass
237238

roundup/configuration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Roundup Issue Tracker configuration support
22
#
3-
# $Id: configuration.py,v 1.12 2004-07-27 01:23:50 richard Exp $
3+
# $Id: configuration.py,v 1.13 2004-07-27 01:59:28 richard Exp $
44
#
55
__docformat__ = "restructuredtext"
66

@@ -448,12 +448,12 @@ class NullableFilePathOption(NullableOption, FilePathOption):
448448
(Option, 'name', 'roundup',
449449
"Name of the Postgresql or MySQL database to use.",
450450
['MYSQL_DBNAME']),
451-
(NullableOption, 'host', 'localhost'
451+
(NullableOption, 'host', 'localhost',
452452
"Hostname that the Postgresql or MySQL database resides on.",
453453
['MYSQL_DBHOST']),
454-
(NullableOption, 'port', '5432'
454+
(NullableOption, 'port', '5432',
455455
"Port number that the Postgresql or MySQL database resides on."),
456-
(NullableOption, 'user', 'roundup'
456+
(NullableOption, 'user', 'roundup',
457457
"Postgresql or MySQL database user that Roundup should use.",
458458
['MYSQL_DBUSER']),
459459
(NullableOption, 'password', 'roundup',

roundup/scripts/roundup_server.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
"""Command-line script that runs a server over roundup.cgi.client.
1919
20-
$Id: roundup_server.py,v 1.58 2004-07-27 00:57:18 richard Exp $
20+
$Id: roundup_server.py,v 1.59 2004-07-27 01:59:28 richard Exp $
2121
"""
2222
__docformat__ = 'restructuredtext'
2323

@@ -54,6 +54,8 @@
5454
23eo0sr/NIGvB37K+lOWXMvJ+uWFeKGU/03Cb7n3D4M3wxI=
5555
'''.strip()))
5656

57+
DEFAULT_PORT = 8080
58+
5759
class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
5860
TRACKER_HOMES = {}
5961
LOG_IPADDRESS = 1
@@ -241,7 +243,6 @@ class RoundupService(win32serviceutil.ServiceFramework,
241243
'''
242244
_svc_name_ = "Roundup Bug Tracker"
243245
_svc_display_name_ = "Roundup Bug Tracker"
244-
address = (HOSTNAME, PORT)
245246
def __init__(self, args):
246247
# redirect stdout/stderr to our logfile
247248
if LOGFILE:
@@ -334,7 +335,7 @@ def usage(message=''):
334335
-d <PIDfile> run the server in the background and write the server's PID
335336
to the file indicated by PIDfile. The -l option *must* be
336337
specified if -d is used.'''
337-
port=PORT
338+
port=DEFAULT_PORT
338339
if message:
339340
message += '\n'
340341
print _('''%(message)sUsage: roundup-server [options] [name=tracker home]*
@@ -437,6 +438,8 @@ def setuid(user):
437438

438439
# People can remove this check if they're really determined
439440
if user is None:
441+
if os.getuid():
442+
return
440443
raise ValueError, _("Can't run as root!")
441444

442445
if os.getuid():
@@ -457,15 +460,15 @@ def setuid(user):
457460
raise ValueError, _("User %(user)s doesn't exist")%locals()
458461
os.setuid(uid)
459462

460-
def run(port=PORT, success_message=None):
463+
undefined = []
464+
def run(port=undefined, success_message=None):
461465
''' Script entry point - handle args and figure out what to to.
462466
'''
463467
# time out after a minute if we can
464468
import socket
465469
if hasattr(socket, 'setdefaulttimeout'):
466470
socket.setdefaulttimeout(60)
467471

468-
undefined = []
469472
hostname = pidfile = logfile = user = group = svc_args = log_ip = undefined
470473
config = None
471474

@@ -506,7 +509,7 @@ def run(port=PORT, success_message=None):
506509
cfg = ConfigParser.ConfigParser()
507510
cfg.read(filename)
508511
if port is undefined:
509-
port = cfg.get('server', 'port', 8080)
512+
port = cfg.get('server', 'port', DEFAULT_PORT)
510513
if user is undefined and cfg.has_option('server', 'user'):
511514
user = cfg.get('server', 'user')
512515
if group is undefined and cfg.has_option('server', 'group'):
@@ -524,6 +527,16 @@ def run(port=PORT, success_message=None):
524527
continue
525528
homes[section] = cfg.get(section, 'home')
526529

530+
# defaults
531+
if hostname is undefined:
532+
hostname = ''
533+
if group is undefined:
534+
group = None
535+
if user is undefined:
536+
user = None
537+
if svc_args is undefined:
538+
svc_args = None
539+
527540
# obtain server before changing user id - allows to use port <
528541
# 1024 if started as root
529542
address = (hostname, port)
@@ -552,9 +565,9 @@ def run(port=PORT, success_message=None):
552565
raise
553566
except ValueError:
554567
usage(error())
555-
except:
556-
print error()
557-
sys.exit(1)
568+
# except:
569+
# print error()
570+
# sys.exit(1)
558571

559572
# we don't want the cgi module interpreting the command-line args ;)
560573
sys.argv = sys.argv[:1]
@@ -570,6 +583,7 @@ def run(port=PORT, success_message=None):
570583

571584
if svc_args is not None:
572585
# don't do any other stuff
586+
RoundupService.address = address
573587
return win32serviceutil.HandleCommandLine(RoundupService, argv=svc_args)
574588

575589
# redirect stdout/stderr to our logfile

0 commit comments

Comments
 (0)