summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <thibault.saunier@collabora.com>2014-01-31 12:21:21 +0100
committerThibault Saunier <thibault.saunier@collabora.com>2014-02-18 21:07:31 +0100
commitca12b78be38f394d800d3a9033971d87203e250b (patch)
treed9ae8b1127bf2cd64b5aab03fc4d02da6b35a5d4
parentdf712e9404df418ab0189a778c3b90cfa05d3aac (diff)
validate:tools: Use regex for parsing when appropriate
-rw-r--r--validate/tools/launcher/baseclasses.py29
-rw-r--r--validate/tools/launcher/utils.py12
2 files changed, 24 insertions, 17 deletions
diff --git a/validate/tools/launcher/baseclasses.py b/validate/tools/launcher/baseclasses.py
index 3a90df3..4d20250 100644
--- a/validate/tools/launcher/baseclasses.py
+++ b/validate/tools/launcher/baseclasses.py
@@ -200,6 +200,8 @@ class Test(Loggable):
class GstValidateTest(Test):
""" A class representing a particular test. """
+ findpos_regex = re.compile('.*position.*(\d+):(\d+):(\d+).(\d+).*duration.*(\d+):(\d+):(\d+).(\d+)')
+ findlastseek_regex = re.compile('seeking to.*(\d+):(\d+):(\d+).(\d+).*stop.*(\d+):(\d+):(\d+).(\d+).*rate.*(\d+)\.(\d+)')
def __init__(self, application_name, classname,
options, reporter, timeout=DEFAULT_TIMEOUT,
@@ -263,17 +265,14 @@ class GstValidateTest(Test):
))
def _parse_position(self, p):
self.log("Parsing %s" % p)
+ times = self.findpos_regex.findall(p)
- start_stop = p.replace("<position: ", '').replace("/>", "").split(" duration: ")
-
- if len(start_stop) < 2:
+ if len(times) != 1:
self.warning("Got a unparsable value: %s" % p)
return 0, 0
- if "speed:"in start_stop[1]:
- start_stop[1] = start_stop[1].split("speed:")[0].rstrip().lstrip()
-
- return utils.parse_gsttimeargs(start_stop[0]), utils.parse_gsttimeargs(start_stop[1])
+ return (utils.gsttime_from_tuple(times[0][:4]),
+ utils.gsttime_from_tuple(times[0][4:]))
def _parse_buffering(self, b):
@@ -303,7 +302,7 @@ class GstValidateTest(Test):
elif j.startswith("buffering") and j.endswith("%"):
position, duration = self._parse_buffering(j)
else:
- self.debug("No info in %s" % j)
+ self.log("No info in %s" % j)
return position, duration
@@ -321,12 +320,16 @@ class GstValidateTest(Test):
self.debug("Could not fine any seeking info")
return start, stop, rate
- tmp = m.split("seeking to: ")[1].split(" stop: ")
- start = tmp[0]
- stop_rate = tmp[1].split(" Rate")
- return utils.parse_gsttimeargs(start), \
- utils.parse_gsttimeargs(stop_rate[0]), float(stop_rate[1].replace(":",""))
+ values = self.findlastseek_regex.findall(m)
+ if len(values) != 1:
+ self.warning("Got a unparsable value: %s" % p)
+ return start, stop, rate
+
+ v = values[0]
+ return (utils.gsttime_from_tuple(v[:4]),
+ utils.gsttime_from_tuple(v[4:8]),
+ float(str(v[8]) + "." + str(v[9])))
def get_current_position(self):
position, duration = self._get_position()
diff --git a/validate/tools/launcher/utils.py b/validate/tools/launcher/utils.py
index 4f6f091..e3faa90 100644
--- a/validate/tools/launcher/utils.py
+++ b/validate/tools/launcher/utils.py
@@ -19,11 +19,14 @@
""" Some utilies. """
import os
+import re
import urllib
import loggable
import urlparse
import subprocess
+from operator import itemgetter
+
GST_SECOND = 1000000000
DEFAULT_TIMEOUT = 10
@@ -199,11 +202,12 @@ def get_profile(combination):
##################################################
# Some utilities to parse gst-validate output #
##################################################
+def gsttime_from_tuple(stime):
+ return long((int(stime[0]) * 3600 + int(stime[1]) * 60 + int(stime[2]) * 60) * GST_SECOND + int(stime[3]))
+
+timeregex = re.compile(r'(?P<_0>.+):(?P<_1>.+):(?P<_2>.+)\.(?P<_3>.+)')
def parse_gsttimeargs(time):
- stime = time.split(":")
- sns = stime[2].split(".")
- stime[2] = sns[0]
- stime.append(sns[1])
+ stime = map(itemgetter(1), sorted(timeregex.match(time).groupdict().items()))
return long((int(stime[0]) * 3600 + int(stime[1]) * 60 + int(stime[2]) * 60) * GST_SECOND + int(stime[3]))
def get_duration(media_file):