create parent directories if they don't exist

This commit is contained in:
joshuaboud 2021-07-16 16:49:26 -03:00
parent a837129f0c
commit 913461feee
No known key found for this signature in database
GPG Key ID: 17EFB59E2A8BF50E
1 changed files with 6 additions and 0 deletions

View File

@ -34,6 +34,12 @@ import json
def write_chunk(chunk, file):
if not file:
path = sys.argv[1]
parent_path = os.path.dirname(path)
if not os.path.exists(parent_path):
os.makedirs(parent_path, exist_ok=True)
elif os.path.isfile(parent_path):
print(parent_path + ": exists and is not a directory.")
sys.exit(1)
try:
file = open(path, "wb")
except Exception as e: