util Package

util Package

console Module

class sts.util.console.Tee(target)[source]

Bases: object

__init__(target)[source]
close()[source]
tee_src(src)[source]
tee_stderr()[source]
tee_stdout()[source]
class sts.util.console.color[source]

Bases: object

BLUE = '\x1b[1;34m'
B_BLUE = '\x1b[1;44m'
B_CRIMSON = '\x1b[1;48m'
B_CYAN = '\x1b[1;46m'
B_GRAY = '\x1b[1;40m'
B_GREEN = '\x1b[1;42m'
B_MAGENTA = '\x1b[1;45m'
B_RED = '\x1b[1;41m'
B_WHITE = '\x1b[1;47m'
B_YELLOW = '\x1b[1;43m'
CRIMSON = '\x1b[1;38m'
CYAN = '\x1b[1;36m'
GRAY = '\x1b[1;30m'
GREEN = '\x1b[1;32m'
MAGENTA = '\x1b[1;35m'
NORMAL = '\x1b[1;m'
RED = '\x1b[1;31m'
WHITE = '\x1b[1;37m'
YELLOW = '\x1b[1;33m'
class sts.util.console.msg[source]
BEGIN = '\x1b[1;'
BLUE = '34m'
B_BLACK = '40m'
B_BLUE = '44m'
B_CRIMSON = '48m'
B_CYAN = '46m'
B_GRAY = '47m'
B_GREEN = '42m'
B_MAGENTA = '45m'
B_RED = '41m'
B_YELLOW = '43m'
CRIMSON = '38m'
CYAN = '36m'
END = '\x1b[1;m'
GRAY = '30m'
GREEN = '32m'
MAGENTA = '35m'
RED = '31m'
WHITE = '37m'
YELLOW = '33m'
static event(message)[source]
static event_success(message)[source]
static event_timeout(message)[source]
static fail(message)[source]
global_io_master = None
static interactive(message)[source]
static mcs_event(message)[source]
static raw_input(message)[source]
static set_io_master(io_master)[source]
static success(message)[source]
static unset_io_master()[source]

convenience Module

class sts.util.convenience.ExitCode(exit_code)[source]

Bases: object

__init__(exit_code)[source]
sts.util.convenience.find(f, seq)[source]

Return first item in sequence where f(item) == True.

sts.util.convenience.find_index(f, seq)[source]

Return the index of the first item in sequence where f(item) == True.

sts.util.convenience.find_port(port_spec)[source]
sts.util.convenience.find_ports(**kwargs)[source]
sts.util.convenience.is_sorted(l)[source]
sts.util.convenience.is_strictly_sorted(l)[source]
sts.util.convenience.mkdir_p(dst)[source]
sts.util.convenience.port_used(address='127.0.0.1', port=6633)[source]
sts.util.convenience.timestamp_string()[source]

deferred_io Module

Created on Feb 25, 2012

@author: aw, cs

class sts.util.deferred_io.DeferredIOWorker(io_worker)[source]

Bases: object

Wrapper class for RecocoIOWorkers.

Rather than actually sending/receiving right away, queue the data. Then there are separate methods for actually sending the data via the wrapped io_worker

io_worker: io_worker to wrap

__init__(io_worker)[source]
block()[source]

Stop allowing data through until unblock() is called

close()[source]
consume_receive_buf(l)[source]

called by client to consume receive buffer

currently_blocked[source]

Return whether we are currently allowing data through

fileno()[source]
io_worker_receive_handler(io_worker)[source]

called from io_worker (recoco thread, after the Select loop pushes onto io_worker)

peek_receive_buf()[source]

Called by client

send(data)[source]

send data from the client side. fire and forget.

set_receive_handler(block)[source]

Called by client

socket[source]
unblock()[source]

Allow data through, and flush buffers

io_master Module

class sts.util.io_master.IOMaster[source]

Bases: object

an IO handler that handles the select work for our IO worker

__init__()[source]
close_all()[source]
create_worker_for_socket(socket)[source]

Return an IOWorker wrapping the given socket.

grab_workers_rwe()[source]
handle_workers_rwe(rlist, wlist, elist)[source]
monkey_time_sleep()[source]

monkey patches time.sleep to use this io_masters’s time.sleep

poll()[source]
raw_input(prompt)[source]

raw_input replacement that enables background IO to take place. NOTE: this migrates the IO to a specifically created BackgroundIOThread while readline’s raw_input is running. raw_input must run in the main thread so the terminal is properly restored on CTRL-C. The Background IO thread is notified and terminates before the return of this function, so no concurrent IO takes place.

select(timeout=0)[source]
sleep(timeout)[source]
class sts.util.io_master.STSIOWorker(socket, on_close)[source]

Bases: pox.lib.ioworker.io_worker.IOWorker

An IOWorker that works with our IOMaster

__init__(socket, on_close)[source]
close()[source]

Register this socket to be closed. fire and forget

fileno()[source]

Return the wrapped sockets’ fileno

send(data)[source]

precompute_cache Module

class sts.util.precompute_cache.PrecomputeCache[source]

Bases: object

__init__()[source]
already_done(input_sequence)[source]
update(input_sequence)[source]
class sts.util.precompute_cache.PrecomputePowerSetCache[source]

Bases: object

__init__()[source]
already_done(input_sequence)[source]
sequence_id = count(1)
update(input_sequence)[source]

procutils Module

sts.util.procutils.kill_procs(child_processes, kill=None, verbose=True, timeout=5)[source]
sts.util.procutils.popen_filtered(name, args, cwd=None, env=None)[source]
sts.util.procutils.split_up(f, l)[source]

rpc_forker Module

class sts.util.rpc_forker.Forker[source]

Bases: object

Easily fork a job and retrieve the results

__init__()[source]
fork(task_name, *args, **kws)[source]

Fork off a child process and invoke the child RPC method. Return the json_hash sent by the child.

Raises a ValueError if task_name is not registered.

register_task(task_name, code_block)[source]

Register a new task to be invoked by this Forker. Parameters: - task_name: the name of the task to be run, later passed to fork() - code_block: a function object to be invoked via RPC

in the child process. Must not depend on any environment state contained in its closure.
class sts.util.rpc_forker.LocalForker[source]

Bases: sts.util.rpc_forker.Forker

fork(task_name, *args, **kws)[source]
static kill_all()[source]
register_task(task_name, code_block)[source]
class sts.util.rpc_forker.RemoteForker(server_info_list)[source]

Bases: sts.util.rpc_forker.Forker

__init__(server_info_list)[source]

cycles through server_info_list for each invocation of fork()

fork(task_name, *args, **kws)[source]
register_task(task_name, code_block)[source]
class sts.util.rpc_forker.TaskRegistry[source]

Bases: object

Maintains code for tasks to be Forked.

__init__()[source]
get_task(task_name)[source]
register_task(task_name, code_block)[source]
sts.util.rpc_forker.test_serialize_request(methodname, *args)[source]
sts.util.rpc_forker.test_serialize_response(*args)[source]

tabular Module

class sts.util.tabular.Tabular(*cols)[source]

Bases: object

__init__(*cols)[source]
show(data)[source]