Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/model.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from __future__ import annotations | from __future__ import annotations | ||||
import sys | import sys | ||||
import json | import json | ||||
from pathlib import PosixPath | from pathlib import PosixPath | ||||
from typing import Any, Dict, Tuple, Iterable | from typing import Any, Dict, Tuple, Iterable | ||||
from enum import Enum | from enum import Enum | ||||
vlorentz: Why `type: ignore`? If mypy is complaining about a missing stub file, you should edit `mypy.ini` | |||||
import ndjson | |||||
from .plot import sunburst | from .plot import sunburst | ||||
from .exceptions import InvalidObjectType | from .exceptions import InvalidObjectType | ||||
from swh.model.identifiers import DIRECTORY, CONTENT | from swh.model.identifiers import DIRECTORY, CONTENT | ||||
class Color(Enum): | class Color(Enum): | ||||
blue = "\033[94m" | blue = "\033[94m" | ||||
green = "\033[92m" | green = "\033[92m" | ||||
red = "\033[91m" | red = "\033[91m" | ||||
end = "\033[0m" | end = "\033[0m" | ||||
Show All 31 Lines | def addNode(self, path: PosixPath, swhid: str, known: bool) -> None: | ||||
self.children[new_path].addNode(path, swhid, known) | self.children[new_path].addNode(path, swhid, known) | ||||
def show(self, format) -> None: | def show(self, format) -> None: | ||||
"""Show tree in different formats""" | """Show tree in different formats""" | ||||
if format == "json": | if format == "json": | ||||
print(json.dumps(self.toDict(), indent=4, sort_keys=True)) | print(json.dumps(self.toDict(), indent=4, sort_keys=True)) | ||||
if format == "ndjson": | |||||
print(ndjson.dumps(dict_path for dict_path in self.iterate())) | |||||
elif format == "text": | elif format == "text": | ||||
isatty = sys.stdout.isatty() | isatty = sys.stdout.isatty() | ||||
print(colorize(str(self.path), Color.blue) if isatty else str(self.path)) | print(colorize(str(self.path), Color.blue) if isatty else str(self.path)) | ||||
self.printChildren(isatty) | self.printChildren(isatty) | ||||
elif format == "sunburst": | elif format == "sunburst": | ||||
root = self.path | root = self.path | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |
Why type: ignore? If mypy is complaining about a missing stub file, you should edit mypy.ini