frutils package¶
Submodules¶
frutils.defaults module¶
Default values for both frutils and the frkl-suite of tools (if appropriate).
frutils.frutils module¶
Utility methods that are used across the frkl-suite (https://frkl.io) of tools.
-
class
frutils.frutils.
IgnoreUndefinedJinjaVariable
(hint=None, obj=missing, name=None, exc=<class 'jinja2.exceptions.UndefinedError'>)[source]¶ Bases:
jinja2.runtime.Undefined
-
class
frutils.frutils.
StringYAML
(**kwargs)[source]¶ Bases:
ruamel.yaml.main.YAML
Wraps :class:~YAML to be able to dump a string from a yaml object.
More details: http://yaml.readthedocs.io/en/latest/example.html#output-of-dump-as-a-string
Parameters: **kwargs (dict) – arguments for the underlying :class:~YAML class
-
frutils.frutils.
add_key_to_dict
(target_dict, key_path, value, split_token='.', ordered=True)[source]¶ Add a key into the key path of a dictionary.
Parameters:
-
frutils.frutils.
append_key_to_dict
(target_dict, key_path, value, split_token='.')[source]¶ Appends a key into the key path of a dictionary.
The value either needs to be a list or tuple, or nonexistent. If this is not the case, this function will throw an exception.
Parameters:
-
frutils.frutils.
calculate_cache_location_for_url
(url)[source]¶ Utility method to get a unique path that can be used for caching a download.
-
frutils.frutils.
can_passwordless_sudo
()[source]¶ Checks if the user can use passwordless sudo on this host.
-
frutils.frutils.
dict_merge
(dct, merge_dct, copy_dct=True)[source]¶ Recursive dict merge. Inspired by :meth:
dict.update()
, instead of updating only top-level keys, dict_merge recurses down into dicts nested to an arbitrary depth, updating keys. Themerge_dct
is merged intodct
.Copied from: https://gist.github.com/angstwad/bf22d1822c38a92ec0a9
Parameters: Returns: the merged dict (original or copied)
Return type:
-
frutils.frutils.
ensure_parent_dir
(path)[source]¶ Makes sure a parent directory exists.
Parameters: path – the path to a file Returns: the parent dir Return type: str
-
frutils.frutils.
flatten_lists
(lists)[source]¶ Utility method to flatten a list of lists.
This will only flatten the first sublist, any deeper list-structure will be preserved.
Parameters: lists (list) – a list of lists Returns: the flattened list Return type: list
-
frutils.frutils.
get_key_path_value
(source_dict, key_path, split_token='.', default_value=None)[source]¶ Queries the source dict tree for the register key, split up using the split_token.
Parameters: Returns: the value for the matching in the tree, or None
Return type:
-
frutils.frutils.
is_list_of_strings
(input_obj)[source]¶ Helper method to determine whether an object is a list or tuple of only strings (or string_types).
Parameters: input_obj (object) – the object in question Returns: whether or not the object is a list of strings Return type: bool
-
frutils.frutils.
is_templated
(text, jinja_delimiter_profile={'block_end_string': '%}', 'block_start_string': '{%', 'variable_end_string': '}}', 'variable_start_string': '{{'})[source]¶ Utility method to determine whether a string has template markers in it.
This is pretty simplistic, it only checks whether one of the template marker strings (e.g. ‘}}’, or ‘{%’) are contained in the text. It doesn’t check for matching opening/ closed brackets etc.
Parameters: Returns: whether the text is templated or not
Return type:
-
frutils.frutils.
is_url_or_abbrev
(url, abbrevs={'bb': ['https://bitbucket.org', '/', -9876, '/', -9876, '/', 'src', '/', '{{ branch }}', '/'], 'gh': ['https://raw.githubusercontent.com', '/', -9876, '/', -9876, '/', '{{ branch }}', '/'], 'gl': ['https://gitlab.com', '/', -9876, '/', -9876, '/', 'raw', '/', '{{ branch }}', '/']})[source]¶
-
frutils.frutils.
merge_list_of_dicts
(dicts, starting_dict=None)[source]¶ Merges a list of dicts.
Parameters: Returns: the merged dict (same as starting_dict)
Return type:
-
frutils.frutils.
readable
(python_object, out='raw', safe=True, indent=0)[source]¶ Utility method to print out readable strings from python objects (mostly dicts).
Parameters:
-
frutils.frutils.
readable_json
(python_object, indent=0)[source]¶ Shortcut for using the
readable()
method with the ‘json’ format.
-
frutils.frutils.
readable_pformat
(python_object, indent=0)[source]¶ Shortcut for using the
readable()
method with the ‘pformat’ format.
-
frutils.frutils.
readable_raw
(python_object, indent=0)[source]¶ Shortcut for using the
readable()
method with the ‘raw’ format.
-
frutils.frutils.
readable_yaml
(python_object, indent=0, safe=True)[source]¶ Shortcut for using the
readable()
method with the ‘yaml’ format.
-
frutils.frutils.
reindent
(s, numSpaces, keep_current=True)[source]¶ Reindents a string.
Parameters: Returns: the indented string
Return type:
-
frutils.frutils.
replace_string
(template_string, replacement_dict=None, block_start_string='{%', block_end_string='%}', variable_start_string='{{', variable_end_string='}}', additional_jinja_extensions=None, local_env_vars_key='LOCAL_ENV', ignore_undefined=False)[source]¶ Replace template markers with values from a replacement dictionary within a string.
Parameters: - template_string (str) – the template string
- replacement_dict (dict) – the dictionary with the replacement strings
- block_start_string (str) – the string to indicate a template block start
- block_end_string (str) – the string to indicate a template block end
- variable_start_string (str) – the string to indicate a template variable start
- variable_end_string (str) – the string to indicate a template variable end
- additional_jinja_extensions (list) – a list of jinja extensions to use
- local_env_vars_key (str) – the key to use under which to put local environment variables
- ignore_undefined (bool) – whether to skip replacement when encountering undefined variables (True), or error out (False)
frutils.frutils_cli module¶
Module contents¶
Top-level package for frutils.