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 | action='callback', callback=self.expand_file, type='str', |
---|
14 | help="experiment certificate file") |
---|
15 | self.add_option("--experiment_name", dest="exp_name", |
---|
16 | type="string", help="human readable experiment name") |
---|
17 | self.add_option("--data", dest="data", default=[], |
---|
18 | action="append", type="choice", |
---|
19 | choices=("id", "experimentdescription", "federant", "vtopo", |
---|
20 | "vis", "log", "status", "embedding"), |
---|
21 | help="data to extract") |
---|
22 | |
---|
23 | parser = exp_data_opts() |
---|
24 | (opts, args) = parser.parse_args() |
---|
25 | cert, fid, url = wrangle_standard_options(opts) |
---|
26 | |
---|
27 | if opts.exp_name and opts.exp_certfile: |
---|
28 | sys.exit("Only one of --experiment_cert and --experiment_name permitted") |
---|
29 | elif opts.exp_certfile: |
---|
30 | exp_id = { 'fedid': fedid(file=opts.exp_certfile) } |
---|
31 | elif opts.exp_name: |
---|
32 | exp_id = { 'localname' : opts.exp_name } |
---|
33 | else: |
---|
34 | sys.exit("specify one of --experiment_cert and --experiment_name") |
---|
35 | |
---|
36 | req = { 'experiment': exp_id } |
---|
37 | |
---|
38 | try: |
---|
39 | resp_dict = do_rpc(req, |
---|
40 | url, opts.transport, cert, opts.trusted, |
---|
41 | serialize_only=opts.serialize_only, |
---|
42 | tracefile=opts.tracefile, |
---|
43 | caller=service_caller('Info'), responseBody='InfoResponseBody') |
---|
44 | except RPCException, e: |
---|
45 | exit_with_fault(e) |
---|
46 | except RuntimeError, e: |
---|
47 | sys.exit("Error processing RPC: %s" % e) |
---|
48 | |
---|
49 | formatter = info_format() |
---|
50 | for d in opts.data: |
---|
51 | try: |
---|
52 | formatter(resp_dict, d) |
---|
53 | except RuntimeError, e: |
---|
54 | print >>sys.stderr, "Warning: %s" % e |
---|