diff --git a/CONTRIBUTORS b/CONTRIBUTORS --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1 +1,2 @@ Daniele Serafini +Kumar Shivendu diff --git a/swh/scanner/model.py b/swh/scanner/model.py --- a/swh/scanner/model.py +++ b/swh/scanner/model.py @@ -64,12 +64,18 @@ print(json.dumps(self.to_dict(), indent=4, sort_keys=True)) if fmt == "ndjson": - print(ndjson.dumps(node.attributes for node in self.iterate())) + print( + ndjson.dumps( + {str(Path(k).relative_to(self.path)): v} + for node in self.iterate() + for k, v in node.attributes.items() + ) + ) elif fmt == "text": isatty = sys.stdout.isatty() - - print(colorize(str(self.path), Color.blue) if isatty else str(self.path)) + root_dir = self.path.relative_to(self.path.parent) + print(colorize(str(root_dir), Color.blue) if isatty else str(root_dir)) self.print_children(isatty) elif fmt == "sunburst": @@ -146,7 +152,11 @@ """ - return {k: v for node in self.iterate() for k, v in node.attributes.items()} + return { + str(Path(k).relative_to(self.path)): v + for node in self.iterate() + for k, v in node.attributes.items() + } def iterate(self) -> Iterator[Tree]: """ diff --git a/swh/scanner/tests/test_model.py b/swh/scanner/tests/test_model.py --- a/swh/scanner/tests/test_model.py +++ b/swh/scanner/tests/test_model.py @@ -46,7 +46,6 @@ def test_get_json_tree_only_one_present(example_tree, temp_folder): - root = temp_folder["root"] filesample_path = temp_folder["filesample"] for path, swhid in temp_folder["paths"].items(): @@ -57,7 +56,7 @@ assert len(result) == 6 for path, node_attr in result.items(): - if path == str(root) + "/subdir/filesample.txt": + if path == "subdir/filesample.txt": assert node_attr["known"] is True else: assert node_attr["known"] is False