]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
xrandr parsing regex updated
authorPhillip Berndt <phillip.berndt@googlemail.com>
Tue, 6 Jan 2015 20:36:03 +0000 (21:36 +0100)
committerPhillip Berndt <phillip.berndt@googlemail.com>
Wed, 7 Jan 2015 06:44:28 +0000 (07:44 +0100)
autorandr.py

index f70fc91a51dae1b74a271f6921320a96eda1c7c2..e19e8648f36597b39a175cae56917a4ae065b5b7 100755 (executable)
@@ -81,15 +81,15 @@ class XrandrOutput(object):
             \+(?P<x>[0-9]+)\+(?P<y>[0-9]+)\s+                                           # Position
             (?P<rotation>[^(]\S+)?                                                      # Has a value if the output is rotated
         ).*
-        (?:\s+(?:                                                                       # Properties of the output
+        (?:\s*(?:                                                                       # Properties of the output
             Gamma: (?P<gamma>[0-9\.:\s]+) |                                             # Gamma value
             Transform: (?P<transform>[0-9\.\s]+) |                                      # Transformation matrix
             EDID: (?P<edid>[0-9a-f\s]+) |                                               # EDID of the output
-            (?![0-9])[^:\s]+:.*(?:\s\\t[\\t ].+)*                                       # Other properties
+            (?![0-9])[^:\s][^:\n]+:.*(?:\s\\t[\\t ].+)*                                       # Other properties
         ))+
         \s*
         (?:  [0-9]+x[0-9]+.+?\*current.+\s+h:.+\s+v:.+clock\s+(?P<rate>[0-9\.]+)Hz\s* | # Interesting (current) resolution: Extract rate
-          [0-9]+x[0-9]+.+\s+h:.+\s+v:.+\s* |                                            # Other resolutions
+          [0-9]+x[0-9]+.+\s+h:.+\s+v:.+\s*                                              # Other resolutions
         )*
         $
     """
@@ -127,7 +127,11 @@ class XrandrOutput(object):
     @classmethod
     def from_xrandr_output(cls, xrandr_output):
         "Instanciate an XrandrOutput from the output of `xrandr --verbose'"
-        match = re.search(XrandrOutput.XRANDR_OUTPUT_REGEXP, xrandr_output).groupdict()
+        match_object = re.search(XrandrOutput.XRANDR_OUTPUT_REGEXP, xrandr_output)
+        remainder = xrandr_output[len(match_object.group(0)):]
+        if remainder:
+            raise RuntimeError("Parsing XRandR output failed, %d bytes left." % len(remainder))
+        match = match_object.groupdict()
 
         options = {}
         if not match["connected"]: