Mercurial > p > roundup > code
comparison roundup/admin.py @ 1108:b0de30171e57
implemented set for all items in a class, and unset
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 11 Sep 2002 01:19:45 +0000 |
| parents | db787cef1385 |
| children | 36ec30d286ea |
comparison
equal
deleted
inserted
replaced
| 1107:1c1ccfc9673d | 1108:b0de30171e57 |
|---|---|
| 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.28 2002-09-10 12:44:42 richard Exp $ | 19 # $Id: admin.py,v 1.29 2002-09-11 01:19:45 richard Exp $ |
| 20 | 20 |
| 21 import sys, os, getpass, getopt, re, UserDict, shlex, shutil | 21 import sys, os, getpass, getopt, re, UserDict, shlex, shutil |
| 22 try: | 22 try: |
| 23 import csv | 23 import csv |
| 24 except ImportError: | 24 except ImportError: |
| 79 raise UsageError, _('argument "%(arg)s" not propname=value')%locals() | 79 raise UsageError, _('argument "%(arg)s" not propname=value')%locals() |
| 80 try: | 80 try: |
| 81 key, value = arg.split('=') | 81 key, value = arg.split('=') |
| 82 except ValueError: | 82 except ValueError: |
| 83 raise UsageError, _('argument "%(arg)s" not propname=value')%locals() | 83 raise UsageError, _('argument "%(arg)s" not propname=value')%locals() |
| 84 props[key] = value | 84 if value: |
| 85 props[key] = value | |
| 86 else: | |
| 87 props[key] = None | |
| 85 return props | 88 return props |
| 86 | 89 |
| 87 def usage(self, message=''): | 90 def usage(self, message=''): |
| 88 if message: | 91 if message: |
| 89 message = _('Problem: %(message)s)\n\n')%locals() | 92 message = _('Problem: %(message)s)\n\n')%locals() |
| 392 print ','.join(l) | 395 print ','.join(l) |
| 393 return 0 | 396 return 0 |
| 394 | 397 |
| 395 | 398 |
| 396 def do_set(self, args): | 399 def do_set(self, args): |
| 397 '''Usage: set designator[,designator]* propname=value ... | 400 '''Usage: set [items] property=value property=value ... |
| 398 Set the given property of one or more designator(s). | 401 Set the given properties of one or more items(s). |
| 399 | 402 |
| 400 Sets the property to the value for all designators given. | 403 The items may be specified as a class or as a comma-separeted |
| 404 list of item designators (ie "designator[,designator,...]"). | |
| 405 | |
| 406 This command sets the properties to the values for all designators | |
| 407 given. If the value is missing (ie. "property=") then the property is | |
| 408 un-set. | |
| 401 ''' | 409 ''' |
| 402 if len(args) < 2: | 410 if len(args) < 2: |
| 403 raise UsageError, _('Not enough arguments supplied') | 411 raise UsageError, _('Not enough arguments supplied') |
| 404 from roundup import hyperdb | 412 from roundup import hyperdb |
| 405 | 413 |
| 406 designators = args[0].split(',') | 414 designators = args[0].split(',') |
| 415 if len(designators) == 1: | |
| 416 designator = designators[0] | |
| 417 try: | |
| 418 designator = hyperdb.splitDesignator(designator) | |
| 419 designators = [designator] | |
| 420 except hyperdb.DesignatorError: | |
| 421 cl = self.get_class(designator) | |
| 422 designators = [(designator, x) for x in cl.list()] | |
| 423 else: | |
| 424 try: | |
| 425 designators = [hyperdb.splitDesignator(x) for x in designators] | |
| 426 except hyperdb.DesignatorError, message: | |
| 427 raise UsageError, message | |
| 407 | 428 |
| 408 # get the props from the args | 429 # get the props from the args |
| 409 props = self.props_from_args(args[1:]) | 430 props = self.props_from_args(args[1:]) |
| 410 | 431 |
| 411 # now do the set for all the nodes | 432 # now do the set for all the nodes |
| 412 for designator in designators: | 433 for classname, itemid in designators: |
| 413 # decode the node designator | |
| 414 try: | |
| 415 classname, nodeid = hyperdb.splitDesignator(designator) | |
| 416 except hyperdb.DesignatorError, message: | |
| 417 raise UsageError, message | |
| 418 | |
| 419 # get the class | |
| 420 cl = self.get_class(classname) | 434 cl = self.get_class(classname) |
| 421 | 435 |
| 422 properties = cl.getprops() | 436 properties = cl.getprops() |
| 423 for key, value in props.items(): | 437 for key, value in props.items(): |
| 424 proptype = properties[key] | 438 proptype = properties[key] |
| 425 if isinstance(proptype, hyperdb.String): | 439 if isinstance(proptype, hyperdb.Multilink): |
| 440 if value is None: | |
| 441 props[key] = [] | |
| 442 else: | |
| 443 props[key] = value.split(',') | |
| 444 elif value is None: | |
| 445 continue | |
| 446 elif isinstance(proptype, hyperdb.String): | |
| 426 continue | 447 continue |
| 427 elif isinstance(proptype, hyperdb.Password): | 448 elif isinstance(proptype, hyperdb.Password): |
| 428 props[key] = password.Password(value) | 449 props[key] = password.Password(value) |
| 429 elif isinstance(proptype, hyperdb.Date): | 450 elif isinstance(proptype, hyperdb.Date): |
| 430 try: | 451 try: |
| 436 props[key] = date.Interval(value) | 457 props[key] = date.Interval(value) |
| 437 except ValueError, message: | 458 except ValueError, message: |
| 438 raise UsageError, '"%s": %s'%(value, message) | 459 raise UsageError, '"%s": %s'%(value, message) |
| 439 elif isinstance(proptype, hyperdb.Link): | 460 elif isinstance(proptype, hyperdb.Link): |
| 440 props[key] = value | 461 props[key] = value |
| 441 elif isinstance(proptype, hyperdb.Multilink): | |
| 442 props[key] = value.split(',') | |
| 443 elif isinstance(proptype, hyperdb.Boolean): | 462 elif isinstance(proptype, hyperdb.Boolean): |
| 444 props[key] = value.lower() in ('yes', 'true', 'on', '1') | 463 props[key] = value.lower() in ('yes', 'true', 'on', '1') |
| 445 elif isinstance(proptype, hyperdb.Number): | 464 elif isinstance(proptype, hyperdb.Number): |
| 446 props[key] = int(value) | 465 props[key] = int(value) |
| 447 | 466 |
| 448 # try the set | 467 # try the set |
| 449 try: | 468 try: |
| 450 apply(cl.set, (nodeid, ), props) | 469 apply(cl.set, (itemid, ), props) |
| 451 except (TypeError, IndexError, ValueError), message: | 470 except (TypeError, IndexError, ValueError), message: |
| 452 raise UsageError, message | 471 raise UsageError, message |
| 453 return 0 | 472 return 0 |
| 454 | 473 |
| 455 def do_find(self, args): | 474 def do_find(self, args): |
