Package cheesecake :: Module util
[show private | hide private]
[frames | no frames]

Module cheesecake.util

Utility functions for Cheesecake project.


Classes
StdoutRedirector Redirect stdout to a temporary file.

Function Summary
  command_successful(cmd)
Returns True if command exited normally, False otherwise.
  mkdirs(dir)
Make directory with parent directories as needed.
  pad_left_spaces(value, length)
Pad value with spaces at left up to given length.
  pad_line(char, length)
Return line consisting of 'char' characters.
  pad_msg(msg, value, msg_length, value_length)
Pad message with dots and pad value with spaces.
  pad_right_spaces(value, length)
Pad value with spaces at left up to given length.
  pad_with_dots(msg, length)
Pad text with dots up to given length.
  run_cmd(cmd, env, max_timeout)
Run command and return its return code and its output.
  time_function(function)
Measure function execution time.
  unegg_package(package, destination)
Unpack given egg to the destination directory.
  untar_package(package, destination)
Untar given package to the destination directory.
  unzip_package(package, destination)
Unzip given package to the destination directory.

Variable Summary
int PAD_TEXT = 40                                                                    
int PAD_VALUE = 4                                                                     

Function Details

command_successful(cmd)

Returns True if command exited normally, False otherwise.

>>> command_successful('/bin/true')
True
>>> command_successful('this-command-doesnt-exist')
False

mkdirs(dir)

Make directory with parent directories as needed.

Don't throw an exception if directory exists.

pad_left_spaces(value, length=4)

Pad value with spaces at left up to given length.

>>> pad_left_spaces(15, 4)
'  15'
>>> pad_left_spaces(123456, 2)
'123456'
>>> len(pad_left_spaces("")) == PAD_VALUE
True

pad_line(char='=', length=45)

Return line consisting of 'char' characters.

>>> pad_line('*', 3)
'***'
>>> pad_line(length=10)
'=========='

pad_msg(msg, value, msg_length=40, value_length=4)

Pad message with dots and pad value with spaces.

>>> pad_msg("123456", 77, msg_length=10, value_length=4)
'123456 ...  77'
>>> pad_msg("123", u"45", msg_length=5, value_length=3)
u'123 . 45'

pad_right_spaces(value, length=4)

Pad value with spaces at left up to given length.

>>> pad_right_spaces(123, 5)
'123  '
>>> pad_right_spaces(12.1, 5)
'12.1 '

pad_with_dots(msg, length=40)

Pad text with dots up to given length.

>>> pad_with_dots("Hello world", 20)
'Hello world ........'
>>> pad_with_dots("Exceeding length", 10)
'Exceeding length'

run_cmd(cmd, env=None, max_timeout=None)

Run command and return its return code and its output.

>>> run_cmd('/bin/true')
(0, '')
>>> run_cmd('/bin/cat', max_timeout=0.2)
(1, 'Time exceeded')

time_function(function)

Measure function execution time.

Return (return value, time taken) tuple.

>>> def fun(x):
...     return x*2
>>> ret, time_taken = time_function(lambda: fun(5))
>>> ret
10

unegg_package(package, destination)

Unpack given egg to the destination directory.

Return name of unpacked directory or None on error.

untar_package(package, destination)

Untar given package to the destination directory.

Return name of unpacked directory or None on error.

unzip_package(package, destination)

Unzip given package to the destination directory.

Return name of unpacked directory or None on error.


Variable Details

PAD_TEXT

Type:
int
Value:
40                                                                    

PAD_VALUE

Type:
int
Value:
4                                                                     

Generated by Epydoc 2.1 on Fri Feb 9 02:15:12 2007 http://epydoc.sf.net