|
16 | 16 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
17 | 17 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
18 | 18 | # |
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 $ |
20 | 20 |
|
21 | | -import sys, os, getpass, getopt, re, UserDict, shlex |
| 21 | +import sys, os, getpass, getopt, re, UserDict, shlex, shutil |
22 | 22 | try: |
23 | 23 | import csv |
24 | 24 | except ImportError: |
@@ -249,15 +249,20 @@ def help_initopts(self): |
249 | 249 | print _('Back ends:'), ', '.join(backends) |
250 | 250 |
|
251 | 251 |
|
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. |
255 | 255 |
|
256 | 256 | The command will prompt for the instance home directory (if not supplied |
257 | 257 | through INSTANCE_HOME or the -i option). The template, backend and admin |
258 | 258 | password may be specified on the command-line as arguments, in that |
259 | 259 | order. |
260 | 260 |
|
| 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 | +
|
261 | 266 | See also initopts help. |
262 | 267 | ''' |
263 | 268 | if len(args) < 1: |
@@ -291,18 +296,70 @@ def do_initialise(self, instance_home, args): |
291 | 296 | if not backend: |
292 | 297 | backend = 'anydbm' |
293 | 298 |
|
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] |
297 | 329 | else: |
298 | 330 | adminpw = '' |
299 | 331 | 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')) |
303 | 360 |
|
304 | | - # create! |
305 | | - init.init(instance_home, template, backend, adminpw) |
| 361 | + # GO |
| 362 | + init.initialise(instance_home, adminpw) |
306 | 363 |
|
307 | 364 | return 0 |
308 | 365 |
|
@@ -955,13 +1012,19 @@ def run_command(self, args): |
955 | 1012 | while not self.instance_home: |
956 | 1013 | self.instance_home = raw_input(_('Enter instance home: ')).strip() |
957 | 1014 |
|
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 |
959 | 1016 | if command == 'initialise': |
960 | 1017 | try: |
961 | 1018 | return self.do_initialise(self.instance_home, args) |
962 | 1019 | except UsageError, message: |
963 | 1020 | print _('Error: %(message)s')%locals() |
964 | 1021 | 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 |
965 | 1028 |
|
966 | 1029 | # get the instance |
967 | 1030 | try: |
@@ -1061,6 +1124,9 @@ def main(self): |
1061 | 1124 |
|
1062 | 1125 | # |
1063 | 1126 | # $Log: not supported by cvs2svn $ |
| 1127 | +# Revision 1.10 2002/04/27 10:07:23 richard |
| 1128 | +# minor fix to error message |
| 1129 | +# |
1064 | 1130 | # Revision 1.9 2002/03/12 22:51:47 richard |
1065 | 1131 | # . #527416 ] roundup-admin uses undefined value |
1066 | 1132 | # . #527503 ] unfriendly init blowup when parent dir |
|
0 commit comments