swh.scanner.output module#

class swh.scanner.output.Color(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

BLUE = '\x1b[94m'#
GREEN = '\x1b[92m'#
RED = '\x1b[91m'#
END = '\x1b[0m'#
swh.scanner.output.colorize(text: str, color: Color)[source]#
swh.scanner.output.get_output_class(mode='text')[source]#

return the output class that correspond to mode

class swh.scanner.output.BaseOutput(root_path: str, nodes_data: MerkleNodeInfo, source_tree: Directory, config: Dict[str, Any], web_client: WebAPIClient)[source]#

Bases: ABC

base class for object able to display scan result

get_path_name(node)[source]#
abstract show()[source]#
class swh.scanner.output.SummaryOutput(root_path: str, nodes_data: MerkleNodeInfo, source_tree: Directory, config: Dict[str, Any], web_client: WebAPIClient)[source]#

Bases: BaseOutput

display a summary of the scan results

compute_summary()[source]#
compute_partially_known_recursive(directories_with_known_files: Set[bytes], partially_known_directories: Set[bytes], full_known_directories: Set[bytes], d: Directory)[source]#

Recursively compute partially known directories.

show()[source]#
class swh.scanner.output.TextOutput(root_path: str, nodes_data: MerkleNodeInfo, source_tree: Directory, config: Dict[str, Any], web_client: WebAPIClient)[source]#

Bases: BaseOutput

display an exhaustive result of the scan in text form

note: as soon as the scan target something larger than a toy project, the usability of this mode is poor.

show() None[source]#
print_node(node: Any, isatty: bool, level: int) None[source]#
class swh.scanner.output.SWHIDEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#

Bases: JSONEncoder

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an RecursionError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (’, ‘, ‘: ‘) if indent is None and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

default(value)[source]#

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
class swh.scanner.output.JsonOutput(root_path: str, nodes_data: MerkleNodeInfo, source_tree: Directory, config: Dict[str, Any], web_client: WebAPIClient)[source]#

Bases: BaseOutput

display the scan result in json

data_as_json()[source]#
show()[source]#
class swh.scanner.output.NDJsonTextOutput(root_path: str, nodes_data: MerkleNodeInfo, source_tree: Directory, config: Dict[str, Any], web_client: WebAPIClient)[source]#

Bases: JsonOutput

display the scan result in newline-delimited json

show()[source]#
class swh.scanner.output.InteractiveDashboardOutput(root_path: str, nodes_data: MerkleNodeInfo, source_tree: Directory, config: Dict[str, Any], web_client: WebAPIClient)[source]#

Bases: SummaryOutput

Dashboard to explore the scan results

show() None[source]#