Browse Source

Try to handle folder name in path by creating the folder if needed.

Godzil 6 years ago
parent
commit
9f617bb409
1 changed files with 10 additions and 0 deletions
  1. 10 0
      nodemcu_uploader/uploader.py

+ 10 - 0
nodemcu_uploader/uploader.py

@@ -10,6 +10,7 @@ import time
 import logging
 import hashlib
 import os
+import errno
 import serial
 
 
@@ -246,6 +247,15 @@ class Uploader(object):
             destination = filename
         log.info('Transferring %s to %s', filename, destination)
         data = self.download_file(filename)
+
+        # Just in case, the filename may contain folder, so create it if needed.
+        log.info(destination)
+        if not os.path.exists(os.path.dirname(destination)):
+            try:
+                os.makedirs(os.path.dirname(destination))
+            except OSError as e:  # Guard against race condition
+                if e.errno != errno.EEXIST:
+                    raise
         with open(destination, 'w') as fil:
             fil.write(data)