Skip to content

Commit f837352

Browse files
author
Richard Jones
committed
split instance initialisation into two steps...
...allowing config changes before the database is initialised.
1 parent e766d1e commit f837352

File tree

4 files changed

+108
-20
lines changed

4 files changed

+108
-20
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Feature:
3030
. reverting to dates for intervals > 2 months sucks
3131
. changed the default message list in issues to display the message body
3232
. applied patch #558876 ] cgi client customization
33+
. split instance initialisation into two steps, allowing config changes
34+
before the database is initialised.
3335

3436
Fixed:
3537
. stop sending blank (whitespace-only) notes

doc/installation.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Installing Roundup
33
==================
44

5-
:Version: $Revision: 1.6 $
5+
:Version: $Revision: 1.7 $
66

77
.. contents::
88

@@ -106,7 +106,7 @@ Set aside 15-30 minutes.
106106
environment variable or specify the full path to
107107
the command in the next step.
108108

109-
c. ``roundup-admin init``
109+
c. ``roundup-admin install``
110110

111111
You will be asked a series of questions. A description of
112112
the Roundup-provided templates can be found under the Overview_::
@@ -116,9 +116,21 @@ Set aside 15-30 minutes.
116116
Select template [classic]: classic
117117
Back ends: anydbm, bsddb
118118
Select backend [anydbm]: anydbm
119+
120+
You will now be directed to edit the instance configuration and
121+
initial schema. See `Customizing Roundup`_ for details on configuration
122+
and schema changes.
123+
124+
d. ``roundup-admin initialise``
125+
126+
This step initialises the instance database. You will need to supply
127+
an admin password at this step. You will be prompted:
128+
119129
Admin Password:
120130
Confirm:
121131

132+
Once this is done, the instance has been created.
133+
122134
3. Each instance ideally should have its own UNIX group, so create
123135
a UNIX group (edit ``/etc/group`` or your appropriate NIS map if
124136
you're using NIS). To continue with my examples so far, I would

roundup/admin.py

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.10 2002-04-27 10:07:23 richard Exp $
19+
# $Id: admin.py,v 1.11 2002-05-23 01:14:20 richard Exp $
2020

21-
import sys, os, getpass, getopt, re, UserDict, shlex
21+
import sys, os, getpass, getopt, re, UserDict, shlex, shutil
2222
try:
2323
import csv
2424
except ImportError:
@@ -249,15 +249,20 @@ def help_initopts(self):
249249
print _('Back ends:'), ', '.join(backends)
250250

251251

252-
def do_initialise(self, instance_home, args):
253-
'''Usage: initialise [template [backend [admin password]]]
254-
Initialise a new Roundup instance.
252+
def do_install(self, instance_home, args):
253+
'''Usage: install [template [backend [admin password]]]
254+
Install a new Roundup instance.
255255
256256
The command will prompt for the instance home directory (if not supplied
257257
through INSTANCE_HOME or the -i option). The template, backend and admin
258258
password may be specified on the command-line as arguments, in that
259259
order.
260260
261+
The initialise command must be called after this command in order
262+
to initialise the instance's database. You may edit the instance's
263+
initial database contents before running that command by editing
264+
the instance's dbinit.py module init() function.
265+
261266
See also initopts help.
262267
'''
263268
if len(args) < 1:
@@ -291,18 +296,70 @@ def do_initialise(self, instance_home, args):
291296
if not backend:
292297
backend = 'anydbm'
293298

294-
# admin password
295-
if len(args) > 3:
296-
adminpw = confirm = args[3]
299+
# install!
300+
init.install(instance_home, template, backend)
301+
302+
print _('''
303+
You should now edit the instance configuration file:
304+
%(instance_config_file)s
305+
... at a minimum, you must set MAILHOST, MAIL_DOMAIN and ADMIN_EMAIL.
306+
307+
If you wish to modify the default schema, you should also edit the database
308+
initialisation file:
309+
%(database_config_file)s
310+
... see the documentation on customizing for more information.
311+
''')%{
312+
'instance_config_file': os.path.join(instance_home, 'instance_config.py'),
313+
'database_config_file': os.path.join(instance_home, 'dbinit.py')
314+
}
315+
return 0
316+
317+
318+
def do_initialise(self, instance_home, args):
319+
'''Usage: initialise [adminpw [adminemail]]
320+
Initialise a new Roundup instance.
321+
322+
The administrator details will be set at this step.
323+
324+
Execute the instance's initialisation function dbinit.init()
325+
'''
326+
# password
327+
if len(args) > 0:
328+
adminpw = args[0]
297329
else:
298330
adminpw = ''
299331
confirm = 'x'
300-
while adminpw != confirm:
301-
adminpw = getpass.getpass(_('Admin Password: '))
302-
confirm = getpass.getpass(_(' Confirm: '))
332+
while adminpw != confirm:
333+
adminpw = getpass.getpass(_('Admin Password: '))
334+
confirm = getpass.getpass(_(' Confirm: '))
335+
336+
# email
337+
if len(args) > 1:
338+
adminemail = args[1]
339+
else:
340+
adminemail = ''
341+
while not adminemail:
342+
adminemail = raw_input(_(' Admin Email: ')).strip()
343+
344+
# make sure the instance home is installed
345+
if not os.path.exists(instance_home):
346+
raise UsageError, _('Instance home does not exist')%locals()
347+
if not os.path.exists(os.path.join(instance_home, 'html')):
348+
raise UsageError, _('Instance has not been installed')%locals()
349+
350+
# is there already a database?
351+
if os.path.exists(os.path.join(instance_home, 'db')):
352+
print _('WARNING: The database is already initialised!')
353+
print _('If you re-initialise it, you will lose all the data!')
354+
ok = raw_input(_('Erase it? Y/[N]: ')).strip()
355+
if ok.lower() != 'y':
356+
return 0
357+
358+
# nuke it
359+
shutil.rmtree(os.path.join(instance_home, 'db'))
303360

304-
# create!
305-
init.init(instance_home, template, backend, adminpw)
361+
# GO
362+
init.initialise(instance_home, adminpw)
306363

307364
return 0
308365

@@ -955,13 +1012,19 @@ def run_command(self, args):
9551012
while not self.instance_home:
9561013
self.instance_home = raw_input(_('Enter instance home: ')).strip()
9571014

958-
# before we open the db, we may be doing an init
1015+
# before we open the db, we may be doing an install or init
9591016
if command == 'initialise':
9601017
try:
9611018
return self.do_initialise(self.instance_home, args)
9621019
except UsageError, message:
9631020
print _('Error: %(message)s')%locals()
9641021
return 1
1022+
elif command == 'install':
1023+
try:
1024+
return self.do_install(self.instance_home, args)
1025+
except UsageError, message:
1026+
print _('Error: %(message)s')%locals()
1027+
return 1
9651028

9661029
# get the instance
9671030
try:
@@ -1061,6 +1124,9 @@ def main(self):
10611124

10621125
#
10631126
# $Log: not supported by cvs2svn $
1127+
# Revision 1.10 2002/04/27 10:07:23 richard
1128+
# minor fix to error message
1129+
#
10641130
# Revision 1.9 2002/03/12 22:51:47 richard
10651131
# . #527416 ] roundup-admin uses undefined value
10661132
# . #527503 ] unfriendly init blowup when parent dir

roundup/init.py

Lines changed: 12 additions & 4 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: init.py,v 1.18 2001-11-22 15:46:42 jhermann Exp $
18+
# $Id: init.py,v 1.19 2002-05-23 01:14:20 richard Exp $
1919

2020
__doc__ = """
2121
Init (create) a roundup instance.
@@ -55,13 +55,12 @@ def copytree(src, dst, symlinks=0):
5555
else:
5656
install_util.copyDigestedFile(srcname, dstname)
5757

58-
def init(instance_home, template, backend, adminpw):
59-
'''Initialise an instance using the named template and backend.
58+
def install(instance_home, template, backend):
59+
'''Install an instance using the named template and backend.
6060
6161
instance_home - the directory to place the instance data in
6262
template - the template to use in creating the instance data
6363
backend - the database to use to store the instance data
64-
adminpw - the password for the "admin" user
6564
6665
The instance_home directory will be created using the files found in
6766
the named template (roundup.templates.<name>). A standard instance_home
@@ -102,12 +101,21 @@ def init(instance_home, template, backend, adminpw):
102101
from roundup.backends.back_%s import Database'''%backend
103102
open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
104103

104+
105+
def initialise(instance_home, adminpw):
106+
'''Initialise an instance's database
107+
108+
adminpw - the password for the "admin" user
109+
'''
105110
# now import the instance and call its init
106111
instance = roundup.instance.open(instance_home)
107112
instance.init(password.Password(adminpw))
108113

109114
#
110115
# $Log: not supported by cvs2svn $
116+
# Revision 1.18 2001/11/22 15:46:42 jhermann
117+
# Added module docstrings to all modules.
118+
#
111119
# Revision 1.17 2001/11/12 23:17:38 jhermann
112120
# Code using copyDigestedFile() that passes unit tests
113121
#

0 commit comments

Comments
 (0)