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

add file id to the csv file

parent 0f71126c
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ from skluc.main.utils import logger ...@@ -25,7 +25,7 @@ from skluc.main.utils import logger
if __name__ == '__main__': if __name__ == '__main__':
arguments = docopt.docopt(__doc__) arguments = docopt.docopt(__doc__)
pattern_to_recognize = arguments["--patern"] pattern_to_recognize = arguments["--patern"] #.+\_stdout.txt
mypath = os.path.abspath(arguments["--input-dir"]) mypath = os.path.abspath(arguments["--input-dir"])
res_walk = walk(mypath) res_walk = walk(mypath)
onlyfiles = [] onlyfiles = []
...@@ -35,18 +35,21 @@ if __name__ == '__main__': ...@@ -35,18 +35,21 @@ if __name__ == '__main__':
results = [] results = []
compiled_re = re.compile(pattern_to_recognize) compiled_re = re.compile(pattern_to_recognize)
first_line = "" first_line = ""
pattern_file_id = r".+\d+job_(\d+)\.\d+_.+"
compiled_re_file_id = re.compile(pattern_file_id)
for f_name in onlyfiles: for f_name in onlyfiles:
if compiled_re.match(f_name) is None: if compiled_re.match(f_name) is None:
continue continue
file_id = compiled_re_file_id.match(f_name).group(1)
with open(f_name, "r") as f: with open(f_name, "r") as f:
lines = f.readlines() lines = f.readlines()
try: try:
if not first_line and arguments["--header"]: if not first_line and arguments["--header"]:
first_line = lines[0].strip() first_line = lines[0].strip() + ",file_timestamp"
if arguments["--header"]: if arguments["--header"]:
results.append(lines[1].strip()) results.append(lines[1].strip() + "," + file_id)
else: else:
results.append(lines[0].strip()) results.append(lines[0].strip() + "," + file_id)
except IndexError: except IndexError:
results.append("") results.append("")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment