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

Module util
source code

Utility functions for Cheesecake project.

Classes [hide private]
StdoutRedirector Redirect stdout to a temporary file.

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

Variables [hide private]
PAD_TEXT  
PAD_VALUE  

Function Details [hide private]

run_cmd(cmd, env=None)

source code 

Run command and return its return code and its output.

>>> run_cmd('/bin/true')
(0, '')

command_successful(cmd)

source code 

Returns True if command exited normally, False otherwise.

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

pad_with_dots(msg, length=PAD_TEXT)

source code 

Pad text with dots up to given length.

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

pad_left_spaces(value, length=PAD_VALUE)

source code 

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_right_spaces(value, length=PAD_VALUE)

source code 

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_msg(msg, value, msg_length=PAD_TEXT, value_length=PAD_VALUE)

source code 

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_line(char="=", length=(PAD_TEXT+PAD_VALUE+1))

source code 

Return line consisting of 'char' characters.

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

unzip_package(package, destination)

source code 

Unzip given package to the destination directory.

Return name of unpacked directory or None on error.

untar_package(package, destination)

source code 

Untar given package to the destination directory.

Return name of unpacked directory or None on error.

unegg_package(package, destination)

source code 

Unpack given egg to the destination directory.

Return name of unpacked directory or None on error.

mkdirs(dir)

source code 

Make directory with parent directories as needed.

Don't throw an exception if directory exists.

time_function(function)

source code 

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

Variables Details [hide private]

PAD_TEXT

Value:
40                                                                    
      

PAD_VALUE

Value:
4