From aa21dbbaeefa29183a6e0e5933fb06ab41450d8d Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 21 Feb 2020 16:24:13 +0000 Subject: Bugfix for creating nested directories Turns out rMapi doesn't support the equivalent of mkdir -p, so we do it ourselves. --- paper2remarkable/utils.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/paper2remarkable/utils.py b/paper2remarkable/utils.py index 22d6d38..859ce6c 100644 --- a/paper2remarkable/utils.py +++ b/paper2remarkable/utils.py @@ -133,13 +133,18 @@ def upload_to_remarkable(filepath, remarkable_dir="/", rmapi_path="rmapi"): # Create the reMarkable dir if it doesn't exist remarkable_dir = remarkable_dir.rstrip("/") if remarkable_dir: - status = subprocess.call( - [rmapi_path, "mkdir", remarkable_dir], stdout=subprocess.DEVNULL, - ) - if not status == 0: - raise RemarkableError( - "Creating directory %s on reMarkable failed" % remarkable_dir + parts = remarkable_dir.split("/") + rmdir = "" + while parts: + rmdir += "/" + parts.pop(0) + status = subprocess.call( + [rmapi_path, "mkdir", rmdir], stdout=subprocess.DEVNULL, ) + if not status == 0: + raise RemarkableError( + "Creating directory %s on reMarkable failed" + % remarkable_dir + ) # Upload the file status = subprocess.call( -- cgit v1.2.3 From 806f22a6245c6379df0fb72255b08b8d1850eb71 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 21 Feb 2020 16:24:19 +0000 Subject: Code formatting --- paper2remarkable/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/paper2remarkable/utils.py b/paper2remarkable/utils.py index 859ce6c..592dcd3 100644 --- a/paper2remarkable/utils.py +++ b/paper2remarkable/utils.py @@ -94,8 +94,9 @@ def get_content_type_with_retry(url, tries=5, cookiejar=None): count += 1 error = False try: - res = requests.head(url, headers=HEADERS, cookies=jar, - allow_redirects=True) + res = requests.head( + url, headers=HEADERS, cookies=jar, allow_redirects=True + ) except requests.exceptions.ConnectionError: error = True if error or not res.ok: -- cgit v1.2.3