-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
59 lines (37 loc) · 1.51 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# coding: utf-8
import config
from modules.client import parse
from modules.log import logsetup, logger
import thriftpy
tracelogs_thrift = thriftpy.load(config.thrift.get('rules'),
module_name=config.thrift.get('module'))
from thriftpy.rpc import client_context
from thriftpy.protocol import TCyBinaryProtocolFactory
from thriftpy.transport import TCyBufferedTransportFactory
from modules.controller import TracesThriftClientController
from socket import error as socket_error
def main():
args = parse()
args_dict = dict(args.__dict__)
logsetup(args_dict)
try:
# create thrift client
with client_context(tracelogs_thrift.TraceLogService,
args.thrift_server, args.thrift_port,
proto_factory=TCyBinaryProtocolFactory(),
trans_factory=TCyBufferedTransportFactory()
) as thrift_client:
client = TracesThriftClientController(client=thrift_client,
module=tracelogs_thrift)
output = client.dispatchCall(args.command, args)
print output
except thriftpy.thrift.TException as ex:
logger.error('Thrift error: %s' % ex.message)
except socket_error as sex:
logger.error('Network error: %s' % sex)
except Exception as ex:
logger.error('Application error: %s' % ex)
raise
if __name__ == '__main__':
main()