utils¶
The guidata.utils
module provides various utility helper functions
(pure python).
- guidata.utils.min_equals_max(min, max)[source]¶
Return True if minimium value equals maximum value Return False if not, or if maximum or minimum value is not defined
- guidata.utils.pairs(iterable)[source]¶
A simple generator that takes a list and generates pairs [ (l[0],l[1]), …, (l[n-2], l[n-1])]
- guidata.utils.add_extension(item, value)[source]¶
Add extension to filename item: data item representing a file path value: possible value for data item
- guidata.utils.bind(fct, value)[source]¶
Returns a callable representing the function ‘fct’ with it’s first argument bound to the value
if g = bind(f,1) and f is a function of x,y,z then g(y,z) will return f(1,y,z)
- guidata.utils.trace(fct)[source]¶
A decorator that traces function entry/exit used for debugging only
- guidata.utils.unicode_to_stdout(ustr)[source]¶
convert a unicode string to a byte string encoded for stdout output
- guidata.utils.update_dataset(dest, source, visible_only=False)[source]¶
Update dest dataset items from source dataset
- dest should inherit from DataSet, whereas source can be:
any Python object containing matching attribute names
or a dictionary with matching key names
For each DataSet item, the function will try to get the attribute of the same name from the source.
visible_only: if True, update only visible items
- guidata.utils.restore_dataset(source, dest)[source]¶
Restore dest dataset items from source dataset
This function is almost the same as update_dataset but requires the source to be a DataSet instead of the destination.
Symetrically from update_dataset, dest may also be a dictionary.
- guidata.utils.assert_interface_supported(klass, iface)[source]¶
Makes sure a class supports an interface
- guidata.utils.assert_interfaces_valid(klass)[source]¶
Makes sure a class supports the interfaces it declares
- class guidata.utils.FormatTime(hours_fmt='%d H ', min_fmt='%d min ', sec_fmt='%d s')[source]¶
Helper object that substitute as a string to format seconds into (nn H mm min ss s)
- guidata.utils.tic(cat)¶
Starting timer
- guidata.utils.toc(cat, msg='delta:')¶
Stopping timer
- guidata.utils.is_program_installed(basename)[source]¶
Return program absolute path if installed in PATH Otherwise, return None
- guidata.utils.run_program(name, args='', cwd=None, shell=True, wait=False)[source]¶
Run program in a separate process
- exception guidata.utils.ProgramError[source]¶
Exception raised when a shell command failed to execute.
- guidata.utils.alter_subprocess_kwargs_by_platform(**kwargs)[source]¶
Given a dict, populate kwargs to create a generally useful default setup for running subprocess processes on different platforms. For example, close_fds is set on posix and creation of a new console window is disabled on Windows.
This function will alter the given kwargs and return the modified dict.
- guidata.utils.run_shell_command(cmdstr, **subprocess_kwargs)[source]¶
Execute the given shell command.
Note that *args and **kwargs will be passed to the subprocess call.
If ‘shell’ is given in subprocess_kwargs it must be True, otherwise ProgramError will be raised.
If ‘executable’ is not given in subprocess_kwargs, it will be set to the value of the SHELL environment variable.
Note that stdin, stdout and stderr will be set by default to PIPE unless specified in subprocess_kwargs.
- Str cmdstr:
The string run as a shell command.
- Subprocess_kwargs:
These will be passed to subprocess.Popen.
- guidata.utils.getcwd_or_home()[source]¶
Safe version of getcwd that will fallback to home user dir.
This will catch the error raised when the current working directory was removed for an external program.
- guidata.utils.remove_backslashes(path)[source]¶
Remove backslashes in path
For Windows platforms only. Returns the path unchanged on other platforms.
This is especially useful when formatting path strings on Windows platforms for which folder paths may contain backslashes and provoke unicode decoding errors in Python 3 (or in Python 2 when future ‘unicode_literals’ symbol has been imported).