[Piglit] [PATCH v2 3/3] core.py: Move parse_listfile to core.py

Dylan Baker baker.dylan.c at gmail.com
Thu Aug 29 13:56:57 PDT 2013


Replaces the two individual implementations of parse_listfile with a
single shared instance in core.py.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/core.py      | 19 ++++++++++++++++++-
 piglit-summary-html.py | 12 +-----------
 piglit-summary.py      |  9 +--------
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index b1a5726..4c36942 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -619,7 +619,6 @@ def loadTestResults(relativepath):
     assert(testrun.name is not None)
     return testrun
 
-
 # Error messages to be ignored
 Test.ignoreErrors = map(re.compile,
                         ["couldn't open libtxc_dxtn.so",
@@ -663,3 +662,21 @@ Test.ignoreErrors = map(re.compile,
                          ".*DeviceName.*",
                          "No memory leaks detected.",
                          "libGL: Can't open configuration file.*"])
+
+
+def parse_listfile(filename):
+    """
+    Parses a newline-seperated list in a text file and reutnrs a python list
+    object. It will expand tildes on Unix-like system to the users home
+    directory.
+
+    ex file.txt:
+        ~/tests1
+        ~/tests2/main
+        /tmp/test3
+
+    returns:
+        ['/home/user/tests1', '/home/users/tests2/main', '/tmp/test3']
+    """
+    with open(filename, 'r') as file:
+        return [path.expanduser(i.rstrip('\n')) for i in file.readlines()]
diff --git a/piglit-summary-html.py b/piglit-summary-html.py
index 6fed689..b9a2996 100755
--- a/piglit-summary-html.py
+++ b/piglit-summary-html.py
@@ -27,21 +27,11 @@ import shutil
 import os.path as path
 
 import framework.summary as summary
-from framework.core import checkDir
+from framework.core import checkDir, parse_listfile
 
 sys.path.append(path.dirname(path.realpath(sys.argv[0])))
 
 
-def parse_listfile(filename):
-    """
-    Read a list of newline seperated flies and return them as a python list.
-    strip the last newline character so the list doesn't have an extra ''
-    element at the end.
-    """
-    with open(filename, 'r') as file:
-        return [path.expanduser(i.rstrip('\n')) for i in file.readlines()]
-
-
 def main():
     parser = argparse.ArgumentParser()
     parser.add_argument("-o", "--overwrite",
diff --git a/piglit-summary.py b/piglit-summary.py
index 24bb30d..ebc01b8 100755
--- a/piglit-summary.py
+++ b/piglit-summary.py
@@ -35,14 +35,7 @@ import sys
 
 sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
 import framework.summary as summary
-
-
-def parse_listfile(filename):
-    """
-    Read a list of newline seperated file names and return them as a list
-    """
-    with open(filename, 'r') as file:
-        return [path.expanduser(i.rstrip('\n')) for i in file.readlines()]
+from framework.core import parse_listfile
 
 def main():
     parser = argparse.ArgumentParser()
-- 
1.8.1.5



More information about the Piglit mailing list