Code

Added the missing keyword/topic interface to classic template (blush)
[roundup.git] / roundup / admin.py
index 51710810eafa2a7876bea19887604788e8505d10..4242cbf61be0912d9d33ef2f516bc4fb8c83b20b 100644 (file)
@@ -16,7 +16,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: admin.py,v 1.27 2002-09-10 07:07:16 richard Exp $
+# $Id: admin.py,v 1.29 2002-09-11 01:19:45 richard Exp $
 
 import sys, os, getpass, getopt, re, UserDict, shlex, shutil
 try:
 
 import sys, os, getpass, getopt, re, UserDict, shlex, shutil
 try:
@@ -81,7 +81,10 @@ class AdminTool:
                 key, value = arg.split('=')
             except ValueError:
                 raise UsageError, _('argument "%(arg)s" not propname=value')%locals()
                 key, value = arg.split('=')
             except ValueError:
                 raise UsageError, _('argument "%(arg)s" not propname=value')%locals()
-            props[key] = value
+            if value:
+                props[key] = value
+            else:
+                props[key] = None
         return props
 
     def usage(self, message=''):
         return props
 
     def usage(self, message=''):
@@ -394,35 +397,53 @@ Command help:
 
 
     def do_set(self, args):
 
 
     def do_set(self, args):
-        '''Usage: set designator[,designator]* propname=value ...
-        Set the given property of one or more designator(s).
+        '''Usage: set [items] property=value property=value ...
+        Set the given properties of one or more items(s).
+
+        The items may be specified as a class or as a comma-separeted
+        list of item designators (ie "designator[,designator,...]").
 
 
-        Sets the property to the value for all designators given.
+        This command sets the properties to the values for all designators
+        given. If the value is missing (ie. "property=") then the property is
+        un-set.
         '''
         if len(args) < 2:
             raise UsageError, _('Not enough arguments supplied')
         from roundup import hyperdb
 
         designators = args[0].split(',')
         '''
         if len(args) < 2:
             raise UsageError, _('Not enough arguments supplied')
         from roundup import hyperdb
 
         designators = args[0].split(',')
+        if len(designators) == 1:
+            designator = designators[0]
+            try:
+                designator = hyperdb.splitDesignator(designator)
+                designators = [designator]
+            except hyperdb.DesignatorError:
+                cl = self.get_class(designator)
+                designators = [(designator, x) for x in cl.list()]
+        else:
+            try:
+                designators = [hyperdb.splitDesignator(x) for x in designators]
+            except hyperdb.DesignatorError, message:
+                raise UsageError, message
 
         # get the props from the args
         props = self.props_from_args(args[1:])
 
         # now do the set for all the nodes
 
         # get the props from the args
         props = self.props_from_args(args[1:])
 
         # now do the set for all the nodes
-        for designator in designators:
-            # decode the node designator
-            try:
-                classname, nodeid = hyperdb.splitDesignator(designator)
-            except hyperdb.DesignatorError, message:
-                raise UsageError, message
-
-            # get the class
+        for classname, itemid in designators:
             cl = self.get_class(classname)
 
             properties = cl.getprops()
             for key, value in props.items():
                 proptype =  properties[key]
             cl = self.get_class(classname)
 
             properties = cl.getprops()
             for key, value in props.items():
                 proptype =  properties[key]
-                if isinstance(proptype, hyperdb.String):
+                if isinstance(proptype, hyperdb.Multilink):
+                    if value is None:
+                        props[key] = []
+                    else:
+                        props[key] = value.split(',')
+                elif value is None:
+                    continue
+                elif isinstance(proptype, hyperdb.String):
                     continue
                 elif isinstance(proptype, hyperdb.Password):
                     props[key] = password.Password(value)
                     continue
                 elif isinstance(proptype, hyperdb.Password):
                     props[key] = password.Password(value)
@@ -438,8 +459,6 @@ Command help:
                         raise UsageError, '"%s": %s'%(value, message)
                 elif isinstance(proptype, hyperdb.Link):
                     props[key] = value
                         raise UsageError, '"%s": %s'%(value, message)
                 elif isinstance(proptype, hyperdb.Link):
                     props[key] = value
-                elif isinstance(proptype, hyperdb.Multilink):
-                    props[key] = value.split(',')
                 elif isinstance(proptype, hyperdb.Boolean):
                     props[key] = value.lower() in ('yes', 'true', 'on', '1')
                 elif isinstance(proptype, hyperdb.Number):
                 elif isinstance(proptype, hyperdb.Boolean):
                     props[key] = value.lower() in ('yes', 'true', 'on', '1')
                 elif isinstance(proptype, hyperdb.Number):
@@ -447,7 +466,7 @@ Command help:
 
             # try the set
             try:
 
             # try the set
             try:
-                apply(cl.set, (nodeid, ), props)
+                apply(cl.set, (itemid, ), props)
             except (TypeError, IndexError, ValueError), message:
                 raise UsageError, message
         return 0
             except (TypeError, IndexError, ValueError), message:
                 raise UsageError, message
         return 0
@@ -811,11 +830,11 @@ Command help:
 
     def do_export(self, args):
         '''Usage: export [class[,class]] export_dir
 
     def do_export(self, args):
         '''Usage: export [class[,class]] export_dir
-        Export the database to tab-separated-value files.
+        Export the database to colon-separated-value files.
 
         This action exports the current data from the database into
 
         This action exports the current data from the database into
-        tab-separated-value files that are placed in the nominated destination
-        directory. The journals are not exported.
+        colon-separated-value files that are placed in the nominated
+        destination directory. The journals are not exported.
         '''
         # we need the CSV module
         if csv is None:
         '''
         # we need the CSV module
         if csv is None:
@@ -862,9 +881,9 @@ Command help:
         The imported nodes will have the same nodeid as defined in the
         import file, thus replacing any existing content.
 
         The imported nodes will have the same nodeid as defined in the
         import file, thus replacing any existing content.
 
-        XXX The new nodes are added to the existing database - if you want to
-        XXX create a new database using the imported data, then create a new
-        XXX database (or, tediously, retire all the old data.)
+        The new nodes are added to the existing database - if you want to
+        create a new database using the imported data, then create a new
+        database (or, tediously, retire all the old data.)
         '''
         if len(args) < 1:
             raise UsageError, _('Not enough arguments supplied')
         '''
         if len(args) < 1:
             raise UsageError, _('Not enough arguments supplied')