From 228800b44cfb3c8c295cf81be65e49ec2efee3c1 Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Fri, 26 Sep 2008 01:34:52 +0000 Subject: Added property-selector to the console getObjects function git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@699148 13f79535-47bb-0310-9956-ffa450edef68 --- python/qpid/qmfconsole.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'python/qpid') diff --git a/python/qpid/qmfconsole.py b/python/qpid/qmfconsole.py index 4d06e4a725..3800e54b5b 100644 --- a/python/qpid/qmfconsole.py +++ b/python/qpid/qmfconsole.py @@ -139,6 +139,7 @@ class Session: self.cv = Condition() self.syncSequenceList = [] self.getResult = [] + self.getSelect = [] self.error = None self.bindingKeyList = self._bindingKeys(rcvObjects, rcvEvents, rcvHeartbeats) self.manageConnections = manageConnections @@ -157,7 +158,7 @@ class Session: raise Exception(broker.error) self.brokers.append(broker) - self.getObjects(broker=broker, name="agent") + self.getObjects(broker=broker, cls="agent") return broker def delBroker(self, broker): @@ -220,7 +221,7 @@ class Session: schema = - supply a schema object returned from getSchema key = - supply a classKey from the list returned by getClasses - name = - supply a class name as a string + cls = - supply a class name as a string If objects should be obtained from only one agent, use the following argument. Otherwise, the query will go to all agents. @@ -231,6 +232,10 @@ class Session: add the following argument: broker = - supply a broker as returned by addBroker + + If additional arguments are supplied, they are used as property selectors. For example, + if the argument name="test" is supplied, only objects whose "name" property is "test" + will be returned in the result. """ if "broker" in kwargs: brokerList = [] @@ -254,14 +259,19 @@ class Session: cname = None if "schema" in kwargs: pname, cname, hash = kwargs["schema"].getKey() elif "key" in kwargs: pname, cname, hash = kwargs["key"] - elif "name" in kwargs: pname, cname, hash = None, kwargs["name"], None + elif "cls" in kwargs: pname, cname, hash = None, kwargs["cls"], None if cname == None: - raise Exception("No class supplied, use 'schema', 'key', or 'name' argument") + raise Exception("No class supplied, use 'schema', 'key', or 'cls' argument") map = {} map["_class"] = cname if pname != None: map["_package"] = pname if hash != None: map["_hash"] = hash + self.getSelect = [] + for item in kwargs: + if item != "schema" and item != "key" and item != "cls": + self.getSelect.append((item, kwargs[item])) + self.getResult = [] for agent in agentList: broker = agent.broker @@ -453,7 +463,7 @@ class Session: self.cv.acquire() if seq in self.syncSequenceList: - if object.getTimestamps()[2] == 0: + if object.getTimestamps()[2] == 0 and self._selectMatch(object): self.getResult.append(object) self.cv.release() return @@ -471,6 +481,14 @@ class Session: self.syncSequenceList = [] self.cv.notify() self.cv.release() + + def _selectMatch(self, object): + """ Check the object against self.getSelect to check for a match """ + for key, value in self.getSelect: + for prop, propval in object.properties: + if key == prop.name and value != propval: + return False + return True def _decodeValue(self, codec, typecode): """ Decode, from the codec, a value based on its typecode. """ -- cgit v1.2.1