Mercurial > p > roundup > code
changeset 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 | 943f9d4592b8 |
| children | 18e86941c950 |
| files | demo.py roundup/backends/back_anydbm.py roundup/backends/back_bsddb.py roundup/backends/back_bsddb3.py roundup/cgi/templating.py roundup/configuration.py roundup/scripts/roundup_server.py |
| diffstat | 7 files changed, 58 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/demo.py Tue Jul 27 01:23:50 2004 +0000 +++ b/demo.py Tue Jul 27 01:59:28 2004 +0000 @@ -2,35 +2,30 @@ # # Copyright (c) 2003 Richard Jones (richard@mechanicalcat.net) # -# $Id: demo.py,v 1.12 2004-07-27 00:57:17 richard Exp $ +# $Id: demo.py,v 1.13 2004-07-27 01:59:27 richard Exp $ import sys, os, string, re, urlparse import shutil, socket, errno, BaseHTTPServer from glob import glob def install_demo(home, backend): - # create the instance - if os.path.exists(home): - shutil.rmtree(home) - from roundup import init, instance, password, backends + from roundup import init, instance, password, backends, configuration + + # set up the config for this tracker + config = configuration.Config() + config['TRACKER_HOME'] = home + config['MAIL_DOMAIN'] = 'localhost' + config['DATABASE'] = 'db' + if backend in ('mysql', 'postgresql'): + config['RDBMS_HOST'] = 'localhost' + config['RDBMS_USER'] = 'rounduptest' + config['RDBMS_PASSWORD'] = 'rounduptest' + config['RDBMS_NAME'] = 'rounduptest' # see if we have further db nuking to perform module = getattr(backends, backend) - if backend == 'mysql': - class config: - MYSQL_DBHOST = 'localhost' - MYSQL_DBUSER = 'rounduptest' - MYSQL_DBPASSWORD = 'rounduptest' - MYSQL_DBNAME = 'rounduptest' - DATABASE = 'home' - if module.db_exists(config): - module.db_nuke(config) - elif backend == 'postgresql': - class config: - POSTGRESQL_DATABASE = 'rounduptest' - DATABASE = 'home' - if module.db_exists(config): - module.db_nuke(config) + if module.db_exists(config): + module.db_nuke(config) init.install(home, os.path.join('templates', 'classic')) # don't have email flying around @@ -61,31 +56,16 @@ s.close() print 'already in use.' port += 100 - url = 'http://%s:%s/demo/'%(hostname, port) + config['TRACKER_WEB'] = 'http://%s:%s/demo/'%(hostname, port) # write the config - f = open(os.path.join(home, 'config.py'), 'r') - s = f.read().replace('http://tracker.example/cgi-bin/roundup.cgi/bugs/', - url) - f.close() - # DB connection stuff for mysql and postgresql - s = s + """ -MYSQL_DBHOST = 'localhost' -MYSQL_DBUSER = 'rounduptest' -MYSQL_DBPASSWORD = 'rounduptest' -MYSQL_DBNAME = 'rounduptest' -MYSQL_DATABASE = (MYSQL_DBHOST, MYSQL_DBUSER, MYSQL_DBPASSWORD, MYSQL_DBNAME) -POSTGRESQL_DATABASE = {'database': 'rounduptest'} -""" - f = open(os.path.join(home, 'config.py'), 'w') - f.write(s) - f.close() + config.save() - # initialise the database - init.initialise(home, 'admin') + # open the tracker and initialise + tracker = instance.open(home) + tracker.init(password.Password('admin')) # add the "demo" user - tracker = instance.open(home) db = tracker.open('admin') db.user.create(username='demo', password=password.Password('demo'), realname='Demo User', roles='User') @@ -104,8 +84,8 @@ backend = sys.argv[1] install_demo(home, backend) - f = open(os.path.join(home, 'config.py'), 'r') - url = re.search(r'^TRACKER_WEB\s*=\s*[\'"](http.+/)[\'"]$', f.read(), + f = open(os.path.join(home, 'config.ini'), 'r') + url = re.search(r'^web\s*=\s*(http.+/)$', f.read(), re.M|re.I).group(1) f.close() hostname, port = urlparse.urlparse(url)[1].split(':')
--- a/roundup/backends/back_anydbm.py Tue Jul 27 01:23:50 2004 +0000 +++ b/roundup/backends/back_anydbm.py Tue Jul 27 01:59:28 2004 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.167 2004-07-27 00:57:18 richard Exp $ +#$Id: back_anydbm.py,v 1.168 2004-07-27 01:59:28 richard Exp $ '''This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several @@ -33,7 +33,7 @@ except AssertionError: print "WARNING: you should upgrade to python 2.1.3" -import whichdb, os, marshal, re, weakref, string, copy, time +import whichdb, os, marshal, re, weakref, string, copy, time, shutil from roundup import hyperdb, date, password, roundupdb, security from blobfiles import FileStorage from sessions_dbm import Sessions, OneTimeKeys @@ -45,7 +45,7 @@ def db_exists(config): # check for the user db - for db in 'user user.db'.split(): + for db in 'nodes.user nodes.user.db'.split(): if os.path.exists(os.path.join(config.TRACKER_HOME, 'db', db)): return 1 return 0
--- a/roundup/backends/back_bsddb.py Tue Jul 27 01:23:50 2004 +0000 +++ b/roundup/backends/back_bsddb.py Tue Jul 27 01:59:28 2004 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_bsddb.py,v 1.31 2004-07-27 00:57:18 richard Exp $ +#$Id: back_bsddb.py,v 1.32 2004-07-27 01:59:28 richard Exp $ '''This module defines a backend that saves the hyperdatabase in BSDDB. ''' __docformat__ = 'restructuredtext' @@ -27,7 +27,7 @@ from back_anydbm import Database, Class, FileClass, IssueClass def db_exists(config): - return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'user')) + return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'nodes.user')) def db_nuke(config): shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
--- a/roundup/backends/back_bsddb3.py Tue Jul 27 01:23:50 2004 +0000 +++ b/roundup/backends/back_bsddb3.py Tue Jul 27 01:59:28 2004 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_bsddb3.py,v 1.25 2004-07-27 00:57:18 richard Exp $ +#$Id: back_bsddb3.py,v 1.26 2004-07-27 01:59:28 richard Exp $ '''This module defines a backend that saves the hyperdatabase in BSDDB3. ''' __docformat__ = 'restructuredtext' @@ -27,7 +27,7 @@ from back_anydbm import Database, Class, FileClass, IssueClass def db_exists(config): - return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'user')) + return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'nodes.user')) def db_nuke(config): shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
--- a/roundup/cgi/templating.py Tue Jul 27 01:23:50 2004 +0000 +++ b/roundup/cgi/templating.py Tue Jul 27 01:59:28 2004 +0000 @@ -231,7 +231,8 @@ """ # construct the TemplatingUtils class utils = TemplatingUtils - if hasattr(client.instance.interfaces, 'TemplatingUtils'): + if (hasattr(client.instance, 'interfaces') and + hasattr(client.instance.interfaces, 'TemplatingUtils')): class utils(client.instance.interfaces.TemplatingUtils, utils): pass
--- a/roundup/configuration.py Tue Jul 27 01:23:50 2004 +0000 +++ b/roundup/configuration.py Tue Jul 27 01:59:28 2004 +0000 @@ -1,6 +1,6 @@ # Roundup Issue Tracker configuration support # -# $Id: configuration.py,v 1.12 2004-07-27 01:23:50 richard Exp $ +# $Id: configuration.py,v 1.13 2004-07-27 01:59:28 richard Exp $ # __docformat__ = "restructuredtext" @@ -448,12 +448,12 @@ (Option, 'name', 'roundup', "Name of the Postgresql or MySQL database to use.", ['MYSQL_DBNAME']), - (NullableOption, 'host', 'localhost' + (NullableOption, 'host', 'localhost', "Hostname that the Postgresql or MySQL database resides on.", ['MYSQL_DBHOST']), - (NullableOption, 'port', '5432' + (NullableOption, 'port', '5432', "Port number that the Postgresql or MySQL database resides on."), - (NullableOption, 'user', 'roundup' + (NullableOption, 'user', 'roundup', "Postgresql or MySQL database user that Roundup should use.", ['MYSQL_DBUSER']), (NullableOption, 'password', 'roundup',
--- a/roundup/scripts/roundup_server.py Tue Jul 27 01:23:50 2004 +0000 +++ b/roundup/scripts/roundup_server.py Tue Jul 27 01:59:28 2004 +0000 @@ -17,7 +17,7 @@ """Command-line script that runs a server over roundup.cgi.client. -$Id: roundup_server.py,v 1.58 2004-07-27 00:57:18 richard Exp $ +$Id: roundup_server.py,v 1.59 2004-07-27 01:59:28 richard Exp $ """ __docformat__ = 'restructuredtext' @@ -54,6 +54,8 @@ 23eo0sr/NIGvB37K+lOWXMvJ+uWFeKGU/03Cb7n3D4M3wxI= '''.strip())) +DEFAULT_PORT = 8080 + class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): TRACKER_HOMES = {} LOG_IPADDRESS = 1 @@ -241,7 +243,6 @@ ''' _svc_name_ = "Roundup Bug Tracker" _svc_display_name_ = "Roundup Bug Tracker" - address = (HOSTNAME, PORT) def __init__(self, args): # redirect stdout/stderr to our logfile if LOGFILE: @@ -334,7 +335,7 @@ -d <PIDfile> run the server in the background and write the server's PID to the file indicated by PIDfile. The -l option *must* be specified if -d is used.''' - port=PORT + port=DEFAULT_PORT if message: message += '\n' print _('''%(message)sUsage: roundup-server [options] [name=tracker home]* @@ -437,6 +438,8 @@ # People can remove this check if they're really determined if user is None: + if os.getuid(): + return raise ValueError, _("Can't run as root!") if os.getuid(): @@ -457,7 +460,8 @@ raise ValueError, _("User %(user)s doesn't exist")%locals() os.setuid(uid) -def run(port=PORT, success_message=None): +undefined = [] +def run(port=undefined, success_message=None): ''' Script entry point - handle args and figure out what to to. ''' # time out after a minute if we can @@ -465,7 +469,6 @@ if hasattr(socket, 'setdefaulttimeout'): socket.setdefaulttimeout(60) - undefined = [] hostname = pidfile = logfile = user = group = svc_args = log_ip = undefined config = None @@ -506,7 +509,7 @@ cfg = ConfigParser.ConfigParser() cfg.read(filename) if port is undefined: - port = cfg.get('server', 'port', 8080) + port = cfg.get('server', 'port', DEFAULT_PORT) if user is undefined and cfg.has_option('server', 'user'): user = cfg.get('server', 'user') if group is undefined and cfg.has_option('server', 'group'): @@ -524,6 +527,16 @@ continue homes[section] = cfg.get(section, 'home') + # defaults + if hostname is undefined: + hostname = '' + if group is undefined: + group = None + if user is undefined: + user = None + if svc_args is undefined: + svc_args = None + # obtain server before changing user id - allows to use port < # 1024 if started as root address = (hostname, port) @@ -552,9 +565,9 @@ raise except ValueError: usage(error()) - except: - print error() - sys.exit(1) +# except: +# print error() +# sys.exit(1) # we don't want the cgi module interpreting the command-line args ;) sys.argv = sys.argv[:1] @@ -570,6 +583,7 @@ if svc_args is not None: # don't do any other stuff + RoundupService.address = address return win32serviceutil.HandleCommandLine(RoundupService, argv=svc_args) # redirect stdout/stderr to our logfile
