diff --git a/CHANGELOG b/CHANGELOG index 4f4d0bfa..0971ea22 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ jc changelog +20210316 v1.15.0 +- Add acpi parser tested on linux +- Add upower parser tested on linux + 20210305 v1.14.4 - Packaging fix only for binaries and RPMs hosted on https://github.com/kellyjonbrazil/jc-packaging. Packages from PyPi and OS repositories are not affected. This fixes an issue that kept the YAML diff --git a/EXAMPLES.md b/EXAMPLES.md index cc3ed2e8..aa07a83f 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -1,4 +1,62 @@ ## JC Examples +### acpi +```bash +acpi -V | jc --acpi -p # or: jc -p acpi -V +``` +```json +[ + { + "type": "Battery", + "id": 0, + "state": "Charging", + "charge_percent": 71, + "until_charged": "00:29:20", + "design_capacity_mah": 2110, + "last_full_capacity": 2271, + "last_full_capacity_percent": 100 + }, + { + "type": "Adapter", + "id": 0, + "on-line": true + }, + { + "type": "Thermal", + "id": 0, + "mode": "ok", + "temperature": 46.0, + "temperature_unit": "C", + "trip_points": [ + { + "id": 0, + "switches_to_mode": "critical", + "temperature": 127.0, + "temperature_unit": "C" + }, + { + "id": 1, + "switches_to_mode": "hot", + "temperature": 127.0, + "temperature_unit": "C" + } + ] + }, + { + "type": "Cooling", + "id": 0, + "messages": [ + "Processor 0 of 10" + ] + }, + { + "type": "Cooling", + "id": 1, + "messages": [ + "Processor 0 of 10" + ] + } +] +``` ### airport -I ```bash airport -I | jc --airport -p # or: jc -p airport -I diff --git a/docgen.sh b/docgen.sh index 9a802c61..a292144b 100755 --- a/docgen.sh +++ b/docgen.sh @@ -5,6 +5,7 @@ cd jc pydocmd simple jc+ > ../docs/readme.md pydocmd simple utils+ > ../docs/utils.md +pydocmd simple jc.parsers.acpi+ > ../docs/parsers/acpi.md pydocmd simple jc.parsers.airport+ > ../docs/parsers/airport.md pydocmd simple jc.parsers.airport_s+ > ../docs/parsers/airport_s.md pydocmd simple jc.parsers.arp+ > ../docs/parsers/arp.md diff --git a/docs/parsers/acpi.md b/docs/parsers/acpi.md new file mode 100644 index 00000000..fbc42d6e --- /dev/null +++ b/docs/parsers/acpi.md @@ -0,0 +1,256 @@ + +# jc.parsers.acpi +jc - JSON CLI output utility `acpi` command output parser + +Usage (cli): + + $ acpi -V | jc --acpi + + or + + $ jc acpi -V + +Usage (module): + + import jc.parsers.acpi + result = jc.parsers.acpi.parse(acpi_command_output) + +Compatibility: + + 'linux' + +Examples: + + $ acpi -V | jc --acpi -p + [ + { + "type": "Battery", + "id": 0, + "state": "Charging", + "charge_percent": 71, + "until_charged": "00:29:20", + "design_capacity_mah": 2110, + "last_full_capacity": 2271, + "last_full_capacity_percent": 100 + }, + { + "type": "Adapter", + "id": 0, + "on-line": true + }, + { + "type": "Thermal", + "id": 0, + "mode": "ok", + "temperature": 46.0, + "temperature_unit": "C", + "trip_points": [ + { + "id": 0, + "switches_to_mode": "critical", + "temperature": 127.0, + "temperature_unit": "C" + }, + { + "id": 1, + "switches_to_mode": "hot", + "temperature": 127.0, + "temperature_unit": "C" + } + ] + }, + { + "type": "Cooling", + "id": 0, + "messages": [ + "Processor 0 of 10" + ] + }, + { + "type": "Cooling", + "id": 1, + "messages": [ + "Processor 0 of 10" + ] + }, + { + "type": "Cooling", + "id": 2, + "messages": [ + "x86_pkg_temp no state information available" + ] + }, + { + "type": "Cooling", + "id": 3, + "messages": [ + "Processor 0 of 10" + ] + }, + { + "type": "Cooling", + "id": 4, + "messages": [ + "intel_powerclamp no state information available" + ] + }, + { + "type": "Cooling", + "id": 5, + "messages": [ + "Processor 0 of 10" + ] + } + ] + + $ acpi -V | jc --acpi -p -r + [ + { + "type": "Battery", + "id": "0", + "state": "Charging", + "charge_percent": "71", + "until_charged": "00:29:20", + "design_capacity_mah": "2110", + "last_full_capacity": "2271", + "last_full_capacity_percent": "100" + }, + { + "type": "Adapter", + "id": "0", + "on-line": true + }, + { + "type": "Thermal", + "id": "0", + "mode": "ok", + "temperature": "46.0", + "temperature_unit": "C", + "trip_points": [ + { + "id": "0", + "switches_to_mode": "critical", + "temperature": "127.0", + "temperature_unit": "C" + }, + { + "id": "1", + "switches_to_mode": "hot", + "temperature": "127.0", + "temperature_unit": "C" + } + ] + }, + { + "type": "Cooling", + "id": "0", + "messages": [ + "Processor 0 of 10" + ] + }, + { + "type": "Cooling", + "id": "1", + "messages": [ + "Processor 0 of 10" + ] + }, + { + "type": "Cooling", + "id": "2", + "messages": [ + "x86_pkg_temp no state information available" + ] + }, + { + "type": "Cooling", + "id": "3", + "messages": [ + "Processor 0 of 10" + ] + }, + { + "type": "Cooling", + "id": "4", + "messages": [ + "intel_powerclamp no state information available" + ] + }, + { + "type": "Cooling", + "id": "5", + "messages": [ + "Processor 0 of 10" + ] + } + ] + + +## info +```python +info() +``` + + +## process +```python +process(proc_data) +``` + +Final processing to conform to the schema. + +Parameters: + + proc_data: (List of Dictionaries) raw structured data to process + +Returns: + + List of Dictionaries. Structured data with the following schema: + + [ + { + "type": string, + "id": integer, + "state": string, + "charge_percent": integer, + "until_charged": string, + "charge_remaining" string, + "design_capacity_mah": integer, + "last_full_capacity": integer, + "last_full_capacity_percent": integer, + "on-line": boolean, + "mode": string, + "temperature": float, + "temperature_unit": string, + "trip_points": [ + { + "id": integer, + "switches_to_mode": string, + "temperature": float, + "temperature_unit": string + } + ], + "messages": [ + string + ] + } + ] + + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main text parsing function + +Parameters: + + data: (string) text data to parse + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + +Returns: + + List of Dictionaries. Raw or processed structured data. + diff --git a/jc/cli.py b/jc/cli.py index 8874bffc..29e16e53 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -21,7 +21,7 @@ import jc.appdirs as appdirs class info(): - version = '1.14.5' + version = '1.15.0' description = 'JSON CLI output utility' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' diff --git a/setup.py b/setup.py index aad9f2a9..7ab3b3c4 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r') as f: setuptools.setup( name='jc', - version='1.14.4', + version='1.15.0', author='Kelly Brazil', author_email='kellyjonbrazil@gmail.com', description='Converts the output of popular command-line tools and file-types to JSON.',