comparison env/bin/cq @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 #!/Users/cmdms/OneDrive-UOB/Development/Projects/2021/sam-consensus-v3/env/bin/python3
2 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish, dis-
8 # tribute, sublicense, and/or sell copies of the Software, and to permit
9 # persons to whom the Software is furnished to do so, subject to the fol-
10 # lowing conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 # IN THE SOFTWARE.
22 #
23 import getopt, sys
24 import boto.sqs
25 from boto.sqs.connection import SQSConnection
26 from boto.exception import SQSError
27
28 def usage():
29 print 'cq [-c] [-q queue_name] [-o output_file] [-t timeout] [-r region]'
30
31 def main():
32 try:
33 opts, args = getopt.getopt(sys.argv[1:], 'hcq:o:t:r:',
34 ['help', 'clear', 'queue=',
35 'output=', 'timeout=', 'region='])
36 except:
37 usage()
38 sys.exit(2)
39 queue_name = ''
40 output_file = ''
41 timeout = 30
42 region = ''
43 clear = False
44 for o, a in opts:
45 if o in ('-h', '--help'):
46 usage()
47 sys.exit()
48 if o in ('-q', '--queue'):
49 queue_name = a
50 if o in ('-o', '--output'):
51 output_file = a
52 if o in ('-c', '--clear'):
53 clear = True
54 if o in ('-t', '--timeout'):
55 timeout = int(a)
56 if o in ('-r', '--region'):
57 region = a
58 if region:
59 c = boto.sqs.connect_to_region(region)
60 if c is None:
61 print 'Invalid region (%s)' % region
62 sys.exit(1)
63 else:
64 c = SQSConnection()
65 if queue_name:
66 try:
67 rs = [c.create_queue(queue_name)]
68 except SQSError as e:
69 print 'An Error Occurred:'
70 print '%s: %s' % (e.status, e.reason)
71 print e.body
72 sys.exit()
73 else:
74 try:
75 rs = c.get_all_queues()
76 except SQSError as e:
77 print 'An Error Occurred:'
78 print '%s: %s' % (e.status, e.reason)
79 print e.body
80 sys.exit()
81 for q in rs:
82 if clear:
83 n = q.clear()
84 print 'clearing %d messages from %s' % (n, q.id)
85 elif output_file:
86 q.dump(output_file)
87 else:
88 print q.id, q.count(vtimeout=timeout)
89
90 if __name__ == "__main__":
91 main()
92