Sha256: 216c07acbef063ffe42dc74e78ae9082b4c539331c67253b4cedffe78e6eb236

Contents?: true

Size: 1.67 KB

Versions: 53

Compression:

Stored size: 1.67 KB

Contents

"""Control of and utilities for debugging."""

import os


# When debugging, it can be helpful to force some options, especially when
# debugging the configuration mechanisms you usually use to control debugging!
# This is a list of forced debugging options.
FORCED_DEBUG = []


class DebugControl(object):
    """Control and output for debugging."""

    def __init__(self, options, output):
        """Configure the options and output file for debugging."""
        self.options = options
        self.output = output

    def should(self, option):
        """Decide whether to output debug information in category `option`."""
        return (option in self.options or option in FORCED_DEBUG)

    def write(self, msg):
        """Write a line of debug output."""
        if self.should('pid'):
            msg = "pid %5d: %s" % (os.getpid(), msg)
        self.output.write(msg+"\n")
        self.output.flush()

    def write_formatted_info(self, info):
        """Write a sequence of (label,data) pairs nicely."""
        for line in info_formatter(info):
            self.write(" %s" % line)


def info_formatter(info):
    """Produce a sequence of formatted lines from info.

    `info` is a sequence of pairs (label, data).  The produced lines are
    nicely formatted, ready to print.

    """
    label_len = max([len(l) for l, _d in info])
    for label, data in info:
        if data == []:
            data = "-none-"
        if isinstance(data, (list, tuple)):
            prefix = "%*s:" % (label_len, label)
            for e in data:
                yield "%*s %s" % (label_len+1, prefix, e)
                prefix = ""
        else:
            yield "%*s: %s" % (label_len, label, data)

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
libv8-8.4.255.0.1 vendor/depot_tools/third_party/coverage/debug.py
libv8-8.4.255.0 vendor/depot_tools/third_party/coverage/debug.py
libv8-7.8.279.23.0beta1 vendor/depot_tools/third_party/coverage/debug.py
libv8-7.4.288.28.0beta1 vendor/depot_tools/third_party/coverage/debug.py
libv8-7.3.492.27.3beta1 vendor/depot_tools/third_party/coverage/debug.py
libv8-7.3.492.27.1 vendor/depot_tools/third_party/coverage/debug.py
libv8-7.3.492.27.0 vendor/depot_tools/third_party/coverage/debug.py
libv8-7.3.492.27.0beta1 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.7.288.46.1 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.7.288.46.0 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.7.288.46.1beta0 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.3.292.48.1 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.3.292.48.0 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.3.292.48.0beta2 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.3.292.48.0beta1 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.2.414.42.1 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.2.414.42.0 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.2.414.42.0beta1 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.0.286.54.3 vendor/depot_tools/third_party/coverage/debug.py
libv8-6.0.286.54.2 vendor/depot_tools/third_party/coverage/debug.py