-
-
Notifications
You must be signed in to change notification settings - Fork 38
[FEATURE] JSON output format #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Huh, it's funny the CI build passed, since I'm consistently getting a unit test error on this branch: ======================================================================
ERROR: test_json_output_format (archey.test.test_archey_output.TestOutputUtil)
Test how the `output` method handles JSON preferred formatting of entries
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.8/unittest/mock.py", line 1348, in patched
return func(*newargs, **newkeywargs)
File "/home/michael/git/archey4/archey/test/test_archey_output.py", line 504, in test_json_output_format
output = Output(format_to_json=True)
File "/home/michael/git/archey4/archey/output.py", line 59, in __init__
if ansi_color and Configuration().get('colors_palette')['honor_ansi_color']:
KeyError: 'honor_ansi_color'
----------------------------------------------------------------------
Ran 108 tests in 0.075s
FAILED (errors=1) ...whether I use |
Yes sorry, related to |
'should be well cleaner now. Bye 👋 |
> Rationale : This should be compatible against Python < 3.6
> Rationale: When #71 will be merged, issues due to keys duplication may occur. > This patch sets output values as a list anyway, sparing us an API breakage in the future. > Note: A `Colors.remove_colors` utility method has been added for DRY purposes.
+ Sets results output in a `data` dictionary of the parent document + Adds a new `meta` dictionary containing date of generation and Archey version > Rationale: To keep `Output` concise, API-related code has been moved to a new `API` module. > Rationale 2: Adding a timestamp would allow developers to perform computations based on collection date. > Adding a version identifier would allow **us** to make the API evolve in the future.
57e60dd
to
32cdee5
Compare
Adds proper JSON formatting to the following entries when using the `-j` option: * Disk * LanIp * RAM * Temperature * Terminal * Uptime * WanIp Additionally adds a new attribute `_format_to_json` to the `Entry` base class.
Rationale: Having the raw data in a consistent place makes it far easier to implement an API with our entries. * Removed `_format_to_json` attribute introduced in e709d0e. * Modified all entries to place a generic object (list, string, dict) into the `value` attribute which suits the data best. * Moved pretty-formatting logic to an overriden `output` method. * Tweaked API implementation to use individual entries rather than their outputs (we now deal with the `value` attribute in the API which should contain all of an entry's data, even if it outputs multiple lines). * Modified tests as appropriate :)
Sorry for the delays, I've been a little busy 😃. I made a few more modifications since I wasn't fully satisfied after I started work on e709d0e until seeing 32cdee5 inspired me to change how we treat |
Accidentally removed in 2188def. Sidenote: We should probably add a test for `output` on entries now.
... and fixes minor code formats
... and fixes other minor code formats
Here we are ! Thanks for your huge work on improving the (raw) value/text output integration. Changelog for my previous changes :
Once this has been merged, I'll rebase #71 & #72, leaving you #67 😉 Anyway, there are eventually many changes, so a proper review is needed 😨 |
Unfortunately a rebase against new Anyway, a proper review is more than required, but future looks simpler once this patch will be merged 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the patches on top of the changes I made earlier! This is looking nice now 😃. I've left a few comments for stuff I'm not so sure about or could do with changing - I'll hopefully submit commits for some of them if I get the chance. 👍
> `archey -j` --> Compact JSON output > `archey -jj` --> 2-tab indented output > `archey -jj --json` --> 4-tab indented output > `archey -jjjj --> ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, liking the custom assertions implementation 👍. This LGTM!
Edit: I'll refrain from merging anything and let you have the final go-ahead since last time I assumed we were going to merge the other way around 😄.
Description
Simple JSON-formatting of entries data.It's a first basic support, maybe it could be enhanced in the future.
EDIT 2020-05-13 : To keep things clean, DRY and concerns-separated, @ingrinder and myself started to work on a slight rework to make entries' values independent from their corresponding (regular and original) text output.
This will drastically simplify future work on entries data.
Reason and / or context
It would allow one to use Archey as an API or so 😄
How has this been tested ?
Test cases and our machines.
Types of changes :
Checklist :