Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/subprocess-timeouts' into develop
[SVCS-683] Closes: #332
- Loading branch information
Showing
5 changed files
with
81 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
import os | ||
import subprocess | ||
from http import HTTPStatus | ||
from os.path import basename, splitext | ||
from subprocess import run, CalledProcessError | ||
|
||
from mfr.core import extension | ||
from mfr.core import exceptions | ||
from mfr.core.extension import BaseExporter | ||
from mfr.core.exceptions import SubprocessError | ||
from mfr.extensions.unoconv.settings import (PORT, | ||
ADDRESS, | ||
UNOCONV_BIN, | ||
UNOCONV_TIMEOUT) | ||
|
||
from mfr.extensions.unoconv import settings | ||
|
||
|
||
class UnoconvExporter(extension.BaseExporter): | ||
class UnoconvExporter(BaseExporter): | ||
|
||
def export(self): | ||
try: | ||
subprocess.run([ | ||
settings.UNOCONV_BIN, | ||
run([ | ||
UNOCONV_BIN, | ||
'-n', | ||
'-c', 'socket,host={},port={};urp;StarOffice.ComponentContext'.format(settings.ADDRESS, settings.PORT), | ||
'-c', 'socket,host={},port={};urp;StarOffice.ComponentContext'.format(ADDRESS, PORT), | ||
'-f', self.format, | ||
'-o', self.output_file_path, | ||
'-vvv', | ||
self.source_file_path | ||
], check=True, timeout=settings.UNOCONV_TIMEOUT) | ||
|
||
except subprocess.CalledProcessError as err: | ||
name, extension = os.path.splitext(os.path.split(self.source_file_path)[-1]) | ||
raise exceptions.SubprocessError( | ||
], check=True, timeout=UNOCONV_TIMEOUT) | ||
except CalledProcessError as err: | ||
name, extension = splitext(basename(self.source_file_path)) | ||
raise SubprocessError( | ||
'Unable to export the file in the requested format, please try again later.', | ||
process='unoconv', | ||
cmd=str(err.cmd), | ||
returncode=err.returncode, | ||
path=str(self.source_file_path), | ||
code=400, | ||
code=HTTPStatus.BAD_REQUEST, | ||
extension=extension or '', | ||
exporter_class='unoconv', | ||
) |