swh.scanner.model module

class swh.scanner.model.Color(value)[source]

Bases: enum.Enum

An enumeration.

blue = '\x1b[94m'
green = '\x1b[92m'
red = '\x1b[91m'
end = '\x1b[0m'
swh.scanner.model.colorize(text: str, color: swh.scanner.model.Color)[source]
class swh.scanner.model.Tree(path: pathlib.Path, father: Optional[swh.scanner.model.Tree] = None)[source]

Bases: object

Representation of a file system structure

add_node(path: pathlib.Path, swhid: str, known: bool) → None[source]

Recursively add a new path.

show(fmt) → None[source]

Show tree in different formats

print_children(isatty: bool, inc: int = 1) → None[source]
print_node(node: Any, isatty: bool, inc: int) → None[source]
property attributes

Get the attributes of the current node grouped by the relative path.

Returns

a dictionary containing a path as key and its known/unknown status and the SWHID as values.

to_dict() → Dict[str, Dict[str, Any]][source]

Recursively flatten the current tree nodes into a dictionary.

For example, if you have the following structure:


root {
subdir: {

file.txt

}

}

The generated dictionary will be:


{
“root”: {

“swhid”: “…”, “known”: True/False

} “root/subdir”: {

“swhid”: “…”, “known”: True/False

} “root/subdir/file.txt”: {

“swhid”: “…”, “known”: True/False

}

}

iterate() → Iterator[swh.scanner.model.Tree][source]

Recursively iterate through the children of the current node

get_files_from_dir(dir_path: pathlib.Path) → List[source]

Retrieve files information about a specific directory path

Returns

A list containing the files attributes present inside the directory given in input

get_directories_info(root: pathlib.Path) → Dict[pathlib.Path, Tuple[int, int]][source]

Get information about all directories under the given root.

Returns

A dictionary with a directory path as key and the relative contents information (the result of count_contents) as values.

count_contents() → Tuple[int, int][source]
Count how many contents are present inside a directory.

If a directory has a SWHID returns as it has all the contents.

Returns

A tuple with the total number of the contents and the number of contents known (the ones that have a persistent identifier).

has_dirs() → bool[source]

Checks if node has directories