1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-17 01:32:37 +02:00

add human readable output support to the free parser

This commit is contained in:
Kelly Brazil
2024-02-26 10:42:26 -08:00
parent ef2a2121b5
commit bce4eb536a
5 changed files with 26 additions and 25 deletions

View File

@ -1,7 +1,7 @@
jc changelog
20240214 v1.25.2
- TODO: add human output support to the `free` parser
20240226 v1.25.2
- Enhance `free` parser to add human readable output support
- Enhance `df` parser to include `_bytes` fields for `size`, `used`, and `available`.
This provides normalized output when human readable `df` output is used
- Fix `iwconfig` parser to handle more special characters in the SSID name

View File

@ -5,6 +5,8 @@
jc - JSON Convert `free` command output parser
Values are normalized to bytes when using `free -h`.
Usage (cli):
$ free | jc --free
@ -97,4 +99,4 @@ Compatibility: linux
Source: [`jc/parsers/free.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/free.py)
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@ -1,5 +1,7 @@
"""jc - JSON Convert `free` command output parser
Values are normalized to bytes when using `free -h`.
Usage (cli):
$ free | jc --free
@ -73,7 +75,7 @@ import jc.parsers.universal
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.7'
version = '1.8'
description = '`free` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -102,7 +104,7 @@ def _process(proc_data):
for entry in proc_data:
for key in entry:
if key in int_list:
entry[key] = jc.utils.convert_to_int(entry[key])
entry[key] = jc.utils.convert_size_to_int(entry[key])
return proc_data
@ -138,7 +140,4 @@ def parse(data, raw=False, quiet=False):
for entry in raw_output:
entry['type'] = entry['type'].rstrip(':')
if raw:
return raw_output
else:
return _process(raw_output)
return raw_output if raw else _process(raw_output)

View File

@ -1 +1 @@
[{"type":"Mem","total":3,"used":217,"free":3,"shared":11,"buff_cache":267,"available":3},{"type":"Swap","total":2,"used":0,"free":2}]
[{"type":"Mem","total":3700000000,"used":217000000,"free":3200000000,"shared":11000000,"buff_cache":267000000,"available":3200000000},{"type":"Swap","total":2000000000,"used":0,"free":2000000000}]

View File

@ -1 +1 @@
[{"type":"Mem","total":1,"used":237,"free":466,"shared":1,"buff_cache":1,"available":1},{"type":"Swap","total":2,"used":268,"free":2}]
[{"type":"Mem","total":1900000000,"used":237000000,"free":466000000,"shared":1200000,"buff_cache":1200000000,"available":1500000000},{"type":"Swap","total":2000000000,"used":268000,"free":2000000000}]