mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
isolation_provider: Pass doc when creating doc-to-pixels proc
Pass the Document instance that will be converted to the `IsolationProvider.start_doc_to_pixels_proc()` method. Concrete classes can then associate this name with the started process, so that they can later on kill it.
This commit is contained in:
parent
b920de36d1
commit
6850d31edc
5 changed files with 13 additions and 11 deletions
|
@ -69,7 +69,7 @@ class IsolationProvider(ABC):
|
||||||
self.progress_callback = progress_callback
|
self.progress_callback = progress_callback
|
||||||
document.mark_as_converting()
|
document.mark_as_converting()
|
||||||
try:
|
try:
|
||||||
conversion_proc = self.start_doc_to_pixels_proc()
|
conversion_proc = self.start_doc_to_pixels_proc(document)
|
||||||
with tempfile.TemporaryDirectory() as t:
|
with tempfile.TemporaryDirectory() as t:
|
||||||
Path(f"{t}/pixels").mkdir()
|
Path(f"{t}/pixels").mkdir()
|
||||||
self.doc_to_pixels(document, t, conversion_proc)
|
self.doc_to_pixels(document, t, conversion_proc)
|
||||||
|
@ -192,7 +192,7 @@ class IsolationProvider(ABC):
|
||||||
return armor_start + conversion_string + armor_end
|
return armor_start + conversion_string + armor_end
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def start_doc_to_pixels_proc(self) -> subprocess.Popen:
|
def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -251,7 +251,7 @@ class Container(IsolationProvider):
|
||||||
)
|
)
|
||||||
shutil.move(container_output_filename, document.output_filename)
|
shutil.move(container_output_filename, document.output_filename)
|
||||||
|
|
||||||
def start_doc_to_pixels_proc(self) -> subprocess.Popen:
|
def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
|
||||||
# Convert document to pixels
|
# Convert document to pixels
|
||||||
command = [
|
command = [
|
||||||
"/usr/bin/python3",
|
"/usr/bin/python3",
|
||||||
|
|
|
@ -74,7 +74,7 @@ class Dummy(IsolationProvider):
|
||||||
) -> None:
|
) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start_doc_to_pixels_proc(self) -> subprocess.Popen:
|
def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
|
||||||
return subprocess.Popen("True")
|
return subprocess.Popen("True")
|
||||||
|
|
||||||
def get_max_parallel_conversions(self) -> int:
|
def get_max_parallel_conversions(self) -> int:
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Qubes(IsolationProvider):
|
||||||
def get_max_parallel_conversions(self) -> int:
|
def get_max_parallel_conversions(self) -> int:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def start_doc_to_pixels_proc(self) -> subprocess.Popen:
|
def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
|
||||||
dev_mode = getattr(sys, "dangerzone_dev", False) == True
|
dev_mode = getattr(sys, "dangerzone_dev", False) == True
|
||||||
if dev_mode:
|
if dev_mode:
|
||||||
# Use dz.ConvertDev RPC call instead, if we are in development mode.
|
# Use dz.ConvertDev RPC call instead, if we are in development mode.
|
||||||
|
|
|
@ -37,7 +37,7 @@ class IsolationProviderTest:
|
||||||
provider.progress_callback = mocker.MagicMock()
|
provider.progress_callback = mocker.MagicMock()
|
||||||
doc = Document(pdf_11k_pages)
|
doc = Document(pdf_11k_pages)
|
||||||
|
|
||||||
p = provider.start_doc_to_pixels_proc()
|
p = provider.start_doc_to_pixels_proc(doc)
|
||||||
with pytest.raises(errors.ConverterProcException):
|
with pytest.raises(errors.ConverterProcException):
|
||||||
provider.doc_to_pixels(doc, tmpdir, p)
|
provider.doc_to_pixels(doc, tmpdir, p)
|
||||||
assert provider.get_proc_exception(p) == errors.MaxPagesException
|
assert provider.get_proc_exception(p) == errors.MaxPagesException
|
||||||
|
@ -54,7 +54,7 @@ class IsolationProviderTest:
|
||||||
"dangerzone.conversion.errors.MAX_PAGES", 1
|
"dangerzone.conversion.errors.MAX_PAGES", 1
|
||||||
) # sample_doc has 4 pages > 1
|
) # sample_doc has 4 pages > 1
|
||||||
doc = Document(sample_doc)
|
doc = Document(sample_doc)
|
||||||
p = provider.start_doc_to_pixels_proc()
|
p = provider.start_doc_to_pixels_proc(doc)
|
||||||
with pytest.raises(errors.MaxPagesException):
|
with pytest.raises(errors.MaxPagesException):
|
||||||
provider.doc_to_pixels(doc, tmpdir, p)
|
provider.doc_to_pixels(doc, tmpdir, p)
|
||||||
|
|
||||||
|
@ -67,10 +67,12 @@ class IsolationProviderTest:
|
||||||
tmpdir: str,
|
tmpdir: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
provider.progress_callback = mocker.MagicMock()
|
provider.progress_callback = mocker.MagicMock()
|
||||||
p = provider.start_doc_to_pixels_proc()
|
doc = Document(sample_bad_width)
|
||||||
|
p = provider.start_doc_to_pixels_proc(doc)
|
||||||
with pytest.raises(errors.MaxPageWidthException):
|
with pytest.raises(errors.MaxPageWidthException):
|
||||||
provider.doc_to_pixels(Document(sample_bad_width), tmpdir, p)
|
provider.doc_to_pixels(doc, tmpdir, p)
|
||||||
|
|
||||||
p = provider.start_doc_to_pixels_proc()
|
doc = Document(sample_bad_height)
|
||||||
|
p = provider.start_doc_to_pixels_proc(doc)
|
||||||
with pytest.raises(errors.MaxPageHeightException):
|
with pytest.raises(errors.MaxPageHeightException):
|
||||||
provider.doc_to_pixels(Document(sample_bad_height), tmpdir, p)
|
provider.doc_to_pixels(doc, tmpdir, p)
|
||||||
|
|
Loading…
Reference in a new issue