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 | ||||
import ndjson | import ndjson | ||||
from .plot import sunburst | from .plot import generate_sunburst, offline_plot | ||||
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" | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def show(self, format) -> None: | ||||
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 | ||||
directories = self.getDirectoriesInfo(root) | directories = self.getDirectoriesInfo(root) | ||||
sunburst(directories, root) | sunburst = generate_sunburst(directories, root) | ||||
offline_plot(sunburst) | |||||
def printChildren(self, isatty: bool, inc: int = 1) -> None: | def printChildren(self, isatty: bool, inc: int = 1) -> None: | ||||
for path, node in self.children.items(): | for path, node in self.children.items(): | ||||
self.printNode(node, isatty, inc) | self.printNode(node, isatty, inc) | ||||
if node.children: | if node.children: | ||||
node.printChildren(isatty, inc + 1) | node.printChildren(isatty, inc + 1) | ||||
def printNode(self, node: Any, isatty: bool, inc: int) -> None: | def printNode(self, node: Any, isatty: bool, inc: int) -> None: | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |