Skip to content
Snippets Groups Projects
Commit 97c3cef8 authored by Paweł Walkowiak's avatar Paweł Walkowiak
Browse files

Merge branch 'develop' into 'master'

Develop

See merge request !2
parents b75ca6de 50106399
No related branches found
No related tags found
1 merge request!2Develop
Pipeline #10130 passed
...@@ -25,7 +25,7 @@ build: ...@@ -25,7 +25,7 @@ build:
image: docker:18.09.7 image: docker:18.09.7
only: only:
- master - master
- Init - develop
services: services:
- 'docker:18.09.7-dind' - 'docker:18.09.7-dind'
script: script:
......
...@@ -236,7 +236,7 @@ class ArchiveExtractor(nlp_ws.NLPWorker): ...@@ -236,7 +236,7 @@ class ArchiveExtractor(nlp_ws.NLPWorker):
def _safe_report(self, input_size_report: Dict, input_size_sum: int, def _safe_report(self, input_size_report: Dict, input_size_sum: int,
output_size_report: Dict, output_size_sum: int, output_size_report: Dict, output_size_sum: int,
error_report_before: Dict, error_report_after: Dict, error_report_before: Dict, error_report_after: Dict,
files_to_convert: List, dir_path: str): files_to_convert: List, output_path: str, dir_path: str):
"""Save size and error reports to json file. """Save size and error reports to json file.
:param input_size_report: input size report :param input_size_report: input size report
...@@ -253,6 +253,8 @@ class ArchiveExtractor(nlp_ws.NLPWorker): ...@@ -253,6 +253,8 @@ class ArchiveExtractor(nlp_ws.NLPWorker):
:type error_report_after: Dict :type error_report_after: Dict
:param files_to_convert: converted files :param files_to_convert: converted files
:type files_to_convert: List :type files_to_convert: List
:param output_path: Path to output location.
:type output_path: str
:param dir_path: Path to directory where the :param dir_path: Path to directory where the
worker will store result files. worker will store result files.
:type dir_path: str :type dir_path: str
...@@ -267,10 +269,28 @@ class ArchiveExtractor(nlp_ws.NLPWorker): ...@@ -267,10 +269,28 @@ class ArchiveExtractor(nlp_ws.NLPWorker):
self.INPUT_SIZES_SUM: input_size_sum, self.INPUT_SIZES_SUM: input_size_sum,
self.OUTPUT_SIZES: output_size_report, self.OUTPUT_SIZES: output_size_report,
self.OUTPUT_SIZES_SUM: output_size_sum} self.OUTPUT_SIZES_SUM: output_size_sum}
filename = os.path.join(dir_path, 'report.json') filename = os.path.join(output_path, 'report.json')
with open(filename, 'w') as outfile: with open(filename, 'w') as outfile:
json.dump(data, outfile) json.dump(data, outfile)
def _pack_result(self, output_path: str, dir_path: str):
"""Pack cleaned files to zip, removes unpacked files.
:param output_path: Path to output location.
:type output_path: str
:param dir_path: Path to directory where the
worker store result files.
:type dir_path: str
"""
zip_name = os.path.join(output_path, 'result.zip')
_log.info("Packing results to zip...")
with ZipFile(zip_name, 'w') as zip_obj:
for file_path, filename in self._file_generator(dir_path):
zip_obj.write(file_path, filename)
_log.info("Packing completed, removing unpacked files")
shutil.rmtree(dir_path)
def process(self, input_path, task_options, output_path): def process(self, input_path, task_options, output_path):
"""Called for each request made to the worker. """Called for each request made to the worker.
...@@ -291,7 +311,8 @@ class ArchiveExtractor(nlp_ws.NLPWorker): ...@@ -291,7 +311,8 @@ class ArchiveExtractor(nlp_ws.NLPWorker):
if not is_zipfile(input_path): if not is_zipfile(input_path):
raise Exception("Input is not a zip archive") raise Exception("Input is not a zip archive")
dir_path = output_path dir_path = os.path.join(output_path, 'result')
os.mkdir(dir_path)
self._unpack_zip(input_path, dir_path) self._unpack_zip(input_path, dir_path)
files_to_remove, files_to_convert, input_size_sum = [], [], 0 files_to_remove, files_to_convert, input_size_sum = [], [], 0
input_size_report, error_report_before = {}, {member.value: [] input_size_report, error_report_before = {}, {member.value: []
...@@ -345,6 +366,9 @@ class ArchiveExtractor(nlp_ws.NLPWorker): ...@@ -345,6 +366,9 @@ class ArchiveExtractor(nlp_ws.NLPWorker):
f" {output_size_sum} is too large," f" {output_size_sum} is too large,"
f" max size is {self.output_max_size}") f" max size is {self.output_max_size}")
self._pack_result(output_path, dir_path)
self._safe_report(input_size_report, input_size_sum, output_size_report, self._safe_report(input_size_report, input_size_sum, output_size_report,
output_size_sum, error_report_before, output_size_sum, error_report_before,
error_report_after, files_to_convert, dir_path) error_report_after, files_to_convert, output_path,
dir_path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment