aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2020-02-21 16:24:13 +0000
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2020-02-21 16:24:13 +0000
commitaa21dbbaeefa29183a6e0e5933fb06ab41450d8d (patch)
tree28c057413dc09163c7cc181d2d6b783507b4d9f4
parentReadme update (diff)
downloadpaper2remarkable-aa21dbbaeefa29183a6e0e5933fb06ab41450d8d.tar.gz
paper2remarkable-aa21dbbaeefa29183a6e0e5933fb06ab41450d8d.zip
Bugfix for creating nested directories
Turns out rMapi doesn't support the equivalent of mkdir -p, so we do it ourselves.
-rw-r--r--paper2remarkable/utils.py17
1 files 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(