Parcourir la source

1. Rename run_bindctl to bindctl.
2. Rename file name "bindctl.py" to 'bindcmd.py'.
3. Rename file name "command.py" to 'cmdparse.py'.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@528 e5f2f494-b856-4b98-b285-d166d9295462

Likun Zhang il y a 15 ans
Parent
commit
11510aca9c

+ 2 - 2
configure.ac

@@ -146,7 +146,7 @@ AC_OUTPUT([src/bin/bind-cfgd/bind-cfgd
            src/bin/cmd-ctrld/cmd-ctrld
            src/bin/cmd-ctrld/cmd-ctrld
            src/bin/bind10/bind10
            src/bin/bind10/bind10
            src/bin/bind10/bind10_test
            src/bin/bind10/bind10_test
-           src/bin/bindctl/run_bindctl
+           src/bin/bindctl/bindctl
            src/bin/msgq/msgq
            src/bin/msgq/msgq
            src/bin/msgq/msgq_test
            src/bin/msgq/msgq_test
            src/bin/parkinglot/config.h
            src/bin/parkinglot/config.h
@@ -154,7 +154,7 @@ AC_OUTPUT([src/bin/bind-cfgd/bind-cfgd
            chmod +x src/bin/bind-cfgd/bind-cfgd
            chmod +x src/bin/bind-cfgd/bind-cfgd
            chmod +x src/bin/cmd-ctrld/cmd-ctrld
            chmod +x src/bin/cmd-ctrld/cmd-ctrld
            chmod +x src/bin/bind10/bind10
            chmod +x src/bin/bind10/bind10
-           chmod +x src/bin/bindctl/run_bindctl
+           chmod +x src/bin/bindctl/bindctl
            chmod +x src/bin/msgq/msgq
            chmod +x src/bin/msgq/msgq
            chmod +x src/bin/msgq/msgq_test
            chmod +x src/bin/msgq/msgq_test
           ])
           ])

+ 1 - 1
src/bin/bindctl/Makefile.am

@@ -1,2 +1,2 @@
-bin_SCRIPTS = run_bindctl run_bindctl.py
+bin_SCRIPTS = bindctl bindctl.py
 man_MANS = bindctl.1
 man_MANS = bindctl.1

+ 12 - 0
src/bin/bindctl/bindctl.in

@@ -0,0 +1,12 @@
+#! /bin/sh
+
+PYTHON_EXEC=${PYTHON_EXEC:-@PYTHON@}
+export PYTHON_EXEC
+
+BINDCTL_PATH=@abs_top_srcdir@/src/bin/bindctl
+
+PYTHONPATH=@abs_top_srcdir@/src/lib/cc/python:@abs_top_srcdir@/src/lib/bindctl/
+export PYTHONPATH
+
+cd ${BINDCTL_PATH}
+exec ${PYTHON_EXEC} -O bindctl.py $*

+ 4 - 4
src/bin/bindctl/run_bindctl.py

@@ -1,10 +1,10 @@
 from moduleinfo  import *
 from moduleinfo  import *
-from bindctl import *
+from bindcmd import *
 import ISC
 import ISC
 import pprint
 import pprint
 
 
 
 
-def prepare_config_commands(bindctl):
+def prepare_config_commands(tool):
     module = ModuleInfo(name = "config", desc = "Configuration commands")
     module = ModuleInfo(name = "config", desc = "Configuration commands")
     cmd = CommandInfo(name = "show", desc = "Show configuration", need_inst_param = False)
     cmd = CommandInfo(name = "show", desc = "Show configuration", need_inst_param = False)
     param = ParamInfo(name = "identifier", type = "string", optional=True)
     param = ParamInfo(name = "identifier", type = "string", optional=True)
@@ -48,7 +48,7 @@ def prepare_config_commands(bindctl):
     cmd.add_param(param)
     cmd.add_param(param)
     module.add_command(cmd)
     module.add_command(cmd)
 
 
-    bindctl.add_module_info(module)
+    tool.add_module_info(module)
     
     
 def prepare_boss_command(tool):
 def prepare_boss_command(tool):
     # Prepare the command 'shutdown' for Boss, this is one 'hardcode' exception.
     # Prepare the command 'shutdown' for Boss, this is one 'hardcode' exception.
@@ -62,7 +62,7 @@ def prepare_boss_command(tool):
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     try:
     try:
-        tool = BindCtl("localhost:8080")
+        tool = BindCmdInterpreter("localhost:8080")
         prepare_config_commands(tool)
         prepare_config_commands(tool)
         prepare_boss_command(tool)
         prepare_boss_command(tool)
         tool.run()
         tool.run()

+ 0 - 10
src/bin/bindctl/run_bindctl.in

@@ -1,10 +0,0 @@
-#! /bin/sh
-
-PYTHON_EXEC=${PYTHON_EXEC:-@PYTHON@}
-BINDCTL_PATH=.
-
-PYTHONPATH=../../lib/cc/python:../../lib/bindctl/
-export PYTHONPATH
-
-cd ${BINDCTL_PATH}
-exec ${PYTHON_EXEC} -O run_bindctl.py $*

+ 4 - 4
src/lib/bindctl/bindctl.py

@@ -3,7 +3,7 @@ import readline
 from cmd import Cmd
 from cmd import Cmd
 from exception import *
 from exception import *
 from moduleinfo import *
 from moduleinfo import *
-from command import BindCtlCmd
+from cmdparse import BindCmdParse
 from xml.dom import minidom
 from xml.dom import minidom
 import ISC
 import ISC
 import ISC.CC.data
 import ISC.CC.data
@@ -31,7 +31,7 @@ Type \"<module_name> <command_name> help\" for help on the specific command.
 
 
 CONST_COMMAND_NODE = "command"
 CONST_COMMAND_NODE = "command"
 
 
-class BindCtl(Cmd):
+class BindCmdInterpreter(Cmd):
     """simple bindctl example."""    
     """simple bindctl example."""    
 
 
     def __init__(self, server_port = 'localhost:8080'):
     def __init__(self, server_port = 'localhost:8080'):
@@ -249,7 +249,7 @@ class BindCtl(Cmd):
             hints = []
             hints = []
             cur_line = readline.get_line_buffer()            
             cur_line = readline.get_line_buffer()            
             try:
             try:
-                cmd = BindCtlCmd(cur_line)
+                cmd = BindCmdParse(cur_line)
                 if not cmd.params and text:
                 if not cmd.params and text:
                     hints = self._get_command_startswith(cmd.module, text)
                     hints = self._get_command_startswith(cmd.module, text)
                 else:                       
                 else:                       
@@ -325,7 +325,7 @@ class BindCtl(Cmd):
 
 
     def _parse_cmd(self, line):
     def _parse_cmd(self, line):
         try:
         try:
-            cmd = BindCtlCmd(line)
+            cmd = BindCmdParse(line)
             self.validate_cmd(cmd)
             self.validate_cmd(cmd)
             self._handle_cmd(cmd)
             self._handle_cmd(cmd)
         except BindCtlException as e:
         except BindCtlException as e:

+ 1 - 1
src/lib/bindctl/command.py

@@ -18,7 +18,7 @@ PARAM_PATTERN = re.compile(param_name_str + param_value_str + next_params_str)
 # Used for module and command name
 # Used for module and command name
 NAME_PATTERN = re.compile("^\s*(?P<name>[\w]+)(?P<blank>\s*)(?P<others>.*)$")
 NAME_PATTERN = re.compile("^\s*(?P<name>[\w]+)(?P<blank>\s*)(?P<others>.*)$")
 
 
-class BindCtlCmd:
+class BindCmdParse:
     """ This class will parse the command line usr input into three part
     """ This class will parse the command line usr input into three part
     module name, command, parameters
     module name, command, parameters
     the first two parts are strings and parameter is one hash, 
     the first two parts are strings and parameter is one hash, 

+ 20 - 20
src/lib/bindctl/unittest_bindctl.py

@@ -1,6 +1,6 @@
 import unittest
 import unittest
-import command
-import bindctl
+import cmdparse
+import bindcmd
 from moduleinfo import *
 from moduleinfo import *
 from exception import *    
 from exception import *    
 try:
 try:
@@ -11,11 +11,11 @@ except ImportError:
 class TestCmdLex(unittest.TestCase):
 class TestCmdLex(unittest.TestCase):
     
     
     def my_assert_raise(self, exception_type, cmd_line):
     def my_assert_raise(self, exception_type, cmd_line):
-        self.assertRaises(exception_type, command.BindCtlCmd, cmd_line)
+        self.assertRaises(exception_type, cmdparse.BindCmdParse, cmd_line)
 
 
 
 
     def testCommandWithoutParameter(self):
     def testCommandWithoutParameter(self):
-        cmd = command.BindCtlCmd("zone add")
+        cmd = cmdparse.BindCmdParse("zone add")
         assert cmd.module == "zone"
         assert cmd.module == "zone"
         assert cmd.command == "add"
         assert cmd.command == "add"
         self.assertEqual(len(cmd.params), 0)
         self.assertEqual(len(cmd.params), 0)
@@ -27,7 +27,7 @@ class TestCmdLex(unittest.TestCase):
                  "zone add zone_name = 'cnnic.cn\", file ='cnnic.cn.file' master=1.1.1.1, " }
                  "zone add zone_name = 'cnnic.cn\", file ='cnnic.cn.file' master=1.1.1.1, " }
         
         
         for cmd_line in lines:
         for cmd_line in lines:
-            cmd = command.BindCtlCmd(cmd_line)
+            cmd = cmdparse.BindCmdParse(cmd_line)
             assert cmd.module == "zone"
             assert cmd.module == "zone"
             assert cmd.command == "add"
             assert cmd.command == "add"
             assert cmd.params["zone_name"] == "cnnic.cn"
             assert cmd.params["zone_name"] == "cnnic.cn"
@@ -36,15 +36,15 @@ class TestCmdLex(unittest.TestCase):
             
             
             
             
     def testCommandWithListParam(self):
     def testCommandWithListParam(self):
-            cmd = command.BindCtlCmd("zone set zone_name='cnnic.cn', master='1.1.1.1, 2.2.2.2'")
+            cmd = cmdparse.BindCmdParse("zone set zone_name='cnnic.cn', master='1.1.1.1, 2.2.2.2'")
             assert cmd.params["master"] == '1.1.1.1, 2.2.2.2'            
             assert cmd.params["master"] == '1.1.1.1, 2.2.2.2'            
         
         
         
         
     def testCommandWithHelpParam(self):
     def testCommandWithHelpParam(self):
-        cmd = command.BindCtlCmd("zone add help")
+        cmd = cmdparse.BindCmdParse("zone add help")
         assert cmd.params["help"] == "help"
         assert cmd.params["help"] == "help"
         
         
-        cmd = command.BindCtlCmd("zone add help *&)&)*&&$#$^%")
+        cmd = cmdparse.BindCmdParse("zone add help *&)&)*&&$#$^%")
         assert cmd.params["help"] == "help"
         assert cmd.params["help"] == "help"
         self.assertEqual(len(cmd.params), 1)
         self.assertEqual(len(cmd.params), 1)
         
         
@@ -82,10 +82,10 @@ class TestCmdLex(unittest.TestCase):
 
 
 class TestCmdSyntax(unittest.TestCase):
 class TestCmdSyntax(unittest.TestCase):
     
     
-    def _create_bindctl(self):
-        """Create one bindctl"""
+    def _create_bindcmd(self):
+        """Create one bindcmd"""
         
         
-        tool = bindctl.BindCtl()        
+        tool = bindcmd.BindCmdInterpreter()        
         zone_file_param = ParamInfo(name = "zone_file")
         zone_file_param = ParamInfo(name = "zone_file")
         load_cmd = CommandInfo(name = "load")
         load_cmd = CommandInfo(name = "load")
         load_cmd.add_param(zone_file_param)
         load_cmd.add_param(zone_file_param)
@@ -108,17 +108,17 @@ class TestCmdSyntax(unittest.TestCase):
         
         
         
         
     def setUp(self):
     def setUp(self):
-        self.bindctl = self._create_bindctl()
+        self.bindcmd = self._create_bindcmd()
         
         
         
         
     def no_assert_raise(self, cmd_line):
     def no_assert_raise(self, cmd_line):
-        cmd = command.BindCtlCmd(cmd_line)
-        self.bindctl.validate_cmd(cmd) 
+        cmd = cmdparse.BindCmdParse(cmd_line)
+        self.bindcmd.validate_cmd(cmd) 
         
         
         
         
     def my_assert_raise(self, exception_type, cmd_line):
     def my_assert_raise(self, exception_type, cmd_line):
-        cmd = command.BindCtlCmd(cmd_line)
-        self.assertRaises(exception_type, self.bindctl.validate_cmd, cmd)  
+        cmd = cmdparse.BindCmdParse(cmd_line)
+        self.assertRaises(exception_type, self.bindcmd.validate_cmd, cmd)  
         
         
         
         
     def testValidateSuccess(self):
     def testValidateSuccess(self):
@@ -156,12 +156,12 @@ class TestNameSequence(unittest.TestCase):
     Test if the module/command/parameters is saved in the order creation
     Test if the module/command/parameters is saved in the order creation
     """
     """
     
     
-    def _create_bindctl(self):
-        """Create one bindctl"""     
+    def _create_bindcmd(self):
+        """Create one bindcmd"""     
         
         
         self._cmd = CommandInfo(name = "load")
         self._cmd = CommandInfo(name = "load")
         self.module = ModuleInfo(name = "zone")
         self.module = ModuleInfo(name = "zone")
-        self.tool = bindctl.BindCtl()        
+        self.tool = bindcmd.BindCmdInterpreter()        
         for random_str in self.random_names:
         for random_str in self.random_names:
             self._cmd.add_param(ParamInfo(name = random_str))
             self._cmd.add_param(ParamInfo(name = random_str))
             self.module.add_command(CommandInfo(name = random_str))
             self.module.add_command(CommandInfo(name = random_str))
@@ -169,7 +169,7 @@ class TestNameSequence(unittest.TestCase):
         
         
     def setUp(self):
     def setUp(self):
         self.random_names = ['1erdfeDDWsd', '3fe', '2009erd', 'Fe231', 'tere142', 'rei8WD']
         self.random_names = ['1erdfeDDWsd', '3fe', '2009erd', 'Fe231', 'tere142', 'rei8WD']
-        self._create_bindctl()
+        self._create_bindcmd()
         
         
     def testSequence(self):        
     def testSequence(self):        
         param_names = self._cmd.get_param_names()
         param_names = self._cmd.get_param_names()