HorlogeSkynet / archey4

:computer: Maintained fork of the original Archey (Linux) system tool
https://git.io/archey4
GNU General Public License v3.0
295 stars 37 forks source link

[FEATURE] JSON output format #70

Closed HorlogeSkynet closed 4 years ago

HorlogeSkynet commented 4 years ago
python3 -m archey --json

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 :smile:

How has this been tested ?

Test cases and our machines.

Types of changes :

Checklist :

ingrinder commented 4 years ago

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 python -m unittest or python setup.py -q test. I haven't got a custom configuration file in /etc/archey4 or ~/.config/archey4...

HorlogeSkynet commented 4 years ago

Yes sorry, related to d559edc52d839654989f1b39e6b0d3159bb71497. It's (again) related to how Configuration is mocked across test modules (and the fact that it is actually a Singleton never getting reset)... It should be fixed on your machine now :bow:

HorlogeSkynet commented 4 years ago

'should be well cleaner now. I'll even fix a little blemish in our Output.{append,output} flow when #71 will be merged. Tell me what you think about that !

Bye :wave:

ingrinder commented 4 years ago

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 Entry.value. Anyway, I'll try and get back to you with a more detailed response tomorrow if I get the chance 👍.

HorlogeSkynet commented 4 years ago

Here we are ! Thanks for your huge work on improving the (raw) value/text output integration. I think it would allow more modifiability in the future, currently costing us time though, sorry for that.

Changelog for my previous changes :

Once this has been merged, I'll rebase #71 & #72, leaving you #67 :wink:

Anyway, there are eventually many changes, so a proper review is needed :fearful:

HorlogeSkynet commented 4 years ago

Unfortunately a rebase against new master was a PITA, so I've simply merged it to resolve new conflicts. Due to past PRs merging order, I've had to roll-back chunks of #71 not required anymore according to global rework/cleanup done here.

Anyway, a proper review is more than required, but future looks simpler once this patch will be merged :+1: