4.6. foundations.environment

environment.py

Platform:
Windows, Linux, Mac Os X.
Description:
Provides environment variables manipulation objects.

Others:

4.6.1. Module Attributes

foundations.environment.LOGGER

4.6.2. Functions

foundations.environment.getTemporaryDirectory()[source]

Returns the system temporary directory.

Returns:System temporary directory.
Return type:unicode
foundations.environment.getSystemApplicationDataDirectory()[source]

Returns the system Application data directory.

Examples directories:

- 'C:\Users\$USER\AppData\Roaming' on Windows 7.
- 'C:\Documents and Settings\$USER\Application Data' on Windows XP.
- '/Users/$USER/Library/Preferences' on Mac Os X.
- '/home/$USER' on Linux.
Returns:User Application data directory.
Return type:unicode
foundations.environment.getUserApplicationDataDirectory()[source]
Returns the user Application directory.
If the user Application directory is not available, the function will fallback to system temporary directory.

Examples directories:

- 'C:\Users\$USER\AppData\Roaming\Provider\Application' on Windows 7.
- 'C:\Documents and Settings\$USER\Application Data\Provider\Application' on Windows XP.
- '/Users/$USER/Library/Preferences/Provider/Application' on Mac Os X.
- '/home/$USER/.Provider/Application' on Linux.
Returns:User Application directory.
Return type:unicode

4.6.3. Classes

class foundations.environment.Environment(*args, **kwargs)[source]

Bases: object

Defines methods to manipulate environment variables.

Initializes the class.

Usage:

>>> environment = Environment(JOHN="DOE", DOE="JOHN")
>>> environment.setValues()
True
>>> import os
>>> os.environ["JOHN"]
u'DOE'
>>> os.environ["DOE"]
u'JOHN'
Parameters:
  • *args (*) – Variables.
  • **kwargs (*) – Variables : Values.
variables[source]

Property for self.__variables attribute.

Returns:self.__variables.
Return type:dict
getValues(*args)[source]

Gets environment variables values.

Usage:

>>> environment = Environment("HOME")
>>> environment.getValues()
{'HOME': u'/Users/JohnDoe'}
>>> environment.getValues("USER")
{'HOME': u'/Users/JohnDoe', 'USER': u'JohnDoe'}
Parameters:*args (*) – Additional variables names to retrieve values from.
Returns:Variables : Values.
Return type:dict
setValues(**kwargs)[source]

Sets environment variables values.

Usage:

>>> environment = Environment()
>>> environment.setValues(JOHN="DOE", DOE="JOHN")
True
>>> import os
>>> os.environ["JOHN"]
'DOE'
>>> os.environ["DOE"]
'JOHN'
Parameters:**kwargs (*) – Variables : Values.
Returns:Method success.
Return type:unicode
Note:Any variable with a None value will be skipped.
getValue(variable=None)[source]

Gets given environment variable value.

Parameters:variable (unicode) – Variable to retrieve value.
Returns:Variable value.
Return type:unicode
Note:If the variable argument is not given the first self.__variables attribute value will be returned.
setValue(variable, value)[source]

Sets given environment variable with given value.

Parameters:
  • variable (unicode) – Variable to set value.
  • value (unicode) – Variable value.
Returns:

Method success.

Return type:

bool