mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-06 22:32:54 +02:00
update schema. fix no-data output to match other parsers.
This commit is contained in:
@ -211,4 +211,4 @@ Returns:
|
|||||||
### Parser Information
|
### Parser Information
|
||||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||||
|
|
||||||
Version 1.3 by Kevin Lyter (code (at) lyterk.com)
|
Version 1.4 by Kevin Lyter (code (at) lyterk.com)
|
||||||
|
@ -26,22 +26,24 @@ Schema:
|
|||||||
"current_height": integer,
|
"current_height": integer,
|
||||||
"maximum_width": integer,
|
"maximum_width": integer,
|
||||||
"maximum_height": integer,
|
"maximum_height": integer,
|
||||||
"devices": {
|
"devices": [
|
||||||
"modes": [
|
{
|
||||||
{
|
"modes": [
|
||||||
"resolution_width": integer,
|
{
|
||||||
"resolution_height": integer,
|
"resolution_width": integer,
|
||||||
"is_high_resolution": boolean,
|
"resolution_height": integer,
|
||||||
"frequencies": [
|
"is_high_resolution": boolean,
|
||||||
{
|
"frequencies": [
|
||||||
"frequency": float,
|
{
|
||||||
"is_current": boolean,
|
"frequency": float,
|
||||||
"is_preferred": boolean
|
"is_current": boolean,
|
||||||
}
|
"is_preferred": boolean
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
},
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"is_connected": boolean,
|
"is_connected": boolean,
|
||||||
"is_primary": boolean,
|
"is_primary": boolean,
|
||||||
"device_name": string,
|
"device_name": string,
|
||||||
@ -73,50 +75,52 @@ Examples:
|
|||||||
"current_height": 1080,
|
"current_height": 1080,
|
||||||
"maximum_width": 32767,
|
"maximum_width": 32767,
|
||||||
"maximum_height": 32767,
|
"maximum_height": 32767,
|
||||||
"devices": {
|
"devices": [
|
||||||
"modes": [
|
{
|
||||||
{
|
"modes": [
|
||||||
"resolution_width": 1920,
|
{
|
||||||
"resolution_height": 1080,
|
"resolution_width": 1920,
|
||||||
"is_high_resolution": false,
|
"resolution_height": 1080,
|
||||||
"frequencies": [
|
"is_high_resolution": false,
|
||||||
{
|
"frequencies": [
|
||||||
"frequency": 60.03,
|
{
|
||||||
"is_current": true,
|
"frequency": 60.03,
|
||||||
"is_preferred": true
|
"is_current": true,
|
||||||
},
|
"is_preferred": true
|
||||||
{
|
},
|
||||||
"frequency": 59.93,
|
{
|
||||||
"is_current": false,
|
"frequency": 59.93,
|
||||||
"is_preferred": false
|
"is_current": false,
|
||||||
}
|
"is_preferred": false
|
||||||
]
|
}
|
||||||
},
|
]
|
||||||
{
|
},
|
||||||
"resolution_width": 1680,
|
{
|
||||||
"resolution_height": 1050,
|
"resolution_width": 1680,
|
||||||
"is_high_resolution": false,
|
"resolution_height": 1050,
|
||||||
"frequencies": [
|
"is_high_resolution": false,
|
||||||
{
|
"frequencies": [
|
||||||
"frequency": 59.88,
|
{
|
||||||
"is_current": false,
|
"frequency": 59.88,
|
||||||
"is_preferred": false
|
"is_current": false,
|
||||||
}
|
"is_preferred": false
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
],
|
}
|
||||||
"is_connected": true,
|
],
|
||||||
"is_primary": true,
|
"is_connected": true,
|
||||||
"device_name": "eDP1",
|
"is_primary": true,
|
||||||
"resolution_width": 1920,
|
"device_name": "eDP1",
|
||||||
"resolution_height": 1080,
|
"resolution_width": 1920,
|
||||||
"offset_width": 0,
|
"resolution_height": 1080,
|
||||||
"offset_height": 0,
|
"offset_width": 0,
|
||||||
"dimension_width": 310,
|
"offset_height": 0,
|
||||||
"dimension_height": 170,
|
"dimension_width": 310,
|
||||||
"rotation": "normal",
|
"dimension_height": 170,
|
||||||
"reflection": "normal"
|
"rotation": "normal",
|
||||||
}
|
"reflection": "normal"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -132,53 +136,55 @@ Examples:
|
|||||||
"current_height": 1080,
|
"current_height": 1080,
|
||||||
"maximum_width": 32767,
|
"maximum_width": 32767,
|
||||||
"maximum_height": 32767,
|
"maximum_height": 32767,
|
||||||
"devices": {
|
"devices": [
|
||||||
"modes": [
|
{
|
||||||
{
|
"modes": [
|
||||||
"resolution_width": 1920,
|
{
|
||||||
"resolution_height": 1080,
|
"resolution_width": 1920,
|
||||||
"is_high_resolution": false,
|
"resolution_height": 1080,
|
||||||
"frequencies": [
|
"is_high_resolution": false,
|
||||||
{
|
"frequencies": [
|
||||||
"frequency": 60.03,
|
{
|
||||||
"is_current": true,
|
"frequency": 60.03,
|
||||||
"is_preferred": true
|
"is_current": true,
|
||||||
},
|
"is_preferred": true
|
||||||
{
|
},
|
||||||
"frequency": 59.93,
|
{
|
||||||
"is_current": false,
|
"frequency": 59.93,
|
||||||
"is_preferred": false
|
"is_current": false,
|
||||||
}
|
"is_preferred": false
|
||||||
]
|
}
|
||||||
},
|
]
|
||||||
{
|
},
|
||||||
"resolution_width": 1680,
|
{
|
||||||
"resolution_height": 1050,
|
"resolution_width": 1680,
|
||||||
"is_high_resolution": false,
|
"resolution_height": 1050,
|
||||||
"frequencies": [
|
"is_high_resolution": false,
|
||||||
{
|
"frequencies": [
|
||||||
"frequency": 59.88,
|
{
|
||||||
"is_current": false,
|
"frequency": 59.88,
|
||||||
"is_preferred": false
|
"is_current": false,
|
||||||
}
|
"is_preferred": false
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
],
|
}
|
||||||
"is_connected": true,
|
],
|
||||||
"is_primary": true,
|
"is_connected": true,
|
||||||
"device_name": "eDP1",
|
"is_primary": true,
|
||||||
"model_name": "ASUS VW193S",
|
"device_name": "eDP1",
|
||||||
"product_id": "54297",
|
"model_name": "ASUS VW193S",
|
||||||
"serial_number": "78L8021107",
|
"product_id": "54297",
|
||||||
"resolution_width": 1920,
|
"serial_number": "78L8021107",
|
||||||
"resolution_height": 1080,
|
"resolution_width": 1920,
|
||||||
"offset_width": 0,
|
"resolution_height": 1080,
|
||||||
"offset_height": 0,
|
"offset_width": 0,
|
||||||
"dimension_width": 310,
|
"offset_height": 0,
|
||||||
"dimension_height": 170,
|
"dimension_width": 310,
|
||||||
"rotation": "normal",
|
"dimension_height": 170,
|
||||||
"reflection": "normal"
|
"rotation": "normal",
|
||||||
}
|
"reflection": "normal"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -192,7 +198,6 @@ from jc.parsers.pyedid.helpers.edid_helper import EdidHelper
|
|||||||
|
|
||||||
class info:
|
class info:
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
|
|
||||||
version = "1.4"
|
version = "1.4"
|
||||||
description = "`xrandr` command parser"
|
description = "`xrandr` command parser"
|
||||||
author = "Kevin Lyter"
|
author = "Kevin Lyter"
|
||||||
@ -206,8 +211,18 @@ class info:
|
|||||||
__version__ = info.version
|
__version__ = info.version
|
||||||
|
|
||||||
# keep parsing state so we know which parsers have already tried the line
|
# keep parsing state so we know which parsers have already tried the line
|
||||||
|
# Structure is:
|
||||||
|
# {
|
||||||
|
# <line_string>: [
|
||||||
|
# <parser_string>
|
||||||
|
# ]
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# Where <line_string> is the xrandr output line to be checked and <parser_string>
|
||||||
|
# can contain "screen", "device", or "model"
|
||||||
parse_state: Dict[str, List] = {}
|
parse_state: Dict[str, List] = {}
|
||||||
|
|
||||||
|
|
||||||
def _was_parsed(line: str, parser: str) -> bool:
|
def _was_parsed(line: str, parser: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if entered parser has already parsed. If so return True.
|
Check if entered parser has already parsed. If so return True.
|
||||||
@ -522,9 +537,10 @@ def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict:
|
|||||||
|
|
||||||
linedata = data.splitlines()
|
linedata = data.splitlines()
|
||||||
linedata.reverse() # For popping
|
linedata.reverse() # For popping
|
||||||
result: Response = {"screens": []}
|
result: Dict = {}
|
||||||
|
|
||||||
if jc.utils.has_data(data):
|
if jc.utils.has_data(data):
|
||||||
|
result = {"screens": []}
|
||||||
while linedata:
|
while linedata:
|
||||||
screen = _parse_screen(linedata)
|
screen = _parse_screen(linedata)
|
||||||
if screen:
|
if screen:
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
import re
|
import re
|
||||||
import unittest
|
import unittest
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
@ -22,8 +21,6 @@ from jc.parsers.xrandr import (
|
|||||||
)
|
)
|
||||||
import jc.parsers.xrandr
|
import jc.parsers.xrandr
|
||||||
|
|
||||||
import pprint
|
|
||||||
|
|
||||||
|
|
||||||
class XrandrTests(unittest.TestCase):
|
class XrandrTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -33,7 +30,7 @@ class XrandrTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
Test 'xrandr' with no data
|
Test 'xrandr' with no data
|
||||||
"""
|
"""
|
||||||
self.assertEqual(parse("", quiet=True), {"screens": []})
|
self.assertEqual(parse("", quiet=True), {})
|
||||||
|
|
||||||
def test_regexes(self):
|
def test_regexes(self):
|
||||||
devices = [
|
devices = [
|
||||||
|
Reference in New Issue
Block a user