Use regular expression to find TSC speed
authorReto Buerki <reet@codelabs.ch>
Tue, 12 Sep 2017 19:17:53 +0000 (21:17 +0200)
committerReto Buerki <reet@codelabs.ch>
Tue, 12 Sep 2017 19:43:26 +0000 (21:43 +0200)
src/creator.py

index 2e457cc..88f4139 100644 (file)
@@ -26,6 +26,7 @@ import customExceptions
 import util
 import paths
 import os
+import re
 import message
 import devicecap
 import extractor
@@ -77,21 +78,22 @@ class ProcessorCreator():
 
     def getSpeed(self, dmesgpath):
         "Gets speed value from dmesg"
-        PARSE_KEYWORD = "Refined TSC clocksource calibration"
+        regex = re.compile(r'.*Refined TSC clocksource calibration: '
+                           '(?P<speed>.*)')
         result = 0
         try:
             data = extractor.extractData(dmesgpath)
-            speedstr = parseutil.parseData_Sep(data, PARSE_KEYWORD, ":")
-            result = util.getSpeedValue(speedstr, PROCESSOR_SPEED_KEYWORDS)
+            match = regex.search(data)
+            if match is None:
+                message.addError("Could not find refined TSC clocksource "
+                                 "calibration results in: %s\n" % dmesgpath +
+                                 "Processor speed not found.")
+            result = util.getSpeedValue(match.group("speed"),
+                                        PROCESSOR_SPEED_KEYWORDS)
         except IOError:
             errstr = ("Could not read file: %s\n" % dmesgpath +
                       "Processor speed not found.")
             message.addError(errstr)
-        except customExceptions.KeyNotFound:
-            errstr = ("Could not find refined TSC clocksource "
-                      "calibration results in: %s\n" % dmesgpath +
-                      "Processor speed not found.")
-            message.addError(errstr)
         else:
             return result