1 | #!/usr/local/bin/python |
---|
2 | |
---|
3 | import sys |
---|
4 | |
---|
5 | from federation.remote_service import service_caller |
---|
6 | from federation.client_lib import client_opts, exit_with_fault, RPCException,\ |
---|
7 | wrangle_standard_options, do_rpc, get_experiment_names, info_format |
---|
8 | |
---|
9 | class exp_data_opts(client_opts): |
---|
10 | def __init__(self): |
---|
11 | client_opts.__init__(self) |
---|
12 | self.add_option("--experiment_cert", dest="exp_certfile", |
---|
13 | type="string", help="experiment certificate file") |
---|
14 | self.add_option("--experiment_name", dest="exp_name", |
---|
15 | type="string", help="human readable experiment name") |
---|
16 | self.add_option("--data", dest="data", default=[], |
---|
17 | action="append", type="choice", |
---|
18 | choices=("id", "experimentdescription", "federant", "vtopo", |
---|
19 | "vis", "log", "status", "embedding"), |
---|
20 | help="data to extract") |
---|
21 | |
---|
22 | parser = exp_data_opts() |
---|
23 | (opts, args) = parser.parse_args() |
---|
24 | cert, fid = wrangle_standard_options(opts) |
---|
25 | |
---|
26 | if opts.exp_name and opts.exp_certfile: |
---|
27 | sys.exit("Only one of --experiment_cert and --experiment_name permitted") |
---|
28 | elif opts.exp_certfile: |
---|
29 | exp_id = { 'fedid': fedid(file=opts.exp_certfile) } |
---|
30 | elif opts.exp_name: |
---|
31 | exp_id = { 'localname' : opts.exp_name } |
---|
32 | else: |
---|
33 | sys.exit("specify one of --experiment_cert and --experiment_name") |
---|
34 | |
---|
35 | req = { 'experiment': exp_id } |
---|
36 | |
---|
37 | try: |
---|
38 | resp_dict = do_rpc(req, |
---|
39 | opts.url, opts.transport, cert, opts.trusted, |
---|
40 | serialize_only=opts.serialize_only, |
---|
41 | tracefile=opts.tracefile, |
---|
42 | caller=service_caller('Info'), responseBody='InfoResponseBody') |
---|
43 | except RPCException, e: |
---|
44 | exit_with_fault(e) |
---|
45 | except RuntimeError, e: |
---|
46 | sys.exit("Error processing RPC: %s" % e) |
---|
47 | |
---|
48 | formatter = info_format() |
---|
49 | for d in opts.data: |
---|
50 | try: |
---|
51 | formatter(resp_dict, d) |
---|
52 | except RuntimeError, e: |
---|
53 | print >>sys.stderr, "Warning: %s" % e |
---|