recipyCommon.utils module¶
-
recipyCommon.utils.
create_argument_wrapper
(log_input_function, log_output_function, arg_loc, kwarg_name, input_values, output_values, default_value, source)¶ Determines how an argument should be logged based on another argument.
Used in combination with PatchFileOpenLike.
For example, a netcdf file can be opened using: netCDF4.Dataset(file_name, mode=’r’) and written using: netCDF4.Dataset(file_name, mode=’w’). The method named for opening and saving are the same. So, this wrapper determines whether a file should be logged as an input or as an output, based in the mode keyword argument.
- Args:
- log_input_function (function): Log function that should be called if
- the file name refers to an input.
- log_output_function (function): Log function that should be called if
- the file name refers to an output.
arg_loc (int): index of the file name in the functions’ argument list. kwarg_name (str):key of the keyword argument that should be used to
determine whether the file is an input or an output.- input_values (str or list): values of kwarg_name for which the file
- ame should be logged as an input.
- output_values (string or list): values of kwarg_name for which the
- file name should be logged as an output.
- default_value (str): value for kwarg_name that should be used if
- kwarg_name is not set.
- source (str): name of the module that defines the function that is
- wrapped (is currently not used).
The wrapper for netCDF4 looks like:
``` wrapper = create_argument_wrapper(log_input, log_output, 0, ‘mode’, ‘ra’,
‘aw’, ‘r’, ‘netCDF4’)- Returns:
- function: wrapped function that logs inputs and outputs when it is
- called.
-
recipyCommon.utils.
create_wrapper
(function, arg_loc, source)¶
-
recipyCommon.utils.
json_serializer
(obj)¶ JSON serializer for objects not serializable by default json code
-
recipyCommon.utils.
multiple_insert
(lst, items)¶ Inserts all of the items into the list lst
-
recipyCommon.utils.
open_or_create_db
(path='/home/docs/.recipy/recipyDB.json')¶ Get a TinyDB database object for the recipy database.
This opens the DB, creating it if it doesn’t exist.
-
recipyCommon.utils.
patch_function
(mod, function, wrapper)¶
-
recipyCommon.utils.
recursive_find_module
(name, path)¶
-
recipyCommon.utils.
recursive_getattr
(obj, attr)¶ Does the same as the builtin getattr function, but works with multiple sub-attributes.
So, for example:
getattr(obj, ‘attribute’)
works fine, but
getattr(obj, ‘attribute.anotherattribute’)
doesn’t. This fixes that. Use in exactly the same way as getattr.
-
recipyCommon.utils.
recursive_setattr
(obj, attr, value)¶ Does the same as the builtin setattr function, but works with multiple sub-attributes.
So, for example:
setattr(obj, ‘attribute’, value)
works fine, but
setattr(obj, ‘attribute.anotherattribute’, value)
doesn’t. This fixes that. Use in exactly the same way as getattr.
-
recipyCommon.utils.
reset_patches_table
(db_path='/home/docs/.recipy/recipyDB.json')¶