diff --git a/skluc/main/tools/experiences/check_stderr.py b/skluc/main/tools/experiences/check_stderr.py index 7acd9193dac9c1c2ed8b0e809d36b5f961fa396b..a217ce64967d3b8e80ac08f4b64a048f5a3412a4 100644 --- a/skluc/main/tools/experiences/check_stderr.py +++ b/skluc/main/tools/experiences/check_stderr.py @@ -1,17 +1,43 @@ +""" +check_stderr: Gather errors of OAR experiments in one file.zipfile.BadZipFile: Bad CRC-32 + +Usage: + check_stderr -i IPATH [-p regex] [-P str] [--header] [--verbose] [--commands str] + +Options: + -h --help Show this screen. + -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.txt]. + -P --patern-error=regex Specify the pattern of the error files to be looked at [default: _stderr.txt]. + -r --header Says if there is a header in the result files. + -c --commands=str Write a file containg the command lines arguments for the scripts that have led to an error + -v --verbose Print the lines of the final file +""" + import re +import os from os import walk from os.path import isfile, join +import docopt + if __name__ == "__main__": - path = "/home/luc/Resultats/Deepstrom/september_2018/deepfried_rel" + arguments = docopt.docopt(__doc__) + pattern = arguments["--patern"] + pattern_err = arguments["--patern-error"] + pattern_cmd = arguments["--commands"] + path = os.path.abspath(arguments["--input-dir"]) + onlyfiles = [] for dirpath, dirnames, filenames in walk(path): onlyfiles.extend([join(dirpath, f) for f in filenames if isfile(join(dirpath, f))]) - pattern = "(.+)_stdout.txt" compiled_re = re.compile(pattern) + if pattern_cmd is not None: + compiled_re_cmd = re.compile(pattern_cmd) errors = [] + command_lines = [] for f_name in onlyfiles: if not compiled_re.match(f_name): continue @@ -21,12 +47,22 @@ if __name__ == "__main__": if str_f == "": f_name_split = f_name.split("_") f_name_base = "_".join(f_name_split[:-1]) - f_name_err = f_name_base + "_stderr.txt" + f_name_err = f_name_base + pattern_err with open(f_name_err, 'r') as ferr: str_ferr = ferr.read().strip() errors.append(str_ferr) + if pattern_cmd is not None: + match = compiled_re_cmd.search(str_ferr) + str_match = match.group(1).strip() + command_lines.append(str_match) with open(join(path, "errors.txt"), 'w') as f_out_err: for err in errors: f_out_err.write(err) - f_out_err.write("\n\n\n\n") \ No newline at end of file + f_out_err.write("\n\n\n\n") + + if pattern_cmd is not None: + with open(join(path, "array_param_cmd_errors.txt"), 'w') as f_out_cmd_err: + for cmd in command_lines: + f_out_cmd_err.write(cmd) + f_out_cmd_err.write("\n") \ No newline at end of file diff --git a/skluc/main/tools/experiences/cmd_line_pattern_ex.txt b/skluc/main/tools/experiences/cmd_line_pattern_ex.txt new file mode 100644 index 0000000000000000000000000000000000000000..d43e1c8b5ab7fd92965f196c4e8807841c802d41 --- /dev/null +++ b/skluc/main/tools/experiences/cmd_line_pattern_ex.txt @@ -0,0 +1 @@ +Command line:\s.+\.py\s(.+)\n