-
-
Notifications
You must be signed in to change notification settings - Fork 31
pdf-converter: stop conversion when Cancel is clicked in GUI #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/usr/bin/python3 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should be inside
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the test_client.py is now at qubespdfconverter/tests/test_client.py. |
||
|
|
||
| import asyncio | ||
| import signal | ||
| import unittest | ||
| from pathlib import Path | ||
| from unittest import mock | ||
|
|
||
| from qubespdfconverter.client import Job, PageError, run | ||
|
|
||
|
|
||
| class DummyProc: | ||
| def __init__(self): | ||
| self.returncode = None | ||
| self.terminated = False | ||
| self.stdin = mock.Mock() | ||
| self.stdout = mock.Mock() | ||
|
|
||
| def terminate(self): | ||
| self.terminated = True | ||
| self.returncode = -signal.SIGTERM | ||
|
|
||
| async def wait(self): | ||
| if self.returncode is None: | ||
| self.returncode = 0 | ||
|
|
||
|
|
||
| class TC_ClientCancel(unittest.IsolatedAsyncioTestCase): | ||
| async def test_000_cancel_terminates_qrexec_proc(self): | ||
| job = Job(Path("/tmp/test.pdf"), 0) | ||
| proc = DummyProc() | ||
|
|
||
| with mock.patch("asyncio.create_subprocess_exec", new=mock.AsyncMock(return_value=proc)): | ||
| job._setup = mock.AsyncMock() | ||
| job._start = mock.AsyncMock(side_effect=asyncio.CancelledError) | ||
|
|
||
| with self.assertRaises(asyncio.CancelledError): | ||
| await job.run(Path("/tmp/archive"), depth=1, in_place=False) | ||
|
|
||
| self.assertTrue(proc.terminated) | ||
|
|
||
| async def test_001_failure_terminates_qrexec_proc(self): | ||
| job = Job(Path("/tmp/test.pdf"), 0) | ||
| proc = DummyProc() | ||
|
|
||
| with mock.patch("asyncio.create_subprocess_exec", new=mock.AsyncMock(return_value=proc)): | ||
| job._setup = mock.AsyncMock(side_effect=PageError) | ||
|
|
||
| with self.assertRaises(PageError): | ||
| await job.run(Path("/tmp/archive"), depth=1, in_place=False) | ||
|
|
||
| self.assertTrue(proc.terminated) | ||
|
|
||
| async def test_002_register_sigterm_handler(self): | ||
| loop = asyncio.get_running_loop() | ||
| add_handler_mock = mock.Mock() | ||
|
|
||
| with mock.patch.object(loop, "add_signal_handler", new=add_handler_mock): | ||
| result = await run({ | ||
| "resolution": 300, | ||
| "files": [], | ||
| "archive": Path("/tmp/archive"), | ||
| "batch": 1, | ||
| "in_place": False, | ||
| }) | ||
|
|
||
| self.assertFalse(result) | ||
| handled = {call.args[0] for call in add_handler_mock.mock_calls} | ||
| self.assertEqual(handled, {signal.SIGINT, signal.SIGTERM}) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,29 @@ | |
| # | ||
| # | ||
|
|
||
| set -u | ||
|
|
||
| if [ $# -ne 1 ]; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| export PROGRESS_FOR_GUI="yes" | ||
|
|
||
| /usr/bin/qvm-convert-pdf "$@" | zenity --progress --text="Converting PDF using Disposable VM..." --auto-close --auto-kill | ||
| fifo="$(mktemp -u)" | ||
| mkfifo "$fifo" || exit 1 | ||
|
|
||
| /usr/bin/qvm-convert-pdf "$@" >"$fifo" & | ||
| converter_pid="$!" | ||
|
|
||
| zenity --progress --text="Converting PDF using Disposable VM..." --auto-close <"$fifo" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zenity is not declared as a dependency for all supported distros: https://github.com/search?q=repo%3AQubesOS%2Fqubes-app-linux-pdf-converter%20zenity&type=code t would be nice to have it in a separate commit.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, "recommends" instead of "depends", to not require zenity on minimal system that wants to be a client of pdf conversion. |
||
| zenity_rc="$?" | ||
|
|
||
| rm -f -- "$fifo" | ||
|
|
||
| if [ "$zenity_rc" -ne 0 ]; then | ||
| kill "$converter_pid" | ||
| wait "$converter_pid" | ||
| exit 1 | ||
| fi | ||
|
|
||
| wait "$converter_pid" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And same in rpm_spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added Recommends: zenity to rpm_spec/qpdf-converter.spec.in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two specs in that directory.