jobcontrol.utils

class jobcontrol.utils.cached_property(func, name=None, doc=None)[source]

A decorator that converts a function into a lazy property. The function wrapped is called the first time to retrieve the result and then that calculated result is used the next time you access the value:

class Foo(object):

    @cached_property
    def foo(self):
        # calculate something important here
        return 42

The class has to have a __dict__ in order for this property to work.

jobcontrol.utils.import_object(name)[source]

Import an object from a module, by name.

Parameters:name – The object name, in the package.module:name format.
Returns:The imported object
jobcontrol.utils.get_storage_from_url(url)[source]

Get a storage from URL.

Storages URLs are in the format:

  • <scheme>://
  • <class>+<scheme>:// Load <class>, pass the URL removing <class>+
jobcontrol.utils.get_storage_from_config(config)[source]

Not implemented yet

jobcontrol.utils.short_repr(obj, maxlen=50)[source]

Returns a “shortened representation” of an object; that is, the return value of repr(obj) limited to a certain length, with a trailing ellipsis '...' if text was truncated.

This function is mainly used in order to provide a nice representation of local variables in TracebackInfo objects

jobcontrol.utils.json_dumps(obj)[source]
jobcontrol.utils.trim_string(s, maxlen=1024, ellps='...')[source]

Trim a string to a maximum length, adding an “ellipsis” indicator if the string was trimmed

class jobcontrol.utils.FrameInfo(filename, lineno, name, line, locs)[source]
class jobcontrol.utils.TracebackInfo[source]

Class used to hold information about an error traceback.

This is meant to be serialized & stored in the database, instead of a full traceback object, which is not serializable.

It holds information about:

  • the exception that caused the thing to fail
  • the stack frames (with file / line number, function and exact code around the point in which the exception occurred)
  • a representation of the local variables for each frame.

A textual representation of the traceback information may be retrieved by using str() or unicode() on the object instance.

classmethod from_current_exc()[source]

Instantiate with traceback from sys.exc_info().

classmethod from_tb(tb)[source]

Instantiate from a traceback object.

format()[source]

Format traceback for printing

format_color()[source]

Format traceback for printing on 256-color terminal

class jobcontrol.utils.ProgressReport(name, current=None, total=None, status_line=None, children=None)[source]

Class used to represent progress reports.

It supports progress reporting on a multi-level “tree” structure; each level can have its own progress status, or it will generate it automatically by summing up values from children.

current[source]
total[source]
percent[source]
percent_human[source]
progress_label[source]
color_css_rgb[source]
classmethod from_table(table, base_name=None)[source]
Parameters:table

a list of tuples: (name, current, total, status_line).

  • If there is a tuple with name == None -> use as the object’s current/total report
  • Find all the “namespaces” and use to build progress sub-objects
class jobcontrol.utils.NotSerializableRepr(obj, exception=None)[source]
class jobcontrol.utils.ExceptionPlaceholder(orig)[source]
class jobcontrol.utils.LogRecord(**kwargs)[source]

Wrapper around logging messages.

  • Guarantees that the contained object can be pickled
  • Improves things like “created” -> now automatically a datetime object
  • Stores exception / TracebackInfo in separate attributes
  • Uses better field names
classmethod from_record(record)[source]

Previous topic

jobcontrol.interfaces

Next topic

jobcontrol.utils.depgraph

This Page