selinonlib.helpers module

Selinonlib library helpers.

selinonlib.helpers.check_conf_keys(dict_, known_conf_opts)[source]

Check supplied configuration options against known configuration options.

Parameters:
  • dict – dict with configuration options
  • known_conf_opts – known configuration options
Returns:

configuration options that are now known with their values

selinonlib.helpers.dict2json(dict_, pretty=True, safe=True)[source]

Convert dict to json (string).

Parameters:
  • dict (dict) – dictionary to be converted
  • pretty (bool) – if True, nice formatting will be used
  • safe (bool) – perform safe dump
Returns:

formatted dict in json

Return type:

str

selinonlib.helpers.dict2strkwargs(dict_)[source]

Convert a dictionary into arguments to a string representation that can be used as arguments to a function.

selinonlib.helpers.expr2str(expr)[source]

Convert a Python expression into a Python code.

selinonlib.helpers.get_function_arguments(func)[source]

Get arguments of function.

Parameters:func – function to parse arguments
Returns:list of arguments that predicate function expects
selinonlib.helpers.git_previous_version(file_path)[source]

Get hash of previous version of a file in Git CVS.

Parameters:file_path – a path to file to get previous version from
Returns:git hash of previous version and it’s depth from master
Return type:tuple
selinonlib.helpers.git_previous_version_file(git_hash, file_path, tmp_dir=None)[source]

Get previous version of a file in Git CVS.

Parameters:
  • git_hash – git hash for the given file
  • file_path – a path to file to get previous version from
  • tmp_dir – a directory to store the content of previous file version
Returns:

a path to a temporary file with content from previous version

selinonlib.helpers.keylist2str(keylist)[source]

Convert keylist to a string representation.

Parameters:keylist (list) – keylist to be converted
Returns:string representation
Return type:str
selinonlib.helpers.pushd(new_dir)[source]

Traverse a directory tree in a pushd/popd manner.

Parameters:new_dir (str) – new directory to cd to