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

doc updates

This commit is contained in:
Kelly Brazil
2022-02-14 09:14:46 -08:00
parent ca914ec77d
commit 4723db8e3c
8 changed files with 195 additions and 77 deletions

View File

@ -236,6 +236,7 @@ option.
- `--wc` enables the `wc` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/wc)) - `--wc` enables the `wc` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/wc))
- `--who` enables the `who` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/who)) - `--who` enables the `who` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/who))
- `--xml` enables the XML file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/xml)) - `--xml` enables the XML file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/xml))
- `--xrandr` enables the `xrandr` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/xrandr))
- `--yaml` enables the YAML file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/yaml)) - `--yaml` enables the YAML file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/yaml))
- `--zipinfo` enables the `zipinfo` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/zipinfo)) - `--zipinfo` enables the `zipinfo` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/zipinfo))

View File

@ -68,7 +68,7 @@ Schema:
"group_different": bool/null, "group_different": bool/null,
"acl_different": bool/null, "acl_different": bool/null,
"extended_attribute_different": bool/null, "extended_attribute_different": bool/null,
"epoch": int, [2] "epoch": integer, [2]
} }
] ]
} }

View File

@ -68,7 +68,7 @@ Schema:
"group_different": bool/null, "group_different": bool/null,
"acl_different": bool/null, "acl_different": bool/null,
"extended_attribute_different": bool/null, "extended_attribute_different": bool/null,
"epoch": int, [2] "epoch": integer, [2]
# Below object only exists if using -qq or ignore_exceptions=True # Below object only exists if using -qq or ignore_exceptions=True

109
docs/parsers/xrandr.md Normal file
View File

@ -0,0 +1,109 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.xrandr"></a>
# jc.parsers.xrandr
jc - JSON CLI output utility `xrandr` command output parser
Usage (cli):
$ xrandr | jc --xrandr
or
$ jc xrandr
Usage (module):
import jc
result = jc.parse('xrandr', xrandr_command_output)
or
import jc.parsers.xrandr
result = jc.parsers.xrandr.parse(xrandr_command_output)
Schema:
{
"screens": [
{
"screen_number": integer,
"minimum_width": integer,
"minimum_height": integer,
"current_width": integer,
"current_height": integer,
"maximum_width": integer,
"maximum_height": integer,
"associated_device": {
"associated_modes": [
{
"resolution_width": integer,
"resolution_height": integer,
"is_high_resolution": boolean,
"frequencies": [
{
"frequency": float,
"is_current": boolean,
"is_preferred": boolean
}
],
"is_connected": boolean,
"is_primary": boolean,
"device_name": string,
"resolution_width": integer,
"resolution_height": integer,
"offset_width": integer,
"offset_height": integer,
"dimension_width": integer,
"dimension_height": integer
}
}
],
"unassociated_devices": [
{
"associated_modes": [
{
"resolution_width": integer,
"resolution_height": integer,
"is_high_resolution": boolean,
"frequencies": [
{
"frequency": float,
"is_current": boolean,
"is_preferred": boolean
}
]
}
]
}
]
}
Examples:
$ xrandr | jc --xrandr
<a id="jc.parsers.xrandr.parse"></a>
### parse
```python
def parse(data: str, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.0 by Kevin Lyter (lyter_git at sent.com)

View File

@ -63,7 +63,7 @@ Schema:
"group_different": bool/null, "group_different": bool/null,
"acl_different": bool/null, "acl_different": bool/null,
"extended_attribute_different": bool/null, "extended_attribute_different": bool/null,
"epoch": int, [2] "epoch": integer, [2]
} }
] ]
} }

View File

@ -63,7 +63,7 @@ Schema:
"group_different": bool/null, "group_different": bool/null,
"acl_different": bool/null, "acl_different": bool/null,
"extended_attribute_different": bool/null, "extended_attribute_different": bool/null,
"epoch": int, [2] "epoch": integer, [2]
# Below object only exists if using -qq or ignore_exceptions=True # Below object only exists if using -qq or ignore_exceptions=True

View File

@ -1,74 +1,79 @@
"""jc - JSON CLI output utility `xrandr` command output parser """jc - JSON CLI output utility `xrandr` command output parser
Options supported: Usage (cli):
$ xrandr | jc --xrandr
or
$ jc xrandr
Usage (module): Usage (module):
import jc
result = jc.parse('xrandr', xrandr_command_output)
or
import jc.parsers.xrandr import jc.parsers.xrandr
result = jc.parsers.xrandr.parse(xrandr_command_output) result = jc.parsers.xrandr.parse(xrandr_command_output)
Schema: Schema:
{ {
"screens": [ "screens": [
{ {
"screen_number": 0, "screen_number": integer,
"minimum_width": 8, "minimum_width": integer,
"minimum_height": 8, "minimum_height": integer,
"current_width": 1920, "current_width": integer,
"current_height": 1080, "current_height": integer,
"maximum_width": 32767, "maximum_width": integer,
"maximum_height": 32767, "maximum_height": integer,
"associated_device": { "associated_device": {
"associated_modes": [ "associated_modes": [
{ {
"resolution_width": 1920, "resolution_width": integer,
"resolution_height": 1080, "resolution_height": integer,
"is_high_resolution": false, "is_high_resolution": boolean,
"frequencies": [ "frequencies": [
{ {
"frequency": 60.03, "frequency": float,
"is_current": true, "is_current": boolean,
"is_preferred": true "is_preferred": boolean
}, }
{
"frequency": 59.93,
"is_current": false,
"is_preferred": false
}
]
},
{
"resolution_width": 1680,
"resolution_height": 1050,
"is_high_resolution": false,
"frequencies": [
{
"frequency": 59.88,
"is_current": false,
"is_preferred": false
}
]
}
], ],
"is_connected": true, "is_connected": boolean,
"is_primary": true, "is_primary": boolean,
"device_name": "eDP1", "device_name": string,
"resolution_width": 1920, "resolution_width": integer,
"resolution_height": 1080, "resolution_height": integer,
"offset_width": 0, "offset_width": integer,
"offset_height": 0, "offset_height": integer,
"dimension_width": 310, "dimension_width": integer,
"dimension_height": 170 "dimension_height": integer
} }
} }
], ],
"unassociated_devices": [] "unassociated_devices": [
} {
Translated from: "associated_modes": [
Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767 {
eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 310mm x 170mm "resolution_width": integer,
1920x1080 60.03*+ 59.93 "resolution_height": integer,
1680x1050 59.88 "is_high_resolution": boolean,
"frequencies": [
{
"frequency": float,
"is_current": boolean,
"is_preferred": boolean
}
]
}
]
}
]
}
Examples: Examples:
$ xrandr | jc --xrandr $ xrandr | jc --xrandr
@ -82,7 +87,7 @@ import jc.utils
class info: class info:
"""Provides parser metadata (version, author, etc.)""" """Provides parser metadata (version, author, etc.)"""
version = "1.9" version = "1.0"
description = "`xrandr` command parser" description = "`xrandr` command parser"
author = "Kevin Lyter" author = "Kevin Lyter"
author_email = "lyter_git at sent.com" author_email = "lyter_git at sent.com"
@ -199,7 +204,7 @@ _device_pattern = (
) )
def _parse_device(next_lines: List[str]) -> Optional[Device]: def _parse_device(next_lines: List[str], quiet: bool = False) -> Optional[Device]:
if not next_lines: if not next_lines:
return None return None
@ -223,8 +228,10 @@ def _parse_device(next_lines: List[str]) -> Optional[Device]:
try: try:
if v: if v:
device[k] = int(v) device[k] = int(v)
except ValueError: except ValueError and not quiet:
print(f"Error: {next_line} : {k} - {v} is not int-able") jc.utils.warning_message(
[f"Error: {next_line} : {k} - {v} is not int-able"]
)
while next_lines: while next_lines:
next_line = next_lines.pop() next_line = next_lines.pop()
@ -286,35 +293,31 @@ def parse(data: str, raw=False, quiet=False):
Parameters: Parameters:
data: (string) text data to parse data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True quiet: (boolean) suppress warning messages if True
Returns: Returns:
List of Dictionaries. Raw or processed structured data. List of Dictionaries. Raw or processed structured data.
""" """
if not quiet: jc.utils.compatibility(__name__, info.compatible, quiet)
jc.utils.compatibility(__name__, info.compatible) jc.utils.input_type_check(data)
warned = False
parent = ""
next_is_parent = False
new_section = False
linedata = data.splitlines() linedata = data.splitlines()
linedata.reverse() # For popping linedata.reverse() # For popping
result: Response = {"screens": [], "unassociated_devices": []} result: Response = {"screens": [], "unassociated_devices": []}
if jc.utils.has_data(data): if jc.utils.has_data(data):
result: Response = {"screens": [], "unassociated_devices": []}
while linedata: while linedata:
screen = _parse_screen(linedata) screen = _parse_screen(linedata)
if screen: if screen:
result["screens"].append(screen) result["screens"].append(screen)
else: else:
device = _parse_device(linedata) device = _parse_device(linedata, quiet)
if device: if device:
result["unassociated_devices"].append(device) result["unassociated_devices"].append(device)
if not result["unassociated_devices"] and not result["screens"]: if not result["unassociated_devices"] and not result["screens"]:
return {} return {}
return result return result

View File

@ -1,4 +1,4 @@
.TH jc 1 2022-02-08 1.18.3 "JSON CLI output utility" .TH jc 1 2022-02-14 1.18.3 "JSON CLI output utility"
.SH NAME .SH NAME
jc \- JSONifies the output of many CLI tools and file-types jc \- JSONifies the output of many CLI tools and file-types
.SH SYNOPSIS .SH SYNOPSIS
@ -442,6 +442,11 @@ Key/Value file parser
\fB--xml\fP \fB--xml\fP
XML file parser XML file parser
.TP
.B
\fB--xrandr\fP
`xrandr` command parser
.TP .TP
.B .B
\fB--yaml\fP \fB--yaml\fP