Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7437768
D5213.id18736.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
D5213.id18736.diff
View Options
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -1 +1,2 @@
Daniele Serafini
+Kumar Shivendu
\ No newline at end of file
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
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 14, 5:34 AM (12 h, 41 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3227829
Attached To
D5213: swh/scanner : Strip root path from json output
Event Timeline
Log In to Comment