source: fedd/fedd_ns2topdl.py @ e65150a

axis_examplecompt_changesinfo-ops
Last change on this file since e65150a was a0c2866, checked in by Ted Faber <faber@…>, 14 years ago

Make sure there is an abac directory.

  • Property mode set to 100755
File size: 2.1 KB
Line 
1#!/usr/local/bin/python
2
3import sys
4
5from federation import topdl
6from federation.remote_service import service_caller
7from federation.client_lib import client_opts, exit_with_fault, RPCException, \
8        wrangle_standard_options, do_rpc, get_experiment_names, save_certfile
9
10class ns_topdl_opts(client_opts):
11    def __init__(self):
12        client_opts.__init__(self)
13        self.add_option("--file", dest="file", 
14                action='callback', callback=self.expand_file, type='str',
15                help="experiment description file")
16        self.add_option("--output", dest="outfile", type="string",
17                help="output topdl file")
18
19parser = ns_topdl_opts()
20(opts, args) = parser.parse_args()
21
22try:
23    cert, fid, url = wrangle_standard_options(opts)
24except RuntimeError, e:
25    sys.exit("%s" %e)
26
27if opts.file:
28    try:
29        contents = "".join([l for l in open(opts.file, "r")])
30    except EnvironmentError, e:
31        sys.exit("Can't read %s: %s" % (opts.file, e))
32else:
33    sys.exit("Must specify an experiment description (--file)")
34
35msg = { 'description': { 'ns2description': contents }, }
36
37if opts.debug > 1: print >>sys.stderr, msg
38
39try:
40    resp_dict = do_rpc(msg, 
41            url, opts.transport, cert, opts.trusted, 
42            serialize_only=opts.serialize_only,
43            tracefile=opts.tracefile,
44            caller=service_caller('Ns2Topdl'),
45            responseBody="Ns2TopdlResponseBody")
46except RPCException, e:
47    exit_with_fault(e)
48except RuntimeError, e:
49    sys.exit("Error processing RPC: %s" % e)
50
51if 'experimentdescription' in resp_dict:
52    if 'topdldescription' in resp_dict['experimentdescription']:
53        exp = resp_dict['experimentdescription']['topdldescription']
54        top = topdl.Topology(**exp)
55    else:
56        sys.exit("Bad response: could not translate")
57elif opts.serialize_only:
58    sys.exit(0)
59else:
60    sys.exit("Bad response. %s" % e.message)
61
62if opts.outfile:
63    try:
64        f = open(opts.outfile, "w")
65        print >>f, topdl.topology_to_xml(top, top="experiment")
66        f.close()
67    except EnvironmentError, e:
68        sys.exit("Can't write to %s: %s" % (opts.outfile, e))
69else:
70    print topdl.topology_to_xml(top, top="experiment")
Note: See TracBrowser for help on using the repository browser.