Permalink
Browse files

updated configuration handling

now every amqp instance lives in a given configuration namespace, you will need to update all your config files
  • Loading branch information...
1 parent a9f361b commit 115232ee661289a89fae27e48f294d2b59e273fd Felix Richter committed Jan 31, 2011
Showing with 22 additions and 13 deletions.
  1. +1 −1 VERSION
  2. +12 −6 genericore/auto_amqp.py
  3. +9 −6 genericore/multi_amqp.py
View
@@ -1,2 +1,2 @@
#Brainfuck
-+++++++[>++++++++>+++++++>+++++++<<<-]>---.>---.>.
++++++++[>++++++++>+++++++>+++++++<<<-]>--.>---.>-.
View
@@ -27,16 +27,22 @@
class auto_amqp(Configurable):
conn = None
- def __init__(self,config=None):
- Configurable.__init__(self,DEFAULT_CONFIG)
+ def __init__(self,MODULE_NAME='auto_amqp',config=None):
+ """ constructor if auto_amqp
+ MODULE_NAME is important to distinguish the namespaces for the
+ different Objects"""
+ newConfig = {}
+ newConfig[MODULE_NAME] = DEFAULT_CONFIG
+ Configurable.__init__(self)
self.load_conf(config)
+ self.MODULE_NAME = MODULE_NAME
def create_connection(self):
""" starts the connection the the AMQP Serve """
if self.conn:
raise Exception("Connection already open")
- cfg = self.config['amqp']['connection']
+ cfg = self.config[self.MODULE_NAME]['amqp']['connection']
log.debug(str(cfg))
self.conn = pika.AsyncoreConnection(pika.ConnectionParameters(
credentials = pika.PlainCredentials(cfg['login'],cfg['password']),
@@ -51,8 +57,8 @@ def create_connection(self):
def _setup_tubes(self):
""" creates the in 'config' configured input and output """
chan = self.channel
- inp = self.config['amqp']['in']
- out = self.config['amqp']['out']
+ inp = self.config[self.MODULE_NAME]['amqp']['in']
+ out = self.config[self.MODULE_NAME]['amqp']['out']
if inp['exchange']:
log.info('generating Input Queue'+ str(inp))
chan.exchange_declare(**inp)
@@ -86,7 +92,7 @@ def populate_parser(self,parser):
parser.add_argument('-v','--vhost',dest='amqpVhost',help='AMQP vhost definition',metavar='VHOST')
def eval_parser(self,parsed):
""" loads its individual configuration from the parsed output """
- conf = self.config['amqp']['connection']
+ conf = self.config[self.MODULE_NAME]['amqp']['connection']
conf['host'] = parsed.amqpHost if parsed.amqpHost else conf['host']
conf['port'] = parsed.amqpPort if parsed.amqpPort else conf['port']
conf['login'] = parsed.amqpUsername if parsed.amqpUsername else conf['login']
View
@@ -15,6 +15,7 @@
"vhost" : "/"
},
"exchanges" : {
+ # ======== Example =========
#"basic" : {
# "in" : {
# "exchange" : False,
@@ -38,16 +39,18 @@ class multi_amqp(Configurable):
create multiple 'tubes' (input and output exchanges),
the configuration therefore looks a bit different"""
conn = None
- def __init__(self,config=None):
- Configurable.__init__(self,DEFAULT_CONFIG)
+ def __init__(self,MODULE_NAME='multi_amqp',config=None):
+ self.NAME = MODULE_NAME
+ newConfig = { MODULE_NAME : DEFAULT_CONFIG}
+ Configurable.__init__(self,newConfig)
self.load_conf(config)
def create_connection(self):
""" starts the connection the the AMQP Serve """
if self.conn:
raise Exception("Connection already open")
- cfg = self.config['amqp']['connection']
+ cfg = self.config[self.NAME]['amqp']['connection']
log.debug(str(cfg))
self.conn = pika.AsyncoreConnection(pika.ConnectionParameters(
credentials = pika.PlainCredentials(cfg['login'],cfg['password']),
@@ -65,8 +68,8 @@ def _setup_tubes(self):
""" creates the in 'config' configured input and output """
chan = self.channel
ret = []
- print self.config['amqp']['exchanges']
- for k,v in self.config['amqp']['exchanges'].items():
+ print self.config[self.NAME]['amqp']['exchanges']
+ for k,v in self.config[self.NAME]['amqp']['exchanges'].items():
o = C()
inp = v['in'] if 'in' in v else None
out = v['out'] if 'out' in v else None
@@ -106,7 +109,7 @@ def populate_parser(self,parser):
def eval_parser(self,parsed):
""" loads its individual configuration from the parsed output """
- conf = self.config['amqp']['connection']
+ conf = self.config[self.NAME]['amqp']['connection']
conf['host'] = parsed.amqpHost if parsed.amqpHost else conf['host']
conf['port'] = parsed.amqpPort if parsed.amqpPort else conf['port']
conf['login'] = parsed.amqpUsername if parsed.amqpUsername else conf['login']

0 comments on commit 115232e

Please sign in to comment.