| #!/usr/bin/env python |
| # |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| #!/usr/bin/env python |
| # |
| # Autogenerated by Thrift Compiler (0.9.2) |
| # |
| # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING |
| # |
| # options string: py:utf8strings |
| # |
| |
| import sys |
| import pprint |
| from urlparse import urlparse |
| from thrift.transport import TTransport |
| from thrift.transport import TSocket |
| from thrift.transport import TSSLSocket |
| from thrift.transport import THttpClient |
| from thrift.protocol import TBinaryProtocol |
| |
| from storm import DistributedRPC |
| from storm.ttypes import * |
| |
| if len(sys.argv) <= 1 or sys.argv[1] == '--help': |
| print('') |
| print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] function [arg1 [arg2...]]') |
| print('') |
| print('Functions:') |
| print(' string execute(string functionName, string funcArgs)') |
| print('') |
| sys.exit(0) |
| |
| pp = pprint.PrettyPrinter(indent = 2) |
| host = 'localhost' |
| port = 9090 |
| uri = '' |
| framed = False |
| ssl = False |
| http = False |
| argi = 1 |
| |
| if sys.argv[argi] == '-h': |
| parts = sys.argv[argi+1].split(':') |
| host = parts[0] |
| if len(parts) > 1: |
| port = int(parts[1]) |
| argi += 2 |
| |
| if sys.argv[argi] == '-u': |
| url = urlparse(sys.argv[argi+1]) |
| parts = url[1].split(':') |
| host = parts[0] |
| if len(parts) > 1: |
| port = int(parts[1]) |
| else: |
| port = 80 |
| uri = url[2] |
| if url[4]: |
| uri += '?%s' % url[4] |
| http = True |
| argi += 2 |
| |
| if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed': |
| framed = True |
| argi += 1 |
| |
| if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl': |
| ssl = True |
| argi += 1 |
| |
| cmd = sys.argv[argi] |
| args = sys.argv[argi+1:] |
| |
| if http: |
| transport = THttpClient.THttpClient(host, port, uri) |
| else: |
| socket = TSSLSocket.TSSLSocket(host, port, validate=False) if ssl else TSocket.TSocket(host, port) |
| if framed: |
| transport = TTransport.TFramedTransport(socket) |
| else: |
| transport = TTransport.TBufferedTransport(socket) |
| protocol = TBinaryProtocol.TBinaryProtocol(transport) |
| client = DistributedRPC.Client(protocol) |
| transport.open() |
| |
| if cmd == 'execute': |
| if len(args) != 2: |
| print('execute requires 2 args') |
| sys.exit(1) |
| pp.pprint(client.execute(args[0],args[1],)) |
| |
| else: |
| print('Unrecognized method %s' % cmd) |
| sys.exit(1) |
| |
| transport.close() |