utils package
Submodules
utils._console module
A module for console utilities.
Copyright (C) 2020, fondlez, fondlez at protonmail.com
-
utils._console.
progress_bar
(*pargs, bar_format=None, **kwargs)[source] Customizes the output of tqdm ‘s progress bar.
The default bar format has been changed to eliminate the output of a “rate”, i.e. the default ‘it/s’ (iterations per second) part of the output.
Parameters: - *pargs – positional arguments to pass through.
- bar_format (str) – customized progress bar format.
- *kwargs – keyword arguments to pass through.
Returns: a customized iterable.
Return type: tqdm
utils._exception module
A module for exception handling utilities.
Copyright (C) 2020, fondlez, fondlez at protonmail.com
-
utils._exception.
set_exception_handler
(exception_type, exception, traceback, debug_hook=<built-in function excepthook>, debug_flag=False)[source] Sets the default exception handler based on an argument flag.
Parameters: - exception_type (object) – exception type.
- exception (object) – exception instance.
- traceback (
types.TracebackType
) – traceback object. - debug_hook (function) – hook.
- debug_flag (bool) – flag to determine whether to set a default exception handler or to create customized output.
utils._file module
A module for filesystem utilities.
Copyright (C) 2020, fondlez, fondlez at protonmail.com
-
utils._file.
remove_file_silent
(filename)[source] Removes a file silently even if it does not exist.
-
utils._file.
unixoutput
(filename, **kwargs)[source] Opens filename for output or writes to stdout in a Unix-like manner.
Command line tools that follow Unix conventions are expected to write to standard output (stdout) when an argument ‘-’ is passed to them, otherwise the argument filename is opened as normal for output.
Parameters: - filename (str) – filename for output.
- **kwargs – variable keyword arguments to pass through.
Returns: IO stream object.
utils._i18n module
A module for internationalization (i18n) utilities.
Copyright (C) 2020, fondlez, fondlez at protonmail.com
-
utils._i18n.
n_
(message)[source] Returns its input unchanged.
A transparent function for gettext language translation to protect members of data structures from translation before they are presented to a user.
utils._iterable module
A module containing utilities for searching and manipulating iterables.
Copyright (C) 2020, fondlez, fondlez at protonmail.com
-
utils._iterable.
first_true
(iterable, default=None, pred=None)[source] Returns the first true value from an iterable or a default value.
Parameters: - iterable – any iterable.
- pred – a function returning truthy or falsy.
- default – a default value.
Supplying a function acting as a predicate via the
pred
argument will use that function for truth testing. Ifpred
is None, items in the iterable are directly checked as truthy. If no truthy value is found, a default is returned.
-
utils._iterable.
index_or_none
(seq, value)[source] Returns the index of a value in an iterable if present, otherwise None.
Parameters: - seq – iterable.
- value – value.
-
utils._iterable.
multisort_by_attribute
(inplace, sortspecs)[source] In-place sorts nested attributed sequences by multiple attributes.
Example
>>> from collections import namedtuple >>> Vehicle = namedtuple('Vehicle', ['make', 'model', 'year', 'owner']) >>> car_park = [ ... Vehicle('Mercedes', 'F500', 2003, 'longbottom'), ... Vehicle('BMW', 'X3', 2012, 'malfoy'), ... Vehicle('Maclaren', 'F1', 2003, 'voldemort'), ... Vehicle('Bugatti', 'Veyron', 2009, 'potter')] >>> sortspecs = ( ... ('year', True), ... ('make', False), ... ('model', False), ... ('owner', False)) >>> multisort_by_attribute(car_park, sortspecs) >>> import pprint >>> pp = pprint.PrettyPrinter() >>> pp.pprint(car_park) [Vehicle(make='BMW', model='X3', year=2012, owner='malfoy'), Vehicle(make='Bugatti', model='Veyron', year=2009, owner='potter'), Vehicle(make='Maclaren', model='F1', year=2003, owner='voldemort'), Vehicle(make='Mercedes', model='F500', year=2003, owner='longbottom')]
Parameters: - inplace – iterable containing sequences with one or more attributes.
- sortspecs – tuples of attribute name and a sorting reverse flag.
utils._logging module
A module to support use of the built-in logging facility.
Copyright (C) 2020, fondlez, fondlez at protonmail.com
-
utils._logging.
configure_root_logger
(log_file=None, log_level=None, format=None, date_format=None)[source] Configures basic logging of the root logger.
If a log filename is supplied, the root logger is configured to log to file, otherwise it is configured to log to
sys.stderr
.Parameters:
-
utils._logging.
disable_logging
()[source] Disables logging globally.
-
utils._logging.
get_log
(name='')[source] Returns a named logger object or the root logger.
-
utils._logging.
re_enable_logging
()[source] Re-enables logging globally.
utils._path module
A module for retrieving and manipulating path information.
Copyright (C) 2020, fondlez, fondlez at protonmail.com
-
utils._path.
extless
(path)[source] Returns the filename without a file extension from a path.
-
utils._path.
gen_find_file
(filepat, top)[source] Yields the paths matching a file pattern.
Parameters: Yields: str – matching path string.
utils._timer module
A module for a stopwatch timer.
Copyright (C) 2020, fondlez, fondlez at protonmail.com
utils._warcraft module
A module for handling information peculiar to World of Warcraft.
Copyright (C) 2020, fondlez, fondlez at protonmail.com
-
utils._warcraft.
decimal_gold
(copper_value, disable=False)[source] Converts the copper value of WoW currency to decimal gold.
Parameters: Returns: decimal gold value.
Return type:
-
utils._warcraft.
format_gold
(copper_value, format=None, disable=False)[source] Converts the copper value of WoW currency to its denominations.
Parameters: Returns: formatted gold string.
Return type:
Module contents
Copyright (C) 2020, fondlez, fondlez at protonmail.com