rattail.util
¶
Utilities
- rattail.util.capture_output(*args, **kwargs)[source]¶
Runs
command
and returns any output it produces.
- rattail.util.data_diffs(local_data, host_data, fields=None, fuzzy_fields=None, fuzz_factor=None)[source]¶
Find all (relevant) fields which differ between the host and local data values for a given record.
- rattail.util.get_class_hierarchy(klass, topfirst=True)[source]¶
Returns a list of all classes in the inheritance chain for the given class.
For instance:
class A(object): pass class B(A): pass class C(B): pass get_class_hierarchy(C) # -> [A, B, C]
Specify
topfirst=False
to get[C, B, A]
instead.
- rattail.util.get_package_name(name)[source]¶
Generic logic to derive a “package name” from the given name.
E.g. if
name
is “Poser Plus” this will return “poser_plus”
- rattail.util.get_studly_prefix(name)[source]¶
Generic logic to derive a “studly prefix” from the given name.
E.g. if
name
is “Poser Plus” this will return “PoserPlus”
- rattail.util.hours_as_decimal(hours, places=2)[source]¶
Convert the given
datetime.timedelta
object into a Decimal whose value is in terms of hours.
- rattail.util.import_module_path(module_path)[source]¶
Import an arbitrary Python module.
Warning
This function is deprecated; please use
importlib.import_module()
instead.- Parameters:
module_path¶ – String referencing a module by its “dotted path”.
- Returns:
The referenced module.
- rattail.util.import_reload(module)[source]¶
Reload a module.
Warning
This function is deprecated; please use
importlib.reload()
instead.- Parameters:
module¶ – An already-loaded module.
- Returns:
The module.
- rattail.util.load_entry_points(group, ignore_errors=False)[source]¶
Load a set of
setuptools
-style entry points.This is a compatibility wrapper around
wuttjamaican.util.load_entry_points()
. New code should use that instead; this will eventually be removed.
- rattail.util.load_object(spec)[source]¶
Load an arbitrary object from a module, according to a specifier.
This is a compatibility wrapper around
wuttjamaican.util.load_object()
. New code should use that instead; this will eventually be removed.
- rattail.util.pretty_quantity(value, empty_zero=False)[source]¶
Return a “pretty” version of the given value, as string. This is meant primarily for use with things like order quantities, so that e.g. 1.0000 => 1
- rattail.util.progress_loop(func, items, factory, *args, **kwargs)[source]¶
This will iterate over
items
and callfunc
for each. If a progressfactory
kwarg is provided, then a progress instance will be created and updated along the way.