Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7124809
D2855.id10176.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D2855.id10176.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Dec 21 2024, 8:12 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3223154
Attached To
D2855: scanner: dump json instead of dict
Event Timeline
Log In to Comment