source: fedd/fedd_spewlog.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.6 KB
Line 
1#!/usr/local/bin/python
2
3import sys
4import time
5
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 spew_opts(client_opts):
11    def __init__(self):
12        client_opts.__init__(self)
13        self.add_option("--experiment_cert", dest="exp_certfile",
14                action='callback', callback=self.expand_file, type='str',
15                help="experiment name certificate file")
16        self.add_option("--experiment_name", dest="exp_name",
17                type="string", help="human readable experiment name")
18        self.add_option("--logfile", dest="logfile", default=None,
19                action='callback', callback=self.expand_file, type='str',
20                help="File to write log to")
21        self.add_option('--update_time', dest='update', type='int', default=10,
22                help='how often to update the printed log')
23
24# Keep requesting experiment status and printing updates to the log until the
25# experiment is done being created.
26parser = spew_opts()
27(opts, args) = parser.parse_args()
28
29try:
30    cert, fid, url = wrangle_standard_options(opts)
31except RuntimeError, e:
32    sys.exit("%s" %e)
33
34if opts.exp_name and opts.exp_certfile:
35    sys.exit("Only one of --experiment_cert and --experiment_name permitted");
36elif opts.exp_certfile:
37    exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
38elif opts.exp_name:
39    exp_id = { 'localname' : opts.exp_name }
40else:
41    sys.exit("specify one of --experiment_cert and --experiment_name")
42
43if opts.logfile:
44    try:
45        out = open(opts.logfile, "w")
46    except IOError,e:
47        sys.exit("Cannot open logfile: %s" %e)
48else:
49    out = sys.stdout
50
51req = { 'experiment': exp_id }
52
53status = "starting"
54log = ""
55log_offset = 0
56update = opts.update
57while status == 'starting':
58    try:
59        resp_dict = do_rpc(req,
60                url, opts.transport, cert, opts.trusted, 
61                serialize_only=opts.serialize_only,
62                tracefile=opts.tracefile,
63                caller=service_caller('Info'), responseBody="InfoResponseBody")
64    except RPCException, e:
65        exit_with_fault(e)
66    except RuntimeError, e:
67        sys.exit("Error processing RPC: %s" % e)
68
69    if not opts.serialize_only:
70        status = resp_dict.get('experimentStatus', None)
71    else:
72        status = "active"
73    log = resp_dict.get('allocationLog', None)
74    if not status:
75        sys.exit("No status in Info response??")
76    if log:
77        if len(log) > log_offset:
78            print >>out, log[log_offset:],
79            out.flush()
80            log_offset = len(log)
81    if status == 'starting': 
82        time.sleep(update)
83print >>out
84print >>out, status
85out.close()
Note: See TracBrowser for help on using the repository browser.