From 59dd78f9b2cd2bc0884f5cfd25306eef02468838 Mon Sep 17 00:00:00 2001 From: Cyprian Laskowski Date: Thu, 18 Mar 2021 09:10:27 +0100 Subject: [PATCH] IssueID #1835: fixed use of tempfile --- scripts/process.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/process.py b/scripts/process.py index fcfb48a..f1e9f9a 100644 --- a/scripts/process.py +++ b/scripts/process.py @@ -1,24 +1,26 @@ import argparse import tempfile -import os +import shutil from structure_assignment.pipeline import Pipeline, create_nlp resource_directory = '../resources' def run_all(input_file_name, output_file_name, nlp, structure_file_name): - tmp_file_name = tempfile.mksfile() - string_to_parse(input_file_name, tmp_file_name, nlp) + tmp_directory = tempfile.mkdtemp() + tmp_file_name = tmp_directory + '/parsed.xml' + strings_to_parse(input_file_name, tmp_file_name, nlp) parse_to_dictionary(tmp_file_name, output_file_name, structure_file_name) - os.remove(tmp_file_name) + shutil.rmtree(tmp_directory) validate_structures(structure_file_name) validate_dictionary(output_file_name) def strings_to_dictionary(input_file_name, output_file_name, nlp, structure_file_name): - tmp_file_name = tempfile.mksfile() - string_to_parse(input_file_name, tmp_file_name, nlp) + tmp_directory = tempfile.mkdtemp() + tmp_file_name = tmp_directory + '/parsed.xml' + strings_to_parse(input_file_name, tmp_file_name, nlp) parse_to_dictionary(tmp_file_name, output_file_name, structure_file_name) - os.remove(tmp_file_name) + shutil.rmtree(tmp_directory) def strings_to_parse(input_file_name, output_file_name, nlp): pipeline = Pipeline(resource_directory, nlp)