Skip to content

Commit 245876b

Browse files
author
Richard Jones
committed
I thought I committed this last night. Ho hum.
- This implements most of the rest of the new tracker config layout: - dbinit.py split between schema.py and initial_data.py - interfaces.py gone - tracker and detectors __init__.py gone - Added some missing functionality to backends: db_exists test and db_nuke. - Implemented configuration file options in postgresql backend. - Cleaned up tracker initialisation a lot.
1 parent 7f6c0e5 commit 245876b

File tree

22 files changed

+371
-540
lines changed

22 files changed

+371
-540
lines changed

cgi-bin/roundup.cgi

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup.cgi,v 1.39 2004-06-29 08:59:08 richard Exp $
19+
# $Id: roundup.cgi,v 1.40 2004-07-27 00:57:17 richard Exp $
2020

2121
# python version check
2222
from roundup import version_check
@@ -158,16 +158,19 @@ def main(out, err):
158158
else:
159159
tracker_home = TRACKER_HOMES[tracker]
160160
tracker = roundup.instance.open(tracker_home)
161-
from roundup.cgi.client import Unauthorised, NotFound
162-
client = tracker.Client(tracker, request, os.environ)
161+
from roundup.cgi import client
162+
if hasattr(tracker, 'Client'):
163+
client = tracker.Client(tracker, request, os.environ)
164+
else:
165+
client = client.Client(tracker, request, os.environ)
163166
try:
164167
client.main()
165-
except Unauthorised:
168+
except client.Unauthorised:
166169
request.send_response(403)
167170
request.send_header('Content-Type', 'text/html')
168171
request.end_headers()
169172
out.write('Unauthorised')
170-
except NotFound:
173+
except client.NotFound:
171174
request.send_response(404)
172175
request.send_header('Content-Type', 'text/html')
173176
request.end_headers()

demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Copyright (c) 2003 Richard Jones ([email protected])
44
#
5-
# $Id: demo.py,v 1.11 2004-05-28 01:09:10 richard Exp $
5+
# $Id: demo.py,v 1.12 2004-07-27 00:57:17 richard Exp $
66

77
import sys, os, string, re, urlparse
88
import shutil, socket, errno, BaseHTTPServer
@@ -27,7 +27,7 @@ class config:
2727
module.db_nuke(config)
2828
elif backend == 'postgresql':
2929
class config:
30-
POSTGRESQL_DATABASE = {'database': 'rounduptest'}
30+
POSTGRESQL_DATABASE = 'rounduptest'
3131
DATABASE = 'home'
3232
if module.db_exists(config):
3333
module.db_nuke(config)

frontends/ZRoundup/ZRoundup.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1515
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1616
#
17-
# $Id: ZRoundup.py,v 1.18 2004-07-21 04:50:40 richard Exp $
17+
# $Id: ZRoundup.py,v 1.19 2004-07-27 00:57:17 richard Exp $
1818
#
1919
''' ZRoundup module - exposes the roundup web interface to Zope
2020
@@ -40,7 +40,7 @@
4040
modulesecurity = ModuleSecurityInfo()
4141

4242
import roundup.instance
43-
from roundup.cgi.client import NotFound
43+
from roundup.cgi import client
4444

4545
modulesecurity.declareProtected('View management screens',
4646
'manage_addZRoundupForm')
@@ -139,7 +139,7 @@ def __init__(self, id, instance_home):
139139
def roundup_opendb(self):
140140
'''Open the roundup instance database for a transaction.
141141
'''
142-
instance = roundup.instance.open(self.instance_home)
142+
tracker = roundup.instance.open(self.instance_home)
143143
request = RequestWrapper(self.REQUEST['RESPONSE'])
144144
env = self.REQUEST.environ
145145

@@ -159,7 +159,9 @@ def roundup_opendb(self):
159159
env['TRACKER_NAME'] = path_components[-1]
160160

161161
form = FormWrapper(self.REQUEST.form)
162-
return instance.Client(instance, request, env, form)
162+
if hasattr(tracker, 'Client'):
163+
return tracker.Client(tracker, request, env, form)
164+
return client.Client(tracker, request, env, form)
163165

164166
security.declareProtected('View', 'index_html')
165167
def index_html(self):
@@ -208,7 +210,7 @@ def index_html(self, REQUEST=None):
208210
# and call roundup to do something
209211
client.main()
210212
return ''
211-
except NotFound:
213+
except client.NotFound:
212214
raise 'NotFound', REQUEST.URL
213215
pass
214216
except:

roundup/admin.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.76 2004-07-13 10:21:32 a1s Exp $
19+
# $Id: admin.py,v 1.77 2004-07-27 00:57:17 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -445,29 +445,19 @@ def do_initialise(self, tracker_home, args):
445445
raise UsageError, _('Instance has not been installed')%locals()
446446

447447
# is there already a database?
448-
try:
449-
db_exists = tracker.select_db.Database.exists(tracker.config)
450-
except AttributeError:
451-
# TODO: move this code to exists() static method in every backend
452-
db_exists = os.path.exists(os.path.join(tracker_home, 'db'))
453-
if db_exists:
448+
if tracker.exists():
454449
ok = raw_input(_(
455450
"""WARNING: The database is already initialised!
456451
If you re-initialise it, you will lose all the data!
457452
Erase it? Y/N: """))
458453
if ok.strip().lower() != 'y':
459454
return 0
460455

461-
# Get a database backend in use by tracker
462-
try:
463-
# nuke it
464-
tracker.select_db.Database.nuke(tracker.config)
465-
except AttributeError:
466-
# TODO: move this code to nuke() static method in every backend
467-
shutil.rmtree(os.path.join(tracker_home, 'db'))
456+
# nuke it
457+
tracker.nuke()
468458

469459
# GO
470-
init.initialise(tracker_home, adminpw)
460+
tracker.init(password.Password(adminpw))
471461

472462
return 0
473463

roundup/backends/back_anydbm.py

Lines changed: 11 additions & 1 deletion
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.166 2004-07-22 04:47:35 richard Exp $
18+
#$Id: back_anydbm.py,v 1.167 2004-07-27 00:57:18 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
@@ -43,6 +43,16 @@
4343
Multilink, DatabaseError, Boolean, Number, Node
4444
from roundup.date import Range
4545

46+
def db_exists(config):
47+
# check for the user db
48+
for db in 'user user.db'.split():
49+
if os.path.exists(os.path.join(config.TRACKER_HOME, 'db', db)):
50+
return 1
51+
return 0
52+
53+
def db_nuke(config):
54+
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
55+
4656
#
4757
# Now the database
4858
#

roundup/backends/back_bsddb.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@
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.30 2004-07-02 05:22:09 richard Exp $
18+
#$Id: back_bsddb.py,v 1.31 2004-07-27 00:57:18 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in BSDDB.
2020
'''
2121
__docformat__ = 'restructuredtext'
2222

23-
import bsddb, os, marshal
23+
import bsddb, os, marshal, shutil
2424
from roundup import hyperdb, date
2525

2626
# these classes are so similar, we just use the anydbm methods
2727
from back_anydbm import Database, Class, FileClass, IssueClass
2828

29+
def db_exists(config):
30+
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'user'))
31+
32+
def db_nuke(config):
33+
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
34+
2935
#
3036
# Now the database
3137
#

roundup/backends/back_bsddb3.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@
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.24 2004-07-02 05:22:09 richard Exp $
18+
#$Id: back_bsddb3.py,v 1.25 2004-07-27 00:57:18 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in BSDDB3.
2020
'''
2121
__docformat__ = 'restructuredtext'
2222

23-
import bsddb3, os, marshal, errno
23+
import bsddb3, os, marshal, errno, shutil
2424
from roundup import hyperdb, date
2525

2626
# these classes are so similar, we just use the anydbm methods
2727
from back_anydbm import Database, Class, FileClass, IssueClass
2828

29+
def db_exists(config):
30+
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'user'))
31+
32+
def db_nuke(config):
33+
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
34+
2935
#
3036
# Now the database
3137
#

roundup/backends/back_metakit.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_metakit.py,v 1.81 2004-07-20 23:24:26 richard Exp $
1+
# $Id: back_metakit.py,v 1.82 2004-07-27 00:57:18 richard Exp $
22
'''Metakit backend for Roundup, originally by Gordon McMillan.
33
44
Known Current Bugs:
@@ -56,6 +56,13 @@
5656
READ = 0
5757
READWRITE = 1
5858

59+
def db_exists(config):
60+
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db',
61+
'tracker.mk4'))
62+
63+
def db_nuke(config):
64+
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
65+
5966
# general metakit error
6067
class MKBackendError(Exception):
6168
pass

roundup/backends/back_postgresql.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,37 @@
1414
from roundup import hyperdb, date
1515
from roundup.backends import rdbms_common
1616

17+
from roundup import configuration
18+
19+
configuration.SETTINGS += (
20+
("postgresql", (
21+
(configuration.Option, 'database', 'roundup'),
22+
(configuration.NullableOption, 'host', 'localhost'),
23+
(configuration.NullableOption, 'port', '5432'),
24+
(configuration.NullableOption, 'user', 'roundup'),
25+
(configuration.NullableOption, 'password', 'roundup'),
26+
)),
27+
)
28+
29+
def connection_dict(config):
30+
d = {
31+
'database': config.POSTGRESQL_DATABASE,
32+
}
33+
for name in 'host', 'port', 'password', 'user':
34+
cvar = 'POSTGRESQL_'+name.upper()
35+
if config[cvar] is not None:
36+
d[name] = config[cvar]
37+
return d
38+
1739
def db_create(config):
1840
"""Clear all database contents and drop database itself"""
19-
command = 'CREATE DATABASE %s'%config.POSTGRESQL_DATABASE['database']
41+
command = 'CREATE DATABASE %s'%config.POSTGRESQL_DATABASE
2042
config.logging.getLogger('hyperdb').info(command)
2143
db_command(config, command)
2244

2345
def db_nuke(config, fail_ok=0):
2446
"""Clear all database contents and drop database itself"""
25-
command = 'DROP DATABASE %s'% config.POSTGRESQL_DATABASE['database']
47+
command = 'DROP DATABASE %s'% config.POSTGRESQL_DATABASE
2648
config.logging.getLogger('hyperdb').info(command)
2749
db_command(config, command)
2850

@@ -33,7 +55,7 @@ def db_command(config, command):
3355
'''Perform some sort of database-level command. Retry 10 times if we
3456
fail by conflicting with another user.
3557
'''
36-
template1 = config.POSTGRESQL_DATABASE.copy()
58+
template1 = connection_dict(config)
3759
template1['database'] = 'template1'
3860

3961
try:
@@ -70,7 +92,7 @@ def pg_command(cursor, command):
7092

7193
def db_exists(config):
7294
"""Check if database already exists"""
73-
db = getattr(config, 'POSTGRESQL_DATABASE')
95+
db = connection_dict(config)
7496
try:
7597
conn = psycopg.connect(**db)
7698
conn.close()
@@ -82,7 +104,7 @@ class Database(rdbms_common.Database):
82104
arg = '%s'
83105

84106
def sql_open_connection(self):
85-
db = getattr(self.config, 'POSTGRESQL_DATABASE')
107+
db = connection_dict(config)
86108
self.config.logging.getLogger('hyperdb').info('open database %r'%db)
87109
try:
88110
conn = psycopg.connect(**db)

roundup/backends/back_sqlite.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_sqlite.py,v 1.30 2004-07-02 05:22:09 richard Exp $
1+
# $Id: back_sqlite.py,v 1.31 2004-07-27 00:57:18 richard Exp $
22
'''Implements a backend for SQLite.
33
44
See https://pysqlite.sourceforge.net/ for pysqlite info
@@ -9,13 +9,19 @@
99
'''
1010
__docformat__ = 'restructuredtext'
1111

12-
import os, base64, marshal
12+
import os, base64, marshal, shutil
1313

1414
from roundup import hyperdb, date, password
1515
from roundup.backends import locking
1616
from roundup.backends import rdbms_common
1717
import sqlite
1818

19+
def db_exists(config):
20+
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'db'))
21+
22+
def db_nuke(config):
23+
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
24+
1925
class Database(rdbms_common.Database):
2026
# char to use for positional arguments
2127
arg = '%s'

0 commit comments

Comments
 (0)