Page MenuHomeSoftware Heritage

model: output result to json file
ClosedPublic

Authored by DanSeraf on Mar 2 2020, 7:17 PM.

Details

Summary

New option to output the result to a json file (T2298)

output sample:
{"swh": "swh:1:dir:a811b93f681a066ba0387c4a8b58d00a8da6ec30", "debian": "swh:1:dir:8778aacb9f66337b9be662ee7ab2904ed84d7519", ".git": {"refs": {"remotes": "swh:1:dir:01fa282bb80be5907505d44b4692d3fa40fad140", "tags": "swh:1:dir:4b825dc642cb6eb9a060e54bf8d69288fbee4904"}, "hooks": {"pre-receive.sample": "swh:1:cnt:a1fd29ec14823d8bc4a8d1a2cfe35451580f5118", "pre-push.sample": "swh:1:cnt:6187dbf4390fc6e28445dd3d988aefb9d1111988", "update.sample": "swh:1:cnt:80ba94135cc378364af9d3cb2450df48e51faf2c", "pre-rebase.sample": "swh:1:cnt:6cbef5c370d8c3486ca85423dd70440c5e0a2aa2", "fsmonitor-watchman.sample": "swh:1:cnt:e673bb3980f3c286291809e05f80873852bc3e9c", "post-update.sample": "swh:1:cnt:ec17ec1939b7c3e86b7cb6c0c4de6b0818a7e75e", "pre-commit.sample": "swh:1:cnt:6a756416384c210ada2631f17862f5c01fffa478", "prepare-commit-msg.sample": "swh:1:cnt:10fa14c5ab0134436e2ae435138bf921eb477c60", "commit-msg.sample": "swh:1:cnt:b58d1184a9d43a39c0d95f32453efc78581877d6", "pre-applypatch.sample": "swh:1:cnt:4142082bcb939bbc17985a69ba748491ac6b62a5", "applypatch-msg.sample": "swh:1:cnt:a5d7b84a673458d14d9aab082183a1968c2c7492"}, "objects": {"info": "swh:1:dir:4b825dc642cb6eb9a060e54bf8d69288fbee4904"}, "info": "swh:1:dir:c88b2a15165058d5921a3ffd7cdffe9fd5c73f48", "branches": "swh:1:dir:4b825dc642cb6eb9a060e54bf8d69288fbee4904", "description": "swh:1:cnt:498b267a8c7812490d6479839c5577eaaec79d62", "HEAD": "swh:1:cnt:cb089cd89a7d7686d284d8761201649346b5aa1c"}, "docs": "swh:1:dir:2bda28ad9dcd1ea9de9cd83f3904adfd77cd6709", "requirements-swh.txt": "swh:1:cnt:24f0a5c4b63981861a7fab9996fb44455cc2ef0c", "README.md": "swh:1:cnt:08b97d8e41d4291f95b32d6c8c3c4300955cec74", "AUTHORS": "swh:1:cnt:c329086f6eacdb10daf84199c6c84f9ef6eca553", "requirements.txt": "swh:1:cnt:151b92672f2d12b3b1eca2a026d388b86f03010c", "MANIFEST.in": "swh:1:cnt:807e2e9fef59a7e0c6acaf501e1b494fc22aa12e", "pytest.ini": "swh:1:cnt:afa4cf37b73825b4dd0283b3a0854deaa937a14b", "mypy.ini": "swh:1:cnt:46f8db86749402a13da4be604b0cdb6df568df2a", "LICENSE": "swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2", "CONTRIBUTORS": "swh:1:cnt:e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", "requirements-test.txt": "swh:1:cnt:e079f8a6038dd2dc8512967540f96ee0de172067", ".gitignore": "swh:1:cnt:f9ef9a58ad258d0aa34c34f8f7b30b6b37ee4624", "Makefile": "swh:1:cnt:524175c2bad0b35b975f79284c2f5a6d5eaf2eb4", "tox.ini": "swh:1:cnt:277c26289c6caa6fcfccc0e98df373f5293c79fa", "setup.py": "swh:1:cnt:31a4f81b1b48a3d95f61ab127612a949fc628d34", "CODE_OF_CONDUCT.md": "swh:1:cnt:0ad22b51e38e1a3dc2792766db295fca2892142f", ".pre-commit-config.yaml": "swh:1:cnt:380c658ff9aee0bcc179eaee0a6080bfaa8f7db8"}

Diff Detail

Repository
rDTSCN Code scanner
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

vlorentz requested changes to this revision.Mar 2 2020, 7:37 PM
vlorentz added a subscriber: vlorentz.
vlorentz added inline comments.
swh/scanner/cli.py
36–37

I think it would be more idiomatic to use -o/--output. (And if you want to want to add more formats later, such as a machine-readable plaintext, you can add a --format option)

swh/scanner/model.py
38

Why this change?

71–78

out of scope. Could you move this to a new diff?

89

Needs a docstring. And another name, as it returns a tree, not a child.

This revision now requires changes to proceed.Mar 2 2020, 7:37 PM
zack requested changes to this revision.Mar 2 2020, 7:37 PM
zack added a subscriber: zack.
zack added inline comments.
swh/scanner/cli.py
36

This is conflating together two aspects that should remain separate: where the output goes and the format of the output. We should keep them separate.

So, for this diff, I suggest that you add an option --format/-f that allows to select the output format, without changing where it goes (stdout). We can later add a new option --output/-o that selects where the output goes, defaulting to - for stdout.

Regarding the supported formats, we already have two: text for the previous output and json for the new format. (Unless you want to consider colored text as a separate format, but in my opinion it is not worth it. Color text it's just a better text version, which we use when we can detect that we are outputing text to a terminal.)

cli: --format option, text and json
model:

  • changed function name from getJsonChild to getJsonTree
  • show function: output based on format

good job !

do not forget to add an appropriate "Closes" line to the commit message, so that T2298 will be closed automatically when you land the commit

This revision is now accepted and ready to land.Mar 3 2020, 2:25 PM
This revision was automatically updated to reflect the committed changes.