Tools Module

class inetsix.tools.InetsixTools[source]

Class to expose some useful functions for day to day scripting.

InetsixTools class provides a list of functions used in different script. Using such class to centralize tools help to maintain and enhance code instead of updating all scripts to be enhanced.

static dict_to_list(dict_input=None, key=None)[source]

Transform a dictionary to a list.

Parameters:
  • dict_input (dict()) – Dictionary used to create list
  • key (str) – If defined, only value from this key is extracted
Returns:

A list of entries

Return type:

list()

static download_file(remote_file=None, verbose=False)[source]

Function to download file from HTTP server.

Download file from an HTTP or HTTPS server and save file locally

Parameters:
  • remote_file (str) – URL to download
  • verbose – Manage verbosity level
Returns:

File name to access to local copy of the file

Return type:

str

static file_basename(file_path)[source]

Extract Filename from complete path.

Parameters:file_path (str) – file path to a file
Returns:filename without path
Return type:str
static get_list_files(path=None, extension='j2', debug=False)[source]

List files in a specific directory

Return a list of files found in a directory. A filter can be used to search specific file extensions.

Parameters:
  • path (str) – Path to search for file
  • extension (str) – Extension to search files. Default is j2
  • debug (bool) – Trigger to enable verbosity
Returns:

A list of files found in path

Return type:

list

static jprint(data=[])[source]

PPrint wrapper to display list and dict.

Parameters:data (list or dict) – data to display python structure
static list_unique_values(myList=[])[source]

Remove duplicate entries in a list.

Parameters:myList (list()) – List where duplicates must be removed
Returns:List without duplicates
Return type:list()
static load_constant(key_name, default='UNSET', verbose=False)[source]

Set up constant value from OS Environment.

Help to define CONSTANT from OS Environment. If it is not defined, then, fallback to default value provided within parameters

Example:
>>> from inetsix.tools import InetsixTools
>>> CVP_USER = InetsixTools.load_constant(key_name='CVP_USER', default='username')
>>> print CVP_USER
myUsername
Parameters:
  • key_name (str) – VAR to lookup in os.environment
  • default (str) – Default value to use if key_name is not defined.
  • verbose (bool) – Boolean to activate verbos mode (Optional, expected values: debug level)
Returns:

Value for variable

Return type:

str