aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2019-10-24 14:57:19 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2019-10-24 14:57:19 +0100
commit61807b2ce2d1d4c70016a114c77a8fe5da9fbcdb (patch)
tree49fd6c19b175d9973986bf908e1feca65c5eabd9
parentMove upload functionality to utils (diff)
downloadpaper2remarkable-61807b2ce2d1d4c70016a114c77a8fe5da9fbcdb.tar.gz
paper2remarkable-61807b2ce2d1d4c70016a114c77a8fe5da9fbcdb.zip
Minor fixes to check_file_is_pdf
-rw-r--r--paper2remarkable/providers/_base.py2
-rw-r--r--paper2remarkable/utils.py6
2 files changed, 6 insertions, 2 deletions
diff --git a/paper2remarkable/providers/_base.py b/paper2remarkable/providers/_base.py
index 85415a9..f703874 100644
--- a/paper2remarkable/providers/_base.py
+++ b/paper2remarkable/providers/_base.py
@@ -199,7 +199,7 @@ class Provider(metaclass=abc.ABCMeta):
with tempfile.TemporaryDirectory(prefix="a2r_") as working_dir:
os.chdir(working_dir)
self.retrieve_pdf(src, tmp_filename)
- self.check_file_is_pdf(tmp_filename)
+ check_file_is_pdf(tmp_filename)
intermediate_fname = tmp_filename
for op in self.operations:
diff --git a/paper2remarkable/utils.py b/paper2remarkable/utils.py
index 26b024e..110453b 100644
--- a/paper2remarkable/utils.py
+++ b/paper2remarkable/utils.py
@@ -29,6 +29,10 @@ def exception(msg):
def check_file_is_pdf(filename):
+ """Check that a given file is a PDF file.
+
+ This is done by trying to open it using PyPDF2.
+ """
try:
fp = open(filename, "rb")
pdf = PyPDF2.PdfFileReader(fp, strict=False)
@@ -36,7 +40,7 @@ def check_file_is_pdf(filename):
del pdf
return True
except PyPDF2.utils.PdfReadError:
- exception("Downloaded file isn't a valid pdf file.")
+ exception("File %s isn't a valid pdf file." % filename)
def upload_to_remarkable(filepath, remarkable_dir="/", rmapi_path="rmapi"):