Package elisa :: Package core :: Package utils :: Module misc

Module misc

source code

Miscellaneaous utilities that don't need their own module because they are reasonnably small.

Functions
string
env_var_expand(var_name)
Expand the given environment variable content.
source code
list of strings
env_var_explode_list(var_name, default='')
Explode a list of values stored in an environment variable as a single string.
source code
string
un_camelify(camel_string)
Convert CamelCase styled strings to lower_cased style.
source code
 
is_hildon_desktop_running() source code
 
get_distro() source code
 
get_os_name() source code
list of int
linux_pidof(program_name)
Get the Linux process id of the given program name.
source code
str
get_user_desktop_name()
Detect the Desktop environment used by the user.
source code
 
pkg_resources_copy_dir(resource_spec, resource_dir, dest_dir)
Copy a directory recursively using pkg_resources.
source code
 
run_functional_tests_check()
Check whether functional tests should be run or not.
source code
 
chainDeferredIgnoringResult(first, chained) source code
 
mappings_from_text(text)
Unserialise mappings from a string text.
source code
 
text_from_mappings(mappings)
Takes a mappings and return a serialised form.
source code
 
read_mappings(iter_lines)
Setuptools compliant deserialiser for mappings.
source code
Variables
  FUNCTIONAL_TESTS_STR = 'RUN_FUNCTIONAL_TESTS'
  LINESEP = '\n'

Imports: platform, os, re, subprocess, SkipTest, pkg_resources


Function Details

env_var_expand(var_name)

source code 

Expand the given environment variable content. If it contains other references to environment variables, they are expanded too.

Supported platforms are win32 and linux.

Example of use:

  >>> env_var_expand('$HOME')
  >>> '/home/phil'
Parameters:
  • var_name (string) - environment variable
Returns: string
Raises:
  • ValueError - if current system's platform is not windows or linux

env_var_explode_list(var_name, default='')

source code 

Explode a list of values stored in an environment variable as a single string. On win32 the item separator is ';' and on other platforms it is ':'.

Example of use:

  >>> env_var_explode_list('$PATH')
  >>> ['/usr/bin','/bin']
Parameters:
  • var_name (string) - environment variable
  • default (string) - value to use if environment variable not found
Returns: list of strings

un_camelify(camel_string)

source code 

Convert CamelCase styled strings to lower_cased style.

Parameters:
  • camel_string (string) - CamelStyled string to convert
Returns: string

linux_pidof(program_name)

source code 

Get the Linux process id of the given program name. Because multiple processes can exist, we return a list of the pids.

Returns: list of int
the list of running pids of given program name

get_user_desktop_name()

source code 

Detect the Desktop environment used by the user. On windows this returns empty string. On other OSes we can currently detect gnome, kde and xfce.

Returns: str
the desktop name used (either gnome, kde or xfce)

run_functional_tests_check()

source code 

Check whether functional tests should be run or not. This is done by checking whether the FUNCTIONAL_TESTS_STR environment variable is set to 'True'. If it is not explictly set to True, this method raises a twisted.trial.unittest.SkipTest (saying that the functional test is not run).

This method allows functional tests to have an easy way to check if they should be run. This simple example checks in the setup (but it could also be done inside the method itself):

   from elisa.core.utils.misc import run_functional_tests_check
   [...]
   class MyFunctionalTestCase(TestCase):

       def setUp(self):
           run_functional_tests_check()
           ...

mappings_from_text(text)

source code 

Unserialise mappings from a string text. Mappings are lists of 2-uplets.

Example:

   key1 = value1
   key2 = value2a
   key2 = value2b

is deserialised into:

   [("key1", "value1"), ("key2", "value2a"), ("key2", "value2b")]

text_from_mappings(mappings)

source code 

Takes a mappings and return a serialised form. Mappings are list of 2-uplets.

Example:

   [("key1", "value1"), ("key2", "value2a"), ("key2", "value2b")]

is serialised into:

   key1 = value1
   key2 = value2a
   key2 = value2b