source: fedd/fedd_spewlog.py @ 62f3dd9

axis_examplecompt_changesinfo-ops
Last change on this file since 62f3dd9 was 62f3dd9, checked in by Ted Faber <faber@…>, 13 years ago

allow command line progams to expand tildes. Added a class derived from OptionParser? to make that easily available.

  • Property mode set to 100755
File size: 2.5 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
29cert, fid, url = wrangle_standard_options(opts)
30
31if opts.exp_name and opts.exp_certfile:
32    sys.exit("Only one of --experiment_cert and --experiment_name permitted");
33elif opts.exp_certfile:
34    exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
35elif opts.exp_name:
36    exp_id = { 'localname' : opts.exp_name }
37else:
38    sys.exit("specify one of --experiment_cert and --experiment_name")
39
40if opts.logfile:
41    try:
42        out = open(opts.logfile, "w")
43    except IOError,e:
44        sys.exit("Cannot open logfile: %s" %e)
45else:
46    out = sys.stdout
47
48req = { 'experiment': exp_id }
49
50status = "starting"
51log = ""
52log_offset = 0
53update = opts.update
54while status == 'starting':
55    try:
56        resp_dict = do_rpc(req,
57                url, opts.transport, cert, opts.trusted, 
58                serialize_only=opts.serialize_only,
59                tracefile=opts.tracefile,
60                caller=service_caller('Info'), responseBody="InfoResponseBody")
61    except RPCException, e:
62        exit_with_fault(e)
63    except RuntimeError, e:
64        sys.exit("Error processing RPC: %s" % e)
65
66    if not opts.serialize_only:
67        status = resp_dict.get('experimentStatus', None)
68    else:
69        status = "active"
70    log = resp_dict.get('allocationLog', None)
71    if not status:
72        sys.exit("No status in Info response??")
73    if log:
74        if len(log) > log_offset:
75            print >>out, log[log_offset:],
76            out.flush()
77            log_offset = len(log)
78    if status == 'starting': 
79        time.sleep(update)
80print >>out
81print >>out, status
82out.close()
Note: See TracBrowser for help on using the repository browser.