mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-18 21:35:44 +00:00
validate:tools: Use regex for parsing when appropriate
This commit is contained in:
parent
df712e9404
commit
ca12b78be3
2 changed files with 24 additions and 17 deletions
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue