Package commons :: Module misc
[hide private]
[frames] | no frames]

Module misc

source code

Miscellanea.

Classes [hide private]
  timeout_exception
  TerminalController
From http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475116.
  color_test
Functions [hide private]
 
sendmail(sender, to, subj, body) source code
 
days(td)
Returns the ceil(days in the timedelta td).
source code
 
generate_bit_fields(count)
A generator of [2^i] for i from 0 to (count - 1).
source code
 
wall_clock(*args, **kwds)
A simple timer for code sections.
source code
 
settimeout(secs)
Set the signal handler for SIGALRM to raise timeout_exception, and call alarm(secs).
source code
 
cleartimeout() source code
 
default_if_none(x, d)
Returns x if it's not None, otherwise returns d.
source code
 
seq(f, g)
Evaluate 0-ary functions f then g, returning g().
source code
 
run(cmd)
Run the given command (a list of program and argument strings) and return the stdout as a string, raising a CalledProcessError if the program exited with a non-zero status.
source code
 
remove_colors(s)
Removes ANSI escape codes (e.g.
source code
Variables [hide private]
  PIPE = -1
  remove_colors_pat = re.compile(r'\x1b\[[0-9;]*m')
  ITIMER_PROF = 2
  ITIMER_REAL = 0
  ITIMER_VIRTUAL = 1
  NSIG = 65
  SIGABRT = 6
  SIGALRM = 14
  SIGBUS = 7
  SIGCHLD = 17
  SIGCLD = 17
  SIGCONT = 18
  SIGFPE = 8
  SIGHUP = 1
  SIGILL = 4
  SIGINT = 2
  SIGIO = 29
  SIGIOT = 6
  SIGKILL = 9
  SIGPIPE = 13
  SIGPOLL = 29
  SIGPROF = 27
  SIGPWR = 30
  SIGQUIT = 3
  SIGRTMAX = 64
  SIGRTMIN = 34
  SIGSEGV = 11
  SIGSTOP = 19
  SIGSYS = 31
  SIGTERM = 15
  SIGTRAP = 5
  SIGTSTP = 20
  SIGTTIN = 21
  SIGTTOU = 22
  SIGURG = 23
  SIGUSR1 = 10
  SIGUSR2 = 12
  SIGVTALRM = 26
  SIGWINCH = 28
  SIGXCPU = 24
  SIGXFSZ = 25
  SIG_DFL = 0
  SIG_IGN = 1
  __package__ = 'commons'
  accept2dyear = 1
  altzone = 14400
  daylight = 1
  timezone = 18000
  tzname = ('EST', 'EDT')
Function Details [hide private]

generate_bit_fields(count)

source code 

A generator of [2^i] for i from 0 to (count - 1). Useful for, e.g., enumerating bitmask flags:

   red, yellow, green, blue = generate_bit_fields(4)
   color1 = blue
   color2 = red | yellow
Parameters:
  • count (int) - The number of times to perform the left-shift.

wall_clock(*args, **kwds)

source code 

A simple timer for code sections.

Example:

 t = [0]
 with wall_clock(t):
   sleep(1)
 print "the sleep operation took %d seconds" % t[0]
Parameters:
  • output (index-writeable) - The resulting time is put into index 0 of output.
Decorators:
  • @contextmanager

run(cmd)

source code 

Run the given command (a list of program and argument strings) and return the stdout as a string, raising a CalledProcessError if the program exited with a non-zero status. Different from check_call because I return the (piped) stdout.

remove_colors(s)

source code 

Removes ANSI escape codes (e.g. those for terminal colors).