Mercurial > p > roundup > code
comparison roundup/admin.py @ 656:eae9b69a0115
[SF#527416] roundup-admin uses undefined value
[SF#527503] unfriendly init blowup when parent dir
(also handles UsageError correctly now in init)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 12 Mar 2002 22:51:47 +0000 |
| parents | 29f7e41ee437 |
| children | a26afb64a947 54333751e98d |
comparison
equal
deleted
inserted
replaced
| 655:35cdc70e6a96 | 656:eae9b69a0115 |
|---|---|
| 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 18 # | 18 # |
| 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 $ |
| 20 | 20 |
| 21 import sys, os, getpass, getopt, re, UserDict, shlex | 21 import sys, os, getpass, getopt, re, UserDict, shlex |
| 22 try: | 22 try: |
| 23 import csv | 23 import csv |
| 24 except ImportError: | 24 except ImportError: |
| 260 | 260 |
| 261 See also initopts help. | 261 See also initopts help. |
| 262 ''' | 262 ''' |
| 263 if len(args) < 1: | 263 if len(args) < 1: |
| 264 raise UsageError, _('Not enough arguments supplied') | 264 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 | |
| 265 # select template | 272 # select template |
| 266 import roundup.templates | 273 import roundup.templates |
| 267 templates = roundup.templates.listTemplates() | 274 templates = roundup.templates.listTemplates() |
| 268 template = len(args) > 1 and args[1] or '' | 275 template = len(args) > 1 and args[1] or '' |
| 269 if template not in templates: | 276 if template not in templates: |
| 271 while template not in templates: | 278 while template not in templates: |
| 272 template = raw_input(_('Select template [classic]: ')).strip() | 279 template = raw_input(_('Select template [classic]: ')).strip() |
| 273 if not template: | 280 if not template: |
| 274 template = 'classic' | 281 template = 'classic' |
| 275 | 282 |
| 283 # select hyperdb backend | |
| 276 import roundup.backends | 284 import roundup.backends |
| 277 backends = roundup.backends.__all__ | 285 backends = roundup.backends.__all__ |
| 278 backend = len(args) > 2 and args[2] or '' | 286 backend = len(args) > 2 and args[2] or '' |
| 279 if backend not in backends: | 287 if backend not in backends: |
| 280 print _('Back ends:'), ', '.join(backends) | 288 print _('Back ends:'), ', '.join(backends) |
| 281 while backend not in backends: | 289 while backend not in backends: |
| 282 backend = raw_input(_('Select backend [anydbm]: ')).strip() | 290 backend = raw_input(_('Select backend [anydbm]: ')).strip() |
| 283 if not backend: | 291 if not backend: |
| 284 backend = 'anydbm' | 292 backend = 'anydbm' |
| 293 | |
| 294 # admin password | |
| 285 if len(args) > 3: | 295 if len(args) > 3: |
| 286 adminpw = confirm = args[3] | 296 adminpw = confirm = args[3] |
| 287 else: | 297 else: |
| 288 adminpw = '' | 298 adminpw = '' |
| 289 confirm = 'x' | 299 confirm = 'x' |
| 290 while adminpw != confirm: | 300 while adminpw != confirm: |
| 291 adminpw = getpass.getpass(_('Admin Password: ')) | 301 adminpw = getpass.getpass(_('Admin Password: ')) |
| 292 confirm = getpass.getpass(_(' Confirm: ')) | 302 confirm = getpass.getpass(_(' Confirm: ')) |
| 303 | |
| 304 # create! | |
| 293 init.init(instance_home, template, backend, adminpw) | 305 init.init(instance_home, template, backend, adminpw) |
| 306 | |
| 294 return 0 | 307 return 0 |
| 295 | 308 |
| 296 | 309 |
| 297 def do_get(self, args): | 310 def do_get(self, args): |
| 298 '''Usage: get property designator[,designator]* | 311 '''Usage: get property designator[,designator]* |
| 527 props[key] = value | 540 props[key] = value |
| 528 else: | 541 else: |
| 529 props = self.props_from_args(args[1:]) | 542 props = self.props_from_args(args[1:]) |
| 530 | 543 |
| 531 # convert types | 544 # convert types |
| 532 for propname in props.keys(): | 545 for propname, value in props.items(): |
| 533 # get the property | 546 # get the property |
| 534 try: | 547 try: |
| 535 proptype = properties[propname] | 548 proptype = properties[propname] |
| 536 except KeyError: | 549 except KeyError: |
| 537 raise UsageError, _('%(classname)s has no property ' | 550 raise UsageError, _('%(classname)s has no property ' |
| 942 while not self.instance_home: | 955 while not self.instance_home: |
| 943 self.instance_home = raw_input(_('Enter instance home: ')).strip() | 956 self.instance_home = raw_input(_('Enter instance home: ')).strip() |
| 944 | 957 |
| 945 # before we open the db, we may be doing an init | 958 # before we open the db, we may be doing an init |
| 946 if command == 'initialise': | 959 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 | |
| 948 | 965 |
| 949 # get the instance | 966 # get the instance |
| 950 try: | 967 try: |
| 951 instance = roundup.instance.open(self.instance_home) | 968 instance = roundup.instance.open(self.instance_home) |
| 952 except ValueError, message: | 969 except ValueError, message: |
| 953 self.instance_home = '' | 970 self.instance_home = '' |
| 954 print _("Couldn't open instance: %(message)s")%locals() | 971 print _("Error: Couldn't open instance: %(message)s")%locals() |
| 955 return 1 | 972 return 1 |
| 956 | 973 |
| 957 # only open the database once! | 974 # only open the database once! |
| 958 if not self.db: | 975 if not self.db: |
| 959 self.db = instance.open('admin') | 976 self.db = instance.open('admin') |
| 962 ret = 0 | 979 ret = 0 |
| 963 try: | 980 try: |
| 964 ret = function(args[1:]) | 981 ret = function(args[1:]) |
| 965 except UsageError, message: | 982 except UsageError, message: |
| 966 print _('Error: %(message)s')%locals() | 983 print _('Error: %(message)s')%locals() |
| 984 print | |
| 967 print function.__doc__ | 985 print function.__doc__ |
| 968 ret = 1 | 986 ret = 1 |
| 969 except: | 987 except: |
| 970 import traceback | 988 import traceback |
| 971 traceback.print_exc() | 989 traceback.print_exc() |
| 1041 tool = AdminTool() | 1059 tool = AdminTool() |
| 1042 sys.exit(tool.main()) | 1060 sys.exit(tool.main()) |
| 1043 | 1061 |
| 1044 # | 1062 # |
| 1045 # $Log: not supported by cvs2svn $ | 1063 # $Log: not supported by cvs2svn $ |
| 1064 # Revision 1.8 2002/02/27 03:28:21 richard | |
| 1065 # Ran it through pychecker, made fixes | |
| 1066 # | |
| 1046 # Revision 1.7 2002/02/20 05:04:32 richard | 1067 # Revision 1.7 2002/02/20 05:04:32 richard |
| 1047 # Wasn't handling the cvs parser feeding properly. | 1068 # Wasn't handling the cvs parser feeding properly. |
| 1048 # | 1069 # |
| 1049 # Revision 1.6 2002/01/23 07:27:19 grubert | 1070 # Revision 1.6 2002/01/23 07:27:19 grubert |
| 1050 # . allow abbreviation of "help" in admin tool too. | 1071 # . allow abbreviation of "help" in admin tool too. |
