[svn] commit: r719 - in /branches/parkinglot: ./ src/bin/bind10/ src/lib/config/python/isc/config/
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 4 12:13:46 UTC 2010
Author: jelte
Date: Thu Feb 4 12:13:46 2010
New Revision: 719
Log:
renamed camelCase methods to underscored in the python config classes
started with unittests for config/python
Added:
branches/parkinglot/src/lib/config/python/isc/config/config_test.in (with props)
branches/parkinglot/src/lib/config/python/isc/config/datadefinition_test.py
Modified:
branches/parkinglot/configure.ac
branches/parkinglot/src/bin/bind10/bind10.py.in
branches/parkinglot/src/lib/config/python/isc/config/ccsession.py
branches/parkinglot/src/lib/config/python/isc/config/datadefinition.py
Modified: branches/parkinglot/configure.ac
==============================================================================
--- branches/parkinglot/configure.ac (original)
+++ branches/parkinglot/configure.ac Thu Feb 4 12:13:46 2010
@@ -185,6 +185,7 @@
src/bin/auth/config.h
src/bin/parkinglot/config.h
src/lib/config/cpp/data_def_unittests_config.h
+ src/lib/config/python/isc/config/config_test
src/lib/dns/cpp/gen-rdatacode.py
], [
chmod +x src/bin/cfgmgr/run_b10-cfgmgr.sh
Modified: branches/parkinglot/src/bin/bind10/bind10.py.in
==============================================================================
--- branches/parkinglot/src/bin/bind10/bind10.py.in (original)
+++ branches/parkinglot/src/bin/bind10/bind10.py.in Thu Feb 4 12:13:46 2010
@@ -460,7 +460,7 @@
# In our main loop, we check for dead processes or messages
# on the c-channel.
wakeup_fd = wakeup_pipe[0]
- ccs_fd = boss_of_bind.ccs.getSocket().fileno()
+ ccs_fd = boss_of_bind.ccs.get_socket().fileno()
while boss_of_bind.runnable:
# XXX: get time for next restart for timeout
Modified: branches/parkinglot/src/lib/config/python/isc/config/ccsession.py
==============================================================================
--- branches/parkinglot/src/lib/config/python/isc/config/ccsession.py (original)
+++ branches/parkinglot/src/lib/config/python/isc/config/ccsession.py Thu Feb 4 12:13:46 2010
@@ -28,22 +28,22 @@
class CCSession:
def __init__(self, spec_file_name, config_handler, command_handler):
self._data_definition = isc.config.DataDefinition(spec_file_name)
- self._module_name = self._data_definition.getModuleName()
+ self._module_name = self._data_definition.get_module_name()
- self.setConfigHandler(config_handler)
- self.setCommandHandler(command_handler)
+ self.set_config_handler(config_handler)
+ self.set_command_handler(command_handler)
self._session = Session()
self._session.group_subscribe(self._module_name, "*")
- self.__sendSpec()
- self.__getFullConfig()
+ self.__send_spec()
+ self.__get_full_config()
- def getSocket(self):
+ def get_socket(self):
"""Returns the socket from the command channel session"""
return self._session._socket
- def getSession(self):
+ def get_session(self):
"""Returns the command-channel session that is used, so the
application can use it directly"""
return self._session
@@ -51,7 +51,7 @@
def close(self):
self._session.close()
- def checkCommand(self):
+ def check_command(self):
"""Check whether there is a command on the channel.
Call the command callback function if so"""
msg, env = self._session.group_recvmsg(False)
@@ -66,7 +66,7 @@
self._session.group_reply(env, answer)
- def setConfigHandler(self, config_handler):
+ def set_config_handler(self, config_handler):
"""Set the config handler for this module. The handler is a
function that takes the full configuration and handles it.
It should return either { "result": [ 0 ] } or
@@ -74,19 +74,19 @@
self._config_handler = config_handler
# should we run this right now since we've changed the handler?
- def setCommandHandler(self, command_handler):
+ def set_command_handler(self, command_handler):
"""Set the command handler for this module. The handler is a
function that takes a command as defined in the .spec file
and return either { "result": [ 0, (result) ] } or
{ "result": [ <error_number>. "error message" ] }"""
self._command_handler = command_handler
- def __sendSpec(self):
+ def __send_spec(self):
"""Sends the data specification to the configuration manager"""
- self._session.group_sendmsg(self._data_definition.getDefinition(), "ConfigManager")
+ self._session.group_sendmsg(self._data_definition.get_definition(), "ConfigManager")
answer, env = self._session.group_recvmsg(False)
- def __getFullConfig(self):
+ def __get_full_config(self):
"""Asks the configuration manager for the current configuration, and call the config handler if set"""
self._session.group_sendmsg({ "command": [ "get_config", { "module_name": self._module_name } ] }, "ConfigManager")
answer, env = self._session.group_recvmsg(False)
Modified: branches/parkinglot/src/lib/config/python/isc/config/datadefinition.py
==============================================================================
--- branches/parkinglot/src/lib/config/python/isc/config/datadefinition.py (original)
+++ branches/parkinglot/src/lib/config/python/isc/config/datadefinition.py Thu Feb 4 12:13:46 2010
@@ -21,18 +21,17 @@
# file objects are passed around as _io.TextIOWrapper objects
# import that so we can check those types
-import _io
class DataDefinitionError(Exception):
pass
class DataDefinition:
def __init__(self, spec_file, check = True):
- if type(spec_file) == _io.TextIOWrapper:
- self._data_spec = __read_data_spec_file(spec_file)
+ if hasattr(spec_file, 'read'):
+ self._data_spec = self.__read_data_spec_file(spec_file)
elif type(spec_file) == str:
file = open(spec_file)
- self._data_spec = self.__readDataSpecFile(file)
+ self._data_spec = self.__read_data_spec_file(file)
file.close()
else:
raise DataDefinitionError("Not a str or file-like object")
@@ -43,13 +42,13 @@
# "TODO"
return True
- def __readDataSpecFile(self, file, check = True):
+ def __read_data_spec_file(self, file, check = True):
"""Reads the data spec from the given file object.
If check is True, check whether it is of the correct form.
If it is not, an DataDefinitionError exception is raised"""
- if type(file) != _io.TextIOWrapper:
+ if not hasattr(file, 'read'):
raise DataDefinitionError("Not a file-like object:" + str(type(file)))
- str = file.read()
+ str = file.read(-1)
# TODO catch error here and reraise as a less ugly exception
data_spec = ast.literal_eval(str)
if check:
@@ -58,10 +57,10 @@
pass
return data_spec
- def getDefinition(self):
+ def get_definition(self):
return self._data_spec
- def getModuleName(self):
+ def get_module_name(self):
return self._data_spec["data_specification"]["module_name"]
def _check(data_spec):
@@ -78,11 +77,11 @@
if "module_name" not in data_spec:
raise DataDefinitionError("no module_name in data_specification")
if "config_data" in data_spec:
- _checkConfigSpec(data_spec["config_data"])
+ _check_config_spec(data_spec["config_data"])
if "commands" in data_spec:
- _checkCommandSpec(data_spec["commands"])
+ _check_command_spec(data_spec["commands"])
-def _checkConfigSpec(config_data):
+def _check_config_spec(config_data):
# config data is a list of items represented by dicts that contain
# things like "item_name", depending on the type they can have
# specific subitems
@@ -92,9 +91,9 @@
if type(config_data) != list:
raise DataDefinitionError("config_data is not a list of items")
for config_item in config_data:
- _checkItemSpec(config_item)
+ _check_item_spec(config_item)
-def _checkCommandSpec(commands):
+def _check_command_spec(commands):
"""Checks the list that contains a set of commands. Raises a
DataDefinitionError is there is an error"""
if type(commands) != list:
@@ -116,10 +115,10 @@
for command_arg in command["command_args"]:
if type(command_arg) != dict:
raise DataDefinitionError("command argument not a dict in " + command_name)
- _checkItemSpec(command_arg)
+ _check_item_spec(command_arg)
pass
-def _checkItemSpec(config_item):
+def _check_item_spec(config_item):
"""Checks the dict that defines one config item
(i.e. containing "item_name", "item_type", etc.
Raises a DataDefinitionError if there is an error"""
@@ -157,7 +156,7 @@
raise DataDefinitionError("no list_item_spec in list item " + item_name)
if type(config_item["list_item_spec"]) != dict:
raise DataDefinitionError("list_item_spec in " + item_name + " is not a dict")
- _checkItemSpec(config_item["list_item_spec"])
+ _check_item_spec(config_item["list_item_spec"])
if item_type == "map":
if "map_item_spec" not in config_item:
raise DataDefinitionError("no map_item_sepc in map item " + item_name)
@@ -166,5 +165,5 @@
for map_item in config_item["map_item_spec"]:
if type(map_item) != dict:
raise DataDefinitionError("map_item_spec element is not a dict")
- _checkItemSpec(map_item)
+ _check_item_spec(map_item)
More information about the bind10-changes
mailing list