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
|
||||
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,7 +26,8 @@ Schema:
|
||||
"current_height": integer,
|
||||
"maximum_width": integer,
|
||||
"maximum_height": integer,
|
||||
"devices": {
|
||||
"devices": [
|
||||
{
|
||||
"modes": [
|
||||
{
|
||||
"resolution_width": integer,
|
||||
@ -41,7 +42,8 @@ Schema:
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
],
|
||||
"is_connected": boolean,
|
||||
"is_primary": boolean,
|
||||
"device_name": string,
|
||||
@ -73,7 +75,8 @@ Examples:
|
||||
"current_height": 1080,
|
||||
"maximum_width": 32767,
|
||||
"maximum_height": 32767,
|
||||
"devices": {
|
||||
"devices": [
|
||||
{
|
||||
"modes": [
|
||||
{
|
||||
"resolution_width": 1920,
|
||||
@ -117,6 +120,7 @@ Examples:
|
||||
"rotation": "normal",
|
||||
"reflection": "normal"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -132,7 +136,8 @@ Examples:
|
||||
"current_height": 1080,
|
||||
"maximum_width": 32767,
|
||||
"maximum_height": 32767,
|
||||
"devices": {
|
||||
"devices": [
|
||||
{
|
||||
"modes": [
|
||||
{
|
||||
"resolution_width": 1920,
|
||||
@ -179,6 +184,7 @@ Examples:
|
||||
"rotation": "normal",
|
||||
"reflection": "normal"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -192,7 +198,6 @@ from jc.parsers.pyedid.helpers.edid_helper import EdidHelper
|
||||
|
||||
class info:
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
|
||||
version = "1.4"
|
||||
description = "`xrandr` command parser"
|
||||
author = "Kevin Lyter"
|
||||
@ -206,8 +211,18 @@ class info:
|
||||
__version__ = info.version
|
||||
|
||||
# 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] = {}
|
||||
|
||||
|
||||
def _was_parsed(line: str, parser: str) -> bool:
|
||||
"""
|
||||
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.reverse() # For popping
|
||||
result: Response = {"screens": []}
|
||||
result: Dict = {}
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
result = {"screens": []}
|
||||
while linedata:
|
||||
screen = _parse_screen(linedata)
|
||||
if screen:
|
||||
|
@ -1,4 +1,3 @@
|
||||
import json
|
||||
import re
|
||||
import unittest
|
||||
from typing import Optional
|
||||
@ -22,8 +21,6 @@ from jc.parsers.xrandr import (
|
||||
)
|
||||
import jc.parsers.xrandr
|
||||
|
||||
import pprint
|
||||
|
||||
|
||||
class XrandrTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@ -33,7 +30,7 @@ class XrandrTests(unittest.TestCase):
|
||||
"""
|
||||
Test 'xrandr' with no data
|
||||
"""
|
||||
self.assertEqual(parse("", quiet=True), {"screens": []})
|
||||
self.assertEqual(parse("", quiet=True), {})
|
||||
|
||||
def test_regexes(self):
|
||||
devices = [
|
||||
|
Reference in New Issue
Block a user