Page MenuHomeSoftware Heritage

D2855.id10174.diff
No OneTemporary

D2855.id10174.diff

diff --git a/swh/scanner/model.py b/swh/scanner/model.py
--- a/swh/scanner/model.py
+++ b/swh/scanner/model.py
@@ -5,6 +5,7 @@
from __future__ import annotations
import sys
+import json
from pathlib import PosixPath
from typing import Any, Dict
from enum import Enum
@@ -54,7 +55,7 @@
def show(self, format) -> None:
"""Print all the tree"""
if format == 'json':
- print(self.getJsonTree())
+ print(json.dumps(self.getTree(), indent=4, sort_keys=True))
elif format == 'text':
isatty = sys.stdout.isatty()
@@ -83,7 +84,7 @@
print(f'{begin}{rel_path}{end}')
- def getJsonTree(self):
+ def getTree(self):
"""Walk through the tree to discover content or directory that have
a persistent identifier. If a persistent identifier is found it saves
the path with the relative PID.
@@ -98,7 +99,7 @@
if child_node.pid:
child_tree[rel_path] = child_node.pid
else:
- next_tree = child_node.getJsonTree()
+ next_tree = child_node.getTree()
if next_tree:
child_tree[rel_path] = next_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
@@ -36,7 +36,7 @@
for path, pid in temp_folder['paths'].items():
example_tree.addNode(path)
- json_tree = example_tree.getJsonTree()
+ json_tree = example_tree.getTree()
assert len(json_tree) == 0
@@ -45,7 +45,7 @@
for path, pid in temp_folder['paths'].items():
example_tree.addNode(path, pid)
- tree_dict = example_tree.getJsonTree()
+ tree_dict = example_tree.getTree()
assert len(tree_dict) == 3
# since subdir have a pid, it can't have a children path
@@ -61,7 +61,7 @@
else:
example_tree.addNode(path)
- tree_dict = example_tree.getJsonTree()
+ tree_dict = example_tree.getTree()
assert len(tree_dict) == 1
assert tree_dict['subdir0']['filesample.txt']
diff --git a/swh/scanner/tests/test_scanner.py b/swh/scanner/tests/test_scanner.py
--- a/swh/scanner/tests/test_scanner.py
+++ b/swh/scanner/tests/test_scanner.py
@@ -74,6 +74,6 @@
event_loop.run_until_complete(
run(sample_folder, api_url, source_tree))
- actual_result = source_tree.getJsonTree()
+ actual_result = source_tree.getTree()
assert actual_result == expected_result

File Metadata

Mime Type
text/plain
Expires
Jul 27 2024, 9:23 PM (11 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3223154

Event Timeline