Skip to content
Snippets Groups Projects
Commit 2b7b4c04 authored by Luc Giffon's avatar Luc Giffon
Browse files

add option pattern to gatherresult with regular expression usage

parent f2f7e747
No related branches found
No related tags found
No related merge requests found
...@@ -4,33 +4,37 @@ gather_results: gather OAR results from one dir to one file called gathered_resu ...@@ -4,33 +4,37 @@ gather_results: gather OAR results from one dir to one file called gathered_resu
The result files should consist of lines and should have "stdout" in their name. The result files should consist of lines and should have "stdout" in their name.
Usage: Usage:
gather_results -i IPATH gather_results -i IPATH [-p regex]
Options: Options:
-h --help Show this screen. -h --help Show this screen.
-i --input-dir=<IPATH> Inut directory wher to find results -i --input-dir=<IPATH> Input directory wher to find results
-p --patern=regex Specify the pattern of the files to be looked at [default: .+\.stdout].
""" """
from os import listdir from os import listdir
import os import os
from os.path import isfile, join from os.path import isfile, join
import docopt import docopt
import re
if __name__ == '__main__': if __name__ == '__main__':
arguments = docopt.docopt(__doc__) arguments = docopt.docopt(__doc__)
pattern_to_recognize = arguments["--patern"]
mypath = os.path.abspath(arguments["--input-dir"]) mypath = os.path.abspath(arguments["--input-dir"])
onlyfiles = [os.path.join(mypath, f) for f in listdir(mypath) if isfile(join(mypath, f))] onlyfiles = [os.path.join(mypath, f) for f in listdir(mypath) if isfile(join(mypath, f))]
count = 0 count = 0
results = [] results = []
compiled_re = re.compile(pattern_to_recognize)
for f_name in onlyfiles: for f_name in onlyfiles:
if ".stdout" not in f_name: if compiled_re.match(f_name) is None:
continue continue
with open(f_name, "r") as f: with open(f_name, "r") as f:
str_f = f.read().strip() str_f = f.read().strip()
results.append(str_f) results.append(str_f)
with open(os.path.join(mypath, "gathered_results"), 'w') as f_w: with open(os.path.join(mypath, "gathered_results.csv"), 'w') as f_w:
for s in results: for s in results:
f_w.write(s) f_w.write(s)
f_w.write("\n") f_w.write("\n")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment