1616# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818#
19- # $Id: admin.py,v 1.8 2002-02-27 03:28:21 richard Exp $
19+ # $Id: admin.py,v 1.9 2002-03-12 22:51:47 richard Exp $
2020
2121import sys , os , getpass , getopt , re , UserDict , shlex
2222try :
@@ -262,6 +262,13 @@ def do_initialise(self, instance_home, args):
262262 '''
263263 if len (args ) < 1 :
264264 raise UsageError , _ ('Not enough arguments supplied' )
265+
266+ # make sure the instance home can be created
267+ parent = os .path .split (instance_home )[0 ]
268+ if not os .path .exists (parent ):
269+ raise UsageError , _ ('Instance home parent directory "%(parent)s"'
270+ 'does not exist' )% locals ()
271+
265272 # select template
266273 import roundup .templates
267274 templates = roundup .templates .listTemplates ()
@@ -273,6 +280,7 @@ def do_initialise(self, instance_home, args):
273280 if not template :
274281 template = 'classic'
275282
283+ # select hyperdb backend
276284 import roundup .backends
277285 backends = roundup .backends .__all__
278286 backend = len (args ) > 2 and args [2 ] or ''
@@ -282,6 +290,8 @@ def do_initialise(self, instance_home, args):
282290 backend = raw_input (_ ('Select backend [anydbm]: ' )).strip ()
283291 if not backend :
284292 backend = 'anydbm'
293+
294+ # admin password
285295 if len (args ) > 3 :
286296 adminpw = confirm = args [3 ]
287297 else :
@@ -290,7 +300,10 @@ def do_initialise(self, instance_home, args):
290300 while adminpw != confirm :
291301 adminpw = getpass .getpass (_ ('Admin Password: ' ))
292302 confirm = getpass .getpass (_ (' Confirm: ' ))
303+
304+ # create!
293305 init .init (instance_home , template , backend , adminpw )
306+
294307 return 0
295308
296309
@@ -529,7 +542,7 @@ def do_create(self, args):
529542 props = self .props_from_args (args [1 :])
530543
531544 # convert types
532- for propname in props .keys ():
545+ for propname , value in props .items ():
533546 # get the property
534547 try :
535548 proptype = properties [propname ]
@@ -944,14 +957,18 @@ def run_command(self, args):
944957
945958 # before we open the db, we may be doing an init
946959 if command == 'initialise' :
947- return self .do_initialise (self .instance_home , args )
960+ try :
961+ return self .do_initialise (self .instance_home , args )
962+ except UsageError , message :
963+ print _ ('Error: %(message)s' )% locals ()
964+ return 1
948965
949966 # get the instance
950967 try :
951968 instance = roundup .instance .open (self .instance_home )
952969 except ValueError , message :
953970 self .instance_home = ''
954- print _ ("Couldn't open instance: %(message)s" )% locals ()
971+ print _ ("Error: Couldn't open instance: %(message)s" )% locals ()
955972 return 1
956973
957974 # only open the database once!
@@ -964,6 +981,7 @@ def run_command(self, args):
964981 ret = function (args [1 :])
965982 except UsageError , message :
966983 print _ ('Error: %(message)s' )% locals ()
984+ print
967985 print function .__doc__
968986 ret = 1
969987 except :
@@ -1043,6 +1061,9 @@ def main(self):
10431061
10441062#
10451063# $Log: not supported by cvs2svn $
1064+ # Revision 1.8 2002/02/27 03:28:21 richard
1065+ # Ran it through pychecker, made fixes
1066+ #
10461067# Revision 1.7 2002/02/20 05:04:32 richard
10471068# Wasn't handling the cvs parser feeding properly.
10481069#
0 commit comments