]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Improve readability
authorLuke Arms <github@lkr.ms>
Wed, 30 Jun 2021 23:05:01 +0000 (09:05 +1000)
committerLuke Arms <github@lkr.ms>
Wed, 30 Jun 2021 23:05:01 +0000 (09:05 +1000)
autorandr.py

index b8b9908eeee87721d07308baaa2c0535bd9321f3..c1bdd1971e81e3d7c174e2f6202a7d18bbe61bd4 100755 (executable)
@@ -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<output>\S[^ ]*)\s+                                                      # Line starts with output name
@@ -185,7 +190,7 @@ class XrandrOutput(object):
             CRTC:\s*(?P<crtc>[0-9]) |                                                   # CRTC value
             Transform: (?P<transform>(?:[\-0-9\. ]+\s+){3}) |                           # Transformation matrix
             EDID: (?P<edid>\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<mode_height>[0-9]+).+clock\s+(?P<rate>[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<name>\S+).+?(?P<preferred>\+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",