[asterisk-scf-commits] asterisk-scf/integration/configurator.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Mar 1 15:13:49 CST 2011
branch "master" has been updated
via eaafaf0a795eedeb446b612217f5970b49340dbc (commit)
from 1e20913bf7364a4f91beadc7e94934472a55204a (commit)
Summary of changes:
Configurator.py | 27 ++++++++++++++-------------
ExampleConfigurator.py | 10 +++++-----
2 files changed, 19 insertions(+), 18 deletions(-)
- Log -----------------------------------------------------------------
commit eaafaf0a795eedeb446b612217f5970b49340dbc
Author: Joshua Colp <jcolp at digium.com>
Date: Tue Mar 1 17:14:12 2011 -0400
Use setattr to set the value of the variable on the object and not the variable holding where the object is.
diff --git a/Configurator.py b/Configurator.py
index 04061bf..7737542 100755
--- a/Configurator.py
+++ b/Configurator.py
@@ -43,19 +43,20 @@ class OptionMapper():
"""Generic class meant to perform option to item mapping"""
self.options = { }
- def map(self, option, item, item_name, method, default = None):
- item = default
- self.options[option] = [ item, item_name, method, default ]
+ def map(self, option, object, item, item_name, method, default = None):
+ setattr(object, item, default)
+ self.options[option] = [ object, item, item_name, method, default ]
def execute(self, group, section, option):
"""Map options to configuration items based on options set"""
- item = self.options[option][0]
- item_name = self.options[option][1]
- method = self.options[option][2]
- default = self.options[option][3]
+ object = self.options[option][0]
+ item = self.options[option][1]
+ item_name = self.options[option][2]
+ method = self.options[option][3]
+ default = self.options[option][4]
try:
- item = method(section, option)
+ setattr(object, item, method(section, option))
except ValueError:
# This is not a fatal error since we just use the default value.
@@ -63,18 +64,18 @@ class OptionMapper():
print "The specified value for option '" + option + "' is not valid and no default value exists."
else:
print "The specified value for option '" + option + "' is not valid. Using default value."
- item = default
+ setattr(object, item, default)
# This has the potential to overwrite an existing item but this is done on purpose so that
# configuration options that all map to a single item can happily exist
if item != None:
- group.configurationItems[item_name] = item
+ group.configurationItems[item_name] = object
def finish(self, group):
"""Finish mapping options by finding ones that should have a value but do not"""
for option in self.options:
- item = self.options[option][0]
- default = self.options[option][3]
+ item = self.options[option][1]
+ default = self.options[option][4]
if default == None:
if item == None:
print "Option '" + option + "' requires a value to be set and no default value exists."
@@ -126,7 +127,7 @@ class ConfiguratorApp(Ice.Application):
configFile = a
elif o in ("-p", "--proxy"):
- configurationService = AsteriskSCF.System.Configuration.V1.ConfigurationServicePrx.uncheckedCast(self.communicator().stringToProxy(a))
+ configurationService = AsteriskSCF.System.Configuration.V1.ConfigurationServicePrx.checkedCast(self.communicator().stringToProxy(a))
elif o in ("-w", "--wipe"):
configurationWipe = True
diff --git a/ExampleConfigurator.py b/ExampleConfigurator.py
index bf53cdb..ac27850 100755
--- a/ExampleConfigurator.py
+++ b/ExampleConfigurator.py
@@ -20,12 +20,12 @@ class ExampleSectionVisitors(Configurator.SectionVisitors):
mapper = Configurator.OptionMapper()
# Enable is easy
- mapper.map('enable', AsteriskSCF.System.Configuration.Example.V1.EnableItem().enabled, 'enabled', config.getboolean, False)
+ mapper.map('enable', AsteriskSCF.System.Configuration.Example.V1.EnableItem(), 'enabled', 'enabled', config.getboolean, False)
# What will be the name and how many of them?
item = AsteriskSCF.System.Configuration.Example.V1.InstanceInfoItem()
- mapper.map('name', item.name, 'instance_info', config.get, None)
- mapper.map('instances', item.num, 'instance_info', config.getint, 1)
+ mapper.map('name', item, 'name', 'instance_info', config.get, None)
+ mapper.map('instances', item, 'num', 'instance_info', config.getint, 1)
# Map all the options to the corresponding items and stuff them in the group!
for option in config.options(section):
@@ -42,8 +42,8 @@ class ExampleSectionVisitors(Configurator.SectionVisitors):
# Create an option mapper, put our options in, and map them
mapper = Configurator.OptionMapper()
- mapper.map('ipv4', AsteriskSCF.System.Configuration.Example.V1.EnableItem().enabled, 'ipv4_enabled', config.getboolean, False)
- mapper.map('ipv6', AsteriskSCF.System.Configuration.Example.V1.EnableItem().enabled, 'ipv6_enabled', config.getboolean, False)
+ mapper.map('ipv4', AsteriskSCF.System.Configuration.Example.V1.EnableItem(), 'enabled', 'ipv4_enabled', config.getboolean, False)
+ mapper.map('ipv6', AsteriskSCF.System.Configuration.Example.V1.EnableItem(), 'enabled', 'ipv6_enabled', config.getboolean, False)
for option in config.options(section):
mapper.execute(group, section, option)
-----------------------------------------------------------------------
--
asterisk-scf/integration/configurator.git
More information about the asterisk-scf-commits
mailing list