From bb59817c165ac85356206dd4ab3777062ee3fa46 Mon Sep 17 00:00:00 2001 From: Luke Arms Date: Thu, 1 Jul 2021 09:05:01 +1000 Subject: [PATCH] Improve readability --- autorandr.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/autorandr.py b/autorandr.py index b8b9908..c1bdd19 100755 --- a/autorandr.py +++ b/autorandr.py @@ -159,6 +159,11 @@ class AutorandrException(Exception): class XrandrOutput(object): "Represents an XRandR output" + XRANDR_PROPERTIES_REGEXP = "|".join( + [r"{}:\s*(?P<{}>[\S ]*\S+)" + .format(p, re.sub(r"\W+", "_", p.lower())) + for p in properties]) + # This regular expression is used to parse an output in `xrandr --verbose' XRANDR_OUTPUT_REGEXP = """(?x) ^\s*(?P\S[^ ]*)\s+ # Line starts with output name @@ -185,7 +190,7 @@ class XrandrOutput(object): CRTC:\s*(?P[0-9]) | # CRTC value Transform: (?P(?:[\-0-9\. ]+\s+){3}) | # Transformation matrix EDID: (?P\s*?(?:\\n\\t\\t[0-9a-f]+)+) | # EDID of the output - %s | # Properties to include in the profile + """ + XRANDR_PROPERTIES_REGEXP + """ | # Properties to include in the profile (?![0-9])[^:\s][^:\n]+:.*(?:\s\\t[\\t ].+)* # Other properties ))+ \s* @@ -195,9 +200,7 @@ class XrandrOutput(object): v:\s+height\s+(?P[0-9]+).+clock\s+(?P[0-9\.]+)Hz\s* | \S+(?:(?!\*current).)+\s+h:.+\s+v:.+\s* # Other resolutions )*) - """ % ("|".join([r"{}:\s*(?P<{}>[\S ]*\S+)" - .format(re.sub(r"(\s)", r"\\\1", p), - re.sub(r"\W+", "_", p.lower())) for p in properties])) + """ XRANDR_OUTPUT_MODES_REGEXP = """(?x) (?P\S+).+?(?P\+preferred)?\s+ @@ -1234,7 +1237,6 @@ def read_config(options, directory): for key, value in config.items("config"): options.setdefault("--%s" % key, value) - def main(argv): try: opts, args = getopt.getopt(argv[1:], "s:r:l:d:cfh", -- 2.39.2