summaryrefslogtreecommitdiff
path: root/qpid/cpp/managementgen/generate.py
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2008-06-30 19:00:49 +0000
committerTed Ross <tross@apache.org>2008-06-30 19:00:49 +0000
commitd2051d8e6910c4cbcd9c2ce2ef01089360f83e43 (patch)
tree14142fcee4c5aa5decfaf138f2d04e8d6f1b9651 /qpid/cpp/managementgen/generate.py
parent061d6a61e73c8d4e43a711e526d6586db9f54c01 (diff)
downloadqpid-python-d2051d8e6910c4cbcd9c2ce2ef01089360f83e43.tar.gz
QPID-1160 - Per-thread counters in management API to avoid locking
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@672864 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/managementgen/generate.py')
-rwxr-xr-xqpid/cpp/managementgen/generate.py62
1 files changed, 47 insertions, 15 deletions
diff --git a/qpid/cpp/managementgen/generate.py b/qpid/cpp/managementgen/generate.py
index da78d6c7e9..197deec4f1 100755
--- a/qpid/cpp/managementgen/generate.py
+++ b/qpid/cpp/managementgen/generate.py
@@ -30,39 +30,62 @@ class Template:
Expandable File Template - This class is instantiated each time a
template is to be expanded. It is instantiated with the "filename"
which is the full path to the template file and the "handler" which
- is an object that is responsible for storing variables (setVariable)
- and expanding tags (substHandler).
+ is an object that is responsible for storing variables (setVariable),
+ checking conditions (testCondition), and expanding tags (substHandler).
"""
def __init__ (self, filename, handler):
self.filename = filename
self.handler = handler
self.handler.initExpansion ()
+ self.writing = True
def expandLine (self, line, stream, object):
cursor = 0
while 1:
sub = line.find ("/*MGEN:", cursor)
if sub == -1:
- stream.write (line[cursor:len (line)])
+ if self.writing:
+ stream.write (line[cursor:len (line)])
return
subend = line.find("*/", sub)
- stream.write (line[cursor:sub])
+ if self.writing:
+ stream.write (line[cursor:sub])
cursor = subend + 2
- tag = line[sub:subend]
- equalPos = tag.find ("=")
- if equalPos == -1:
- dotPos = tag.find (".")
+ tag = line[sub:subend]
+
+ if tag[7:10] == "IF(":
+ close = tag.find(")")
+ if close == -1:
+ raise ValueError ("Missing ')' on condition")
+ cond = tag[10:close]
+ dotPos = cond.find (".")
if dotPos == -1:
- raise ValueError ("Invalid tag: %s" % tag)
- tagObject = tag[7:dotPos]
- tagName = tag[dotPos + 1:len (tag)]
- self.handler.substHandler (object, stream, tagObject, tagName)
+ raise ValueError ("Invalid condition tag: %s" % cond)
+ tagObject = cond[0:dotPos]
+ tagName = cond[dotPos + 1 : len(cond)]
+ if not self.handler.testCondition(object, tagObject, tagName):
+ self.writing = False
+
+ elif tag[7:12] == "ENDIF":
+ self.writing = True
+
else:
- tagKey = tag[7:equalPos]
- tagVal = tag[equalPos + 1:len (tag)]
- self.handler.setVariable (tagKey, tagVal)
+ equalPos = tag.find ("=")
+ if equalPos == -1:
+ dotPos = tag.find (".")
+ if dotPos == -1:
+ raise ValueError ("Invalid tag: %s" % tag)
+ tagObject = tag[7:dotPos]
+ tagName = tag[dotPos + 1:len (tag)]
+ if self.writing:
+ self.handler.substHandler (object, stream, tagObject, tagName)
+ else:
+ tagKey = tag[7:equalPos]
+ tagVal = tag[equalPos + 1:len (tag)]
+ if self.writing:
+ self.handler.setVariable (tagKey, tagVal)
def expand (self, object):
fd = open (self.filename)
@@ -224,6 +247,15 @@ class Generator:
call = obj + ".gen" + tag + "(stream, self.variables)"
eval (call)
+ def testCondition (self, object, tagObject, tag):
+ if tagObject == "Root":
+ obj = "self"
+ else:
+ obj = "object" # MUST be the same as the 2nd formal parameter
+
+ call = obj + ".test" + tag + "(self.variables)"
+ return eval (call)
+
def setVariable (self, key, value):
self.variables[key] = value