[svn] commit: r345 - in /branches/jelte-datadef/src: bin/bigtool/run_bigtool.py lib/bigtool/bigtool.py

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Dec 3 13:03:34 UTC 2009


Author: jelte
Date: Thu Dec  3 13:03:34 2009
New Revision: 345

Log:
config 'go' command, keep track of location within the configuration

Modified:
    branches/jelte-datadef/src/bin/bigtool/run_bigtool.py
    branches/jelte-datadef/src/lib/bigtool/bigtool.py

Modified: branches/jelte-datadef/src/bin/bigtool/run_bigtool.py
==============================================================================
--- branches/jelte-datadef/src/bin/bigtool/run_bigtool.py (original)
+++ branches/jelte-datadef/src/bin/bigtool/run_bigtool.py Thu Dec  3 13:03:34 2009
@@ -59,7 +59,7 @@
     cmd = CommandInfo(name = "add", desc = "Add entry to configuration list", need_inst_param = False)
     param = ParamInfo(name = "identifier", type = "string", optional=True)
     cmd.add_param(param)
-    param = ParamInfo(name = "value", type = "string", optional=True)
+    param = ParamInfo(name = "value", type = "string", optional=False)
     cmd.add_param(param)
     module.add_command(cmd)
 
@@ -88,6 +88,11 @@
     cmd = CommandInfo(name = "commit", desc = "Commit all local changes", need_inst_param = False)
     module.add_command(cmd)
 
+    cmd = CommandInfo(name = "go", desc = "Go to a specific configuration part", need_inst_param = False)
+    param = ParamInfo(name = "identifier", type="string", optional=False)
+    cmd.add_param(param)
+    module.add_command(cmd)
+
     bigtool.add_module_info(module)
     
 

Modified: branches/jelte-datadef/src/lib/bigtool/bigtool.py
==============================================================================
--- branches/jelte-datadef/src/lib/bigtool/bigtool.py (original)
+++ branches/jelte-datadef/src/lib/bigtool/bigtool.py Thu Dec  3 13:03:34 2009
@@ -30,12 +30,18 @@
 
     def __init__(self, session = None):
         Cmd.__init__(self)
-        self.prompt = '> '
+        self.location = ""
+        self.prompt_end = '> '
+        self.prompt = self.prompt_end
         self.ruler = '-'
         self.modules = OrderedDict()
         self.add_module_info(ModuleInfo("help", desc = "Get help for bigtool"))
         self.cc = session
         self.config_data = ISC.CC.data.UIConfigData("", session)
+
+    def postcmd(self, stop, line):
+        self.prompt = self.location + self.prompt_end
+        return stop
 
     def validate_cmd(self, cmd):
         if not cmd.module in self.modules:
@@ -124,7 +130,7 @@
                 
     
     def onecmd(self, line):
-        if line == 'EOF'or line.lower() == "quit":
+        if line == 'EOF' or line.lower() == "quit":
             return True
             
         if line == 'h':
@@ -146,7 +152,7 @@
                                                        text)
                     if cmd.module == "config":
                         # grm text has been stripped of slashes...
-                        my_text = cur_line.rpartition(" ")[2]
+                        my_text = self.location + "/" + cur_line.rpartition(" ")[2]
                         list = self.config_data.config.get_item_list(my_text.rpartition("/")[0])
                         hints.extend([val for val in list if val.startswith(text)])
             except CmdModuleNameFormatError:
@@ -249,10 +255,15 @@
 
 
     def apply_config_cmd(self, cmd):
-        identifier = ""
+        identifier = self.location
         try:
             if 'identifier' in cmd.params:
-                identifier = cmd.params['identifier']
+                if not identifier.endswith("/"):
+                    identifier += "/"
+                if cmd.params['identifier'].startswith("/"):
+                    identifier = cmd.params['identifier']
+                else:
+                    identifier += cmd.params['identifier']
             if cmd.command == "show":
                 values = self.config_data.get_value_maps(identifier)
                 for value_map in values:
@@ -280,10 +291,25 @@
                 self.config_data.revert()
             elif cmd.command == "commit":
                 self.config_data.commit(self.cc)
+            elif cmd.command == "go":
+                self.go(identifier)
         except ISC.CC.data.DataTypeError as dte:
             print("Error: " + str(dte))
         except ISC.CC.data.DataNotFoundError as dnfe:
             print("Error: " + identifier + " not found")
+        except KeyError as ke:
+            print("Error: missing " + str(ke))
+
+    def go(self, identifier):
+        # just to see if it exists
+        self.config_data.get_value(identifier)
+        # some sanitizing
+        identifier = identifier.replace("//", "/")
+        if not identifier.startswith("/"):
+            identifier = "/" + identifier
+        if identifier.endswith("/"):
+            identifier = identifier[:-1]
+        self.location = identifier
 
     def apply_cmd(self, cmd):
         if not self.cc:




More information about the bind10-changes mailing list