diff options
| author | Rajith Muditha Attapattu <rajith@apache.org> | 2008-05-06 20:19:22 +0000 |
|---|---|---|
| committer | Rajith Muditha Attapattu <rajith@apache.org> | 2008-05-06 20:19:22 +0000 |
| commit | 3fa932a1bef60b759f7e77468c989008e662b2c5 (patch) | |
| tree | aa5e5ecf92a2c0a22d4d0a1380216ea0308f71ad /python/commands | |
| parent | f5813621fff3ca6720e7851bf9f914258f16b60c (diff) | |
| download | qpid-python-3fa932a1bef60b759f7e77468c989008e662b2c5.tar.gz | |
This patch was attached to QPID-953.
It allows to specify a comma separated list of queue names to filter with -f flag.
Also I removed getopt and added optparse as it provides a more easy way of handling CLI functionality
including a free help function.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@653904 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/commands')
| -rwxr-xr-x | python/commands/qpid-queue-stats | 76 |
1 files changed, 44 insertions, 32 deletions
diff --git a/python/commands/qpid-queue-stats b/python/commands/qpid-queue-stats index ff28e5b50c..813c6e0cd2 100755 --- a/python/commands/qpid-queue-stats +++ b/python/commands/qpid-queue-stats @@ -20,8 +20,9 @@ # import os -import getopt +import optparse import sys +import re import socket import qpid from threading import Condition @@ -31,21 +32,6 @@ from qpid.connection import Connection from qpid.util import connect from time import sleep -defspecpath = "/usr/share/amqp/amqp.0-10.xml" -specpath = defspecpath -host = "localhost" - -def Usage (): - print "Usage: qpid-queue-stats [OPTIONS]" - print - print "Options:" - print " -a <broker-addr> default: localhost" - print " broker-addr is in the form: hostname | ip-address [:<port>]" - print " ex: localhost, 10.1.1.7:10000, broker-host:10000" - print " -s <amqp-spec-file> default:", defspecpath - print - sys.exit (1) - class Broker: def __init__ (self, text): colon = text.find (":") @@ -78,13 +64,15 @@ class BrokerManager: self.src = None self.broker = None self.objects = {} + self.filter = None + self.specpath="/usr/share/amqp/amqp.0-10.xml" def SetBroker (self, broker): self.broker = broker def ConnectToBroker (self): try: - self.spec = qpid.spec.load (specpath) + self.spec = qpid.spec.load (self.specpath) self.sessionId = "%s.%d" % (os.uname()[1], os.getpid()) self.conn = Connection (connect (self.broker.host, self.broker.port), self.spec) self.conn.start () @@ -94,6 +82,12 @@ class BrokerManager: print "Connect Error:", e exit (1) + def setFilter(self,filter): + self.filter = filter + + def setSpecpath(self,spec): + self.specpath = spec + def Disconnect (self): self.mclient.removeChannel (self.mchannel) @@ -120,6 +114,16 @@ class BrokerManager: self.objects[obj.id] = (name, obj, None) return + if len(self.filter) > 0 : + match = False + + for x in self.filter: + if x.match(name): + match = True + break + if match == False: + return + if last == None: lastSample = first else: @@ -148,19 +152,27 @@ class BrokerManager: ## ## Main Program ## +def main(): + p = optparse.OptionParser() + p.add_option('--broker-address','-a', default='localhost' , help='broker-addr is in the form: hostname | ip-address [:<port>] \n ex: localhost, 10.1.1.7:10000, broker-host:10000') + p.add_option('--amqp-spec-file','-s', default='"/usr/share/amqp/amqp.0-10.xml', help='the path to the amqp spec file') + p.add_option('--filter','-f' ,default=None ,help='a list of comma separated queue names (regex are accepted) to show') + + options, arguments = p.parse_args() + + host = options.broker_address + specpath = options.amqp_spec_file + filter = [] + if options.filter != None: + for s in options.filter.split(","): + filter.append(re.compile(s)) + + bm = BrokerManager () + bm.SetBroker (Broker (host)) + bm.setSpecpath(specpath) + bm.setFilter(filter) + bm.Display() + +if __name__ == '__main__': + main() -try: - (optlist, cargs) = getopt.getopt (sys.argv[1:], "s:a:") -except: - Usage () - -for opt in optlist: - if opt[0] == "-s": - specpath = opt[1] - if opt[0] == "-a": - host = opt[1] - -nargs = len (cargs) -bm = BrokerManager () -bm.SetBroker (Broker (host)) -bm.Display () |
