source: fedd/fedd_spewlog.py @ aa9a417

axis_examplecompt_changesinfo-opsversion-3.01version-3.02
Last change on this file since aa9a417 was d743d60, checked in by Ted Faber <faber@…>, 14 years ago

Totally refactor fedd_client.py into component scripts. The previous layout
have become a twisty hell of misdirected OOP and learning python run amok.
This version is actually pretty readable and will be much easier to build on.

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