mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
rename List class to _List for documentation purposes
This commit is contained in:
@ -33,7 +33,7 @@ Schema:
|
|||||||
"maximum_height": integer,
|
"maximum_height": integer,
|
||||||
"devices": [
|
"devices": [
|
||||||
{
|
{
|
||||||
"modes": [
|
"resolution_modes": [
|
||||||
{
|
{
|
||||||
"resolution_width": integer,
|
"resolution_width": integer,
|
||||||
"resolution_height": integer,
|
"resolution_height": integer,
|
||||||
@ -82,7 +82,7 @@ Examples:
|
|||||||
"maximum_height": 32767,
|
"maximum_height": 32767,
|
||||||
"devices": [
|
"devices": [
|
||||||
{
|
{
|
||||||
"modes": [
|
"resolution_modes": [
|
||||||
{
|
{
|
||||||
"resolution_width": 1920,
|
"resolution_width": 1920,
|
||||||
"resolution_height": 1080,
|
"resolution_height": 1080,
|
||||||
@ -143,7 +143,7 @@ Examples:
|
|||||||
"maximum_height": 32767,
|
"maximum_height": 32767,
|
||||||
"devices": [
|
"devices": [
|
||||||
{
|
{
|
||||||
"modes": [
|
"resolution_modes": [
|
||||||
{
|
{
|
||||||
"resolution_width": 1920,
|
"resolution_width": 1920,
|
||||||
"resolution_height": 1080,
|
"resolution_height": 1080,
|
||||||
@ -199,7 +199,7 @@ Examples:
|
|||||||
### parse
|
### parse
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict
|
def parse(data: str, raw: bool = False, quiet: bool = False) -> Response
|
||||||
```
|
```
|
||||||
|
|
||||||
Main text parsing function
|
Main text parsing function
|
||||||
@ -219,4 +219,4 @@ Compatibility: linux, darwin, cygwin, aix, freebsd
|
|||||||
|
|
||||||
Source: [`jc/parsers/xrandr.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/xrandr.py)
|
Source: [`jc/parsers/xrandr.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/xrandr.py)
|
||||||
|
|
||||||
Version 1.4 by Kevin Lyter (code (at) lyterk.com)
|
Version 2.0 by Kevin Lyter (code (at) lyterk.com)
|
||||||
|
@ -354,7 +354,7 @@ class LineType(Enum):
|
|||||||
Invalid = 6
|
Invalid = 6
|
||||||
|
|
||||||
|
|
||||||
class Line:
|
class _Line:
|
||||||
"""Provide metadata about line to make handling it more simple across fn boundaries"""
|
"""Provide metadata about line to make handling it more simple across fn boundaries"""
|
||||||
|
|
||||||
def __init__(self, s: str, t: LineType, m: Match):
|
def __init__(self, s: str, t: LineType, m: Match):
|
||||||
@ -363,7 +363,7 @@ class Line:
|
|||||||
self.m = m
|
self.m = m
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def categorize(cls, line: str) -> "Line":
|
def categorize(cls, line: str) -> "_Line":
|
||||||
"""Iterate through line char by char to see what type of line it is. Apply regexes for more distinctness. Save the regexes and return them for later processing."""
|
"""Iterate through line char by char to see what type of line it is. Apply regexes for more distinctness. Save the regexes and return them for later processing."""
|
||||||
i = 0
|
i = 0
|
||||||
tab_count = 0
|
tab_count = 0
|
||||||
@ -410,7 +410,7 @@ class Line:
|
|||||||
raise Exception(f"Line could not be categorized: '{line}'")
|
raise Exception(f"Line could not be categorized: '{line}'")
|
||||||
|
|
||||||
|
|
||||||
def _parse_screen(line: Line) -> Screen:
|
def _parse_screen(line: _Line) -> Screen:
|
||||||
d = line.m.groupdict()
|
d = line.m.groupdict()
|
||||||
|
|
||||||
screen: Screen = {"devices": []} # type: ignore # Will be populated, but not immediately.
|
screen: Screen = {"devices": []} # type: ignore # Will be populated, but not immediately.
|
||||||
@ -420,7 +420,7 @@ def _parse_screen(line: Line) -> Screen:
|
|||||||
return screen
|
return screen
|
||||||
|
|
||||||
|
|
||||||
def _parse_device(line: Line) -> Device:
|
def _parse_device(line: _Line) -> Device:
|
||||||
matches = line.m.groupdict()
|
matches = line.m.groupdict()
|
||||||
|
|
||||||
device: Device = {
|
device: Device = {
|
||||||
@ -450,7 +450,7 @@ def _parse_device(line: Line) -> Device:
|
|||||||
return device
|
return device
|
||||||
|
|
||||||
|
|
||||||
def _parse_resolution_mode(line: Line) -> ResolutionMode:
|
def _parse_resolution_mode(line: _Line) -> ResolutionMode:
|
||||||
frequencies: List[Frequency] = []
|
frequencies: List[Frequency] = []
|
||||||
|
|
||||||
d = line.m.groupdict()
|
d = line.m.groupdict()
|
||||||
@ -483,7 +483,7 @@ def _parse_resolution_mode(line: Line) -> ResolutionMode:
|
|||||||
return mode
|
return mode
|
||||||
|
|
||||||
|
|
||||||
def _parse_props(index: int, line: Line, lines: List[str]) -> Tuple[int, Props]:
|
def _parse_props(index: int, line: _Line, lines: List[str]) -> Tuple[int, Props]:
|
||||||
tmp_props: Dict[str, List[str]] = {}
|
tmp_props: Dict[str, List[str]] = {}
|
||||||
key = ""
|
key = ""
|
||||||
while index <= len(lines):
|
while index <= len(lines):
|
||||||
@ -504,7 +504,7 @@ def _parse_props(index: int, line: Line, lines: List[str]) -> Tuple[int, Props]:
|
|||||||
break
|
break
|
||||||
index += 1
|
index += 1
|
||||||
try:
|
try:
|
||||||
line = Line.categorize(lines[index])
|
line = _Line.categorize(lines[index])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -545,7 +545,7 @@ def parse(data: str, raw: bool = False, quiet: bool = False) -> Response:
|
|||||||
result: Response = {"screens": []}
|
result: Response = {"screens": []}
|
||||||
if jc.utils.has_data(data):
|
if jc.utils.has_data(data):
|
||||||
while index < len(lines):
|
while index < len(lines):
|
||||||
line = Line.categorize(lines[index])
|
line = _Line.categorize(lines[index])
|
||||||
if line.t == LineType.Screen:
|
if line.t == LineType.Screen:
|
||||||
screen = _parse_screen(line)
|
screen = _parse_screen(line)
|
||||||
result["screens"].append(screen)
|
result["screens"].append(screen)
|
||||||
|
2
man/jc.1
2
man/jc.1
@ -1,4 +1,4 @@
|
|||||||
.TH jc 1 2024-02-10 1.25.1 "JSON Convert"
|
.TH jc 1 2024-02-12 1.25.1 "JSON Convert"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
|
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
|
||||||
and strings
|
and strings
|
||||||
|
@ -6,7 +6,7 @@ from typing import Optional
|
|||||||
from jc.parsers.xrandr import (
|
from jc.parsers.xrandr import (
|
||||||
Device,
|
Device,
|
||||||
Edid,
|
Edid,
|
||||||
Line,
|
_Line,
|
||||||
LineType,
|
LineType,
|
||||||
ResolutionMode,
|
ResolutionMode,
|
||||||
Response,
|
Response,
|
||||||
@ -71,16 +71,16 @@ class XrandrTests(unittest.TestCase):
|
|||||||
prop_value = " 00ffffffffffff0006af3d5700000000"
|
prop_value = " 00ffffffffffff0006af3d5700000000"
|
||||||
invalid = ""
|
invalid = ""
|
||||||
|
|
||||||
self.assertEqual(LineType.Device, Line.categorize(base).t)
|
self.assertEqual(LineType.Device, _Line.categorize(base).t)
|
||||||
self.assertEqual(LineType.ResolutionMode, Line.categorize(resolution_mode).t)
|
self.assertEqual(LineType.ResolutionMode, _Line.categorize(resolution_mode).t)
|
||||||
self.assertEqual(LineType.PropKey, Line.categorize(prop_key).t)
|
self.assertEqual(LineType.PropKey, _Line.categorize(prop_key).t)
|
||||||
self.assertEqual(LineType.PropValue, Line.categorize(prop_value).t)
|
self.assertEqual(LineType.PropValue, _Line.categorize(prop_value).t)
|
||||||
with self.assertRaises(Exception):
|
with self.assertRaises(Exception):
|
||||||
Line.categorize(invalid)
|
_Line.categorize(invalid)
|
||||||
|
|
||||||
def test_screens(self):
|
def test_screens(self):
|
||||||
sample = "Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767"
|
sample = "Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767"
|
||||||
line = Line.categorize(sample)
|
line = _Line.categorize(sample)
|
||||||
actual: Optional[Screen] = _parse_screen(line)
|
actual: Optional[Screen] = _parse_screen(line)
|
||||||
self.assertIsNotNone(actual)
|
self.assertIsNotNone(actual)
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ class XrandrTests(unittest.TestCase):
|
|||||||
sample = (
|
sample = (
|
||||||
"Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384"
|
"Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384"
|
||||||
)
|
)
|
||||||
line = Line.categorize(sample)
|
line = _Line.categorize(sample)
|
||||||
actual = _parse_screen(line)
|
actual = _parse_screen(line)
|
||||||
if actual:
|
if actual:
|
||||||
self.assertEqual(320, actual["minimum_width"])
|
self.assertEqual(320, actual["minimum_width"])
|
||||||
@ -110,7 +110,7 @@ class XrandrTests(unittest.TestCase):
|
|||||||
def test_device(self):
|
def test_device(self):
|
||||||
# regex101 sample link for tests/edits https://regex101.com/r/3cHMv3/1
|
# regex101 sample link for tests/edits https://regex101.com/r/3cHMv3/1
|
||||||
sample = "eDP1 connected primary 1920x1080+0+0 left (normal left inverted right x axis y axis) 310mm x 170mm"
|
sample = "eDP1 connected primary 1920x1080+0+0 left (normal left inverted right x axis y axis) 310mm x 170mm"
|
||||||
line = Line.categorize(sample)
|
line = _Line.categorize(sample)
|
||||||
actual: Optional[Device] = _parse_device(line)
|
actual: Optional[Device] = _parse_device(line)
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
@ -143,7 +143,7 @@ class XrandrTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_device_with_reflect(self):
|
def test_device_with_reflect(self):
|
||||||
sample = "VGA-1 connected primary 1920x1080+0+0 left X and Y axis (normal left inverted right x axis y axis) 310mm x 170mm"
|
sample = "VGA-1 connected primary 1920x1080+0+0 left X and Y axis (normal left inverted right x axis y axis) 310mm x 170mm"
|
||||||
line = Line.categorize(sample)
|
line = _Line.categorize(sample)
|
||||||
actual: Optional[Device] = _parse_device(line)
|
actual: Optional[Device] = _parse_device(line)
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
@ -177,7 +177,7 @@ class XrandrTests(unittest.TestCase):
|
|||||||
"resolution_height": 1080,
|
"resolution_height": 1080,
|
||||||
"is_high_resolution": False,
|
"is_high_resolution": False,
|
||||||
}
|
}
|
||||||
line = Line.categorize(sample_1)
|
line = _Line.categorize(sample_1)
|
||||||
actual: Optional[ResolutionMode] = _parse_resolution_mode(line)
|
actual: Optional[ResolutionMode] = _parse_resolution_mode(line)
|
||||||
|
|
||||||
self.assertIsNotNone(actual)
|
self.assertIsNotNone(actual)
|
||||||
@ -187,7 +187,7 @@ class XrandrTests(unittest.TestCase):
|
|||||||
self.assertEqual(v, actual[k], f"mode regex failed on {k}")
|
self.assertEqual(v, actual[k], f"mode regex failed on {k}")
|
||||||
|
|
||||||
sample_2 = " 1920x1080i 60.00 50.00 59.94"
|
sample_2 = " 1920x1080i 60.00 50.00 59.94"
|
||||||
line = Line.categorize(sample_2)
|
line = _Line.categorize(sample_2)
|
||||||
actual: Optional[ResolutionMode] = _parse_resolution_mode(line)
|
actual: Optional[ResolutionMode] = _parse_resolution_mode(line)
|
||||||
self.assertIsNotNone(actual)
|
self.assertIsNotNone(actual)
|
||||||
if actual:
|
if actual:
|
||||||
|
Reference in New Issue
Block a user