csdms

wmtexe.reporter module

Logging and reporting tools for a wmt-exe environment.

class wmtexe.reporter.Reporter(id, server, filename, **kwds)[source]

Bases: threading.Thread

Event reporter for wmt-exe tasks.

Parameters:

id : str

A unique UUID for a job.

server : str

URL of API server.

filename : str

Name of status file.

**kwds

Arbitrary keyowrd arguments.

Attributes

daemon A boolean value indicating whether this thread is a daemon thread (True) or not (False).
ident Thread identifier of this thread or None if it has not been started.
name A string used for identification purposes only.

Methods

getName()
isAlive() Return whether the thread is alive.
isDaemon()
is_alive() Return whether the thread is alive.
join([timeout]) Wait until the thread terminates.
run() Start reporting on a task.
setDaemon(daemonic)
setName(name)
start() Start the thread’s activity.
stop() Stop reporting on a task.
stopped() Check whether reporting has stopped.
run()[source]

Start reporting on a task.

stop()[source]

Stop reporting on a task.

stopped()[source]

Check whether reporting has stopped.

Returns:

bool

True if reporting has stopped.

exception wmtexe.reporter.TaskCompleted[source]

Bases: exceptions.Exception

Exception thrown when a wmt-exe task completes.

class wmtexe.reporter.TaskStatus(id, server, filename, pid=None, prefix='.')[source]

Bases: wmtexe.reporter.WmtTaskReporter

Task status manager for a wmt-exe environment.

Parameters:

id : str

A unique UUID for a job.

server : str

URL of API server.

filename : str

Name of status file.

pid : str, optional

Process id (default is None).

prefix : str, optional

Path to base directory (default is current directory).

Attributes

elapsed Get the elapsed time in the simulation.
id Get id of task.
server Get server URL.
status_file Get the status file.

Methods

__call__()
get_status() Get task status.
report(status, message) Report task status using requests.
report_error(message) Report an error.
report_status() Report task status at regular intervals until task completes.
report_success(message) Report successful task completion.
report_with_curl(status, message) Report task status using curl.
running() Test whether the simulation is running.
status_with_line_nos([n]) Get status prepended with line numbers.
elapsed

Get the elapsed time in the simulation.

Returns:

float

The elapsed time, in seconds.

get_status()[source]

Get task status.

Returns:

str

The status as a YAML stream.

report_status()[source]

Report task status at regular intervals until task completes.

Returns:

Reponse

Response from server.

running()[source]

Test whether the simulation is running.

Returns:

bool

True if simulation is running.

status_file

Get the status file.

Returns:

str

Name of status file.

status_with_line_nos(n=10)[source]

Get status prepended with line numbers.

Parameters:

n : int, optional

Number of lines to display.

Returns:

str

The status as a YAML stream.

class wmtexe.reporter.WmtTaskReporter(id, server)[source]

Bases: object

Reporter for wmt-exe tasks.

Parameters:

id : str

A unique UUID for a job.

server : str

URL of API server.

Attributes

id Get id of task.
server Get server URL.

Methods

report(status, message) Report task status using requests.
report_error(message) Report an error.
report_success(message) Report successful task completion.
report_with_curl(status, message) Report task status using curl.
id

Get id of task.

Returns:

str

The task id.

report(status, message)[source]

Report task status using requests.

Parameters:

status : str

Type of report.

message : str

Message for report.

Returns:

Reponse

Response from server.

report_error(message)[source]

Report an error.

Parameters:

message : str

Error message.

Returns:

Reponse

Response from server.

report_success(message)[source]

Report successful task completion.

Parameters:

message : str

Success message.

Returns:

Reponse

Response from server.

report_with_curl(status, message)[source]

Report task status using curl.

Parameters:

status : str

Type of report.

message : str

Message for report.

Returns:

str

Response from server.

server

Get server URL.

Returns:

str

The server URL.

wmtexe.reporter.add_line_numbers(lines, start=0, fn=None)[source]

Prefix lines with numbers.

Parameters:

lines : list or list-like of str

Lines to be prefixed with a number.

start : int, optional

The index at which line numbers start (default is 0).

fn : str, optional

File name to prepend to line number (default is None).

Returns:

list

Lines prefixed with numbers.

wmtexe.reporter.load_status_from_lines(lines)[source]

Load task status from strings.

Parameters:

lines : list or list-like of str

List of lines containing task status information.

Returns:

dict

The task status, or an empty dict on error.

wmtexe.reporter.logger = <logging.Logger object>

Logger : Instance of Logging class.

class wmtexe.reporter.open_reporter(id, server, fname)[source]

Bases: object

Manager for a reporter in a wmt-exe environment.

Parameters:

id : str

A unique UUID for a job.

server : str

URL of API server.

fname : str

Name of status file.

wmtexe.reporter.read_wmt_status(fname)[source]

Read the WMT status from a file.

Parameters:

fname : str

WMT status file.

Returns:

dict

The task status, or an empty dict on error.

class wmtexe.reporter.redirect_output(name, log_dir='.', join=False)[source]

Bases: object

Manager for output and error logs.

Parameters:

name : str

Log file name.

log_dir : str, optional

Path to logging directory (default is current directory).

join : bool, optional

Set to True to combine logs (default is False).

wmtexe.reporter.tail(fname, n=10, with_tail='tail')[source]

Get the last lines in a file.

Parameters:

fname : str

File name.

n : int, optional

Number of lines to get (default is 10).

with_tail : str, optional

The ‘tail’ command to use (default is tail).

Returns:

str

The last lines in file, or None on error.

wmtexe.reporter.tail_with_line_numbers(fname, n=10, with_tail='tail', with_wc='wc')[source]

Get the last lines in a file, with line numbers.

Parameters:

fname : str

File name.

n : int, optional

Number of lines to get (default is 10).

with_tail : str, optional

The ‘tail’ command to use (default is tail).

with_wc : str, optional

The ‘wc’ command to use (default is wc).

Returns:

list

The last lines in file, prefixed with numbers.

wmtexe.reporter.wc_l(fname, with_wc='wc')[source]

Count the lines in a file.

Parameters:

fname : str

File name.

with_wc : str, optional

The ‘wc’ command to use (default is wc).

Returns:

int

Number of lines in file, or None on error.