aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2020-04-15 11:13:37 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2020-04-15 11:13:37 +0100
commit3a79f9368a1d73db1eeedfe8e3966e6ebbf6c10b (patch)
tree0a06bd64c226238bd14f80b19df2a8c67eafcc67
parentremove unnecessary logging (diff)
parentProperly check for the installed pdf tool (diff)
downloadpaper2remarkable-3a79f9368a1d73db1eeedfe8e3966e6ebbf6c10b.tar.gz
paper2remarkable-3a79f9368a1d73db1eeedfe8e3966e6ebbf6c10b.zip
Merge branch 'bugfix/detect_pdftool'
-rw-r--r--paper2remarkable/utils.py14
-rw-r--r--tests/test_utils.py21
2 files changed, 31 insertions, 4 deletions
diff --git a/paper2remarkable/utils.py b/paper2remarkable/utils.py
index cca904b..791e81a 100644
--- a/paper2remarkable/utils.py
+++ b/paper2remarkable/utils.py
@@ -175,16 +175,22 @@ def check_pdftool(pdftk_path, qpdf_path):
pdftk_path = pdftk_path or "false"
qpdf_path = qpdf_path or "false"
- status = subprocess.call(
- [pdftk_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
- )
+ try:
+ status = subprocess.call(
+ [pdftk_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
+ )
+ except FileNotFoundError:
+ status = 1
if status == 0:
return "pdftk"
- status = subprocess.call(
+ try:
+ status = subprocess.call(
[qpdf_path, "--help"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
+ except FileNotFoundError:
+ status = 1
if status == 0:
return "qpdf"
raise NoPDFToolError
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644
index 0000000..4c122e0
--- /dev/null
+++ b/tests/test_utils.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+
+from paper2remarkable.exceptions import NoPDFToolError
+from paper2remarkable.utils import check_pdftool
+
+
+class TestUtils(unittest.TestCase):
+ def test_check_pdftool(self):
+ # Needs a system with both pdftk and qpdf available
+ self.assertEqual(check_pdftool("pdftk", "qpdf"), "pdftk")
+ self.assertEqual(check_pdftool("pdftk_xyz", "qpdf"), "qpdf")
+ self.assertEqual(check_pdftool("pdftk", "qpdf_xyz"), "pdftk")
+ with self.assertRaises(NoPDFToolError):
+ check_pdftool("pdftk_xyz", "qpdf_xyz")
+
+
+if __name__ == "__main__":
+ unittest.main()