invirtualenv.utility module

General utility functionality module

invirtualenv.utility.change_uid_gid(user_uid=None, user_gid=None)

preexec_fn to change the uid/gid when using subprocess

Parameters:
  • user_uid (int, optional) – The user UID to set to, does not set user uid if this is not passed
  • user_gid (int, optional) – The user GID to set to, does not set the gid if this is not passed
invirtualenv.utility.chown_recursive(path, uid, gid)

Change the ownership of all files and directories in path

Parameters:
  • path (str) – The root path to start changing the ownership at
  • uid, (int) – The uid to change the ownership to
  • gid, (int) – The gid to change the ownership to
invirtualenv.utility.csv_list(value)

Convert a comma separated string into a list

Parameters:value (str) – The string object to convert to a list
Returns:A list based on splitting the string on the ‘,’ character
Return type:list
invirtualenv.utility.display_header(text='', width=None, separator=None, outfile=None, collapse=False)

Display a textual header message. :param text: The text to print/display :type text: str :param width: The width (text wrap) of the header message.

This will be the current terminal width as determined by the ‘stty size’ shell command if not specified.
Parameters:
  • separator (str, optional) – The character or string to use as a horizontal separator. Will use ‘=’ if one is not specified.
  • outfile (File, optional) – The File object to print the header text to. This will use sys.stdout if not specified.

:param : :type : return:

invirtualenv.utility.get_terminal_size()

Get the terminal rows and columns if we are running on an interactive terminal. :returns: * rows (int) – The number of rows on the current terminal.

  • columns (int) – The number of columns on the current terminal.
invirtualenv.utility.str_format_env(value)

Substitute values with environment variables in a string

Parameters:value (str) – The string object to be formatted and converted into a list
Returns:With env variable values substituded
Return type:str
invirtualenv.utility.str_to_bool(value)

Convert a string too a bool object

Parameters:value (str) – The string object to convert to a bool. The following case insensitive strings evaluate to True [‘true’, 1’, ‘up’, ‘on’]
Returns:Boolean based on the string
Return type:bool
invirtualenv.utility.str_to_dict(value)

Convert a newline terminated string of key=value into a dictionary.

Parameters:value (str) – The string object to convert to a dictionary
Returns:Dictionary based on the string
Return type:dict
invirtualenv.utility.str_to_list(value)

Convert a newline terminated string into a list. Any empty lines will be removed from the result list.

Parameters:value (str) – The string object to convert to a list
Returns:List based on the string
Return type:list
invirtualenv.utility.update_recursive(basedict, updatedict)

Recursively run update on a dictionary

Parameters:
  • basedict (dict) – First dictionary, which will contain the updated result
  • updatedict (dict) – Second dictionary that will be be updated to basedict, conflicts will be replaced with the values from this dictionary.
Returns:

basedict updated to contain the values from updatedict

Return type:

dict

invirtualenv.utility.update_recursive_generator(basedict, updatedict)

Recursively run update on a dictionary

Parameters:
  • basedict (dict) – First dictionary, which will contain the updated result
  • updatedict (dict) – Second dictionary that will be be updated to basedict, conflicts will be replaced with the values from this dictionary.
Returns:

basedict updated to contain the values from updatedict

Return type:

dict

invirtualenv.utility.which(command)

Function searches the path for the command executable

Parameters:command (str) –
Returns:Path to the command
Return type:str
Raises:CommandNotFound: – Command was not found