rattail.util

Utilities

class rattail.util.OrderedDict(*args, **kwargs)[source]
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_object_spec(obj)[source]

Returns the “object spec” string for the given object.

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.prettify(text)[source]

Return a “prettified” version of text.

rattail.util.pretty_boolean(value)[source]

Returns 'Yes' or 'No' or empty string if value is None

rattail.util.pretty_hours(hours=None, seconds=None)[source]

DEPRECATED

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 call func for each. If a progress factory kwarg is provided, then a progress instance will be created and updated along the way.

rattail.util.shlex_join(split_command)[source]

Wrapper which invokes shlex.join() if available; otherwise a workaround is implemented.

cf. https://stackoverflow.com/a/50022816

rattail.util.simple_error(error)[source]

Return a “simple” string for the given error. Result will look like:

"ErrorClass: Description for the error"

However the logic checks to ensure the error has a descriptive message first; if it doesn’t the result will just be:

"ErrorClass"