From 9fb532abe4f55db654863ca3fa7bf877f4990875 Mon Sep 17 00:00:00 2001 From: Nitroretro Date: Tue, 28 Apr 2020 23:07:07 +0300 Subject: calcurse-caldav: Make check_dir create directories This patch makes check_dir(dir) create directories if they don't exist, and it will fail if the path at dir is not a directory. It acts in a similar fashion to io_check_dir from io.c. Signed-off-by: Lukas Fleischer --- contrib/caldav/calcurse-caldav.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'contrib/caldav') diff --git a/contrib/caldav/calcurse-caldav.py b/contrib/caldav/calcurse-caldav.py index beea376..cb777d8 100755 --- a/contrib/caldav/calcurse-caldav.py +++ b/contrib/caldav/calcurse-caldav.py @@ -4,6 +4,7 @@ import argparse import base64 import configparser import httplib2 +import pathlib import os import re import subprocess @@ -37,9 +38,10 @@ def die(msg): def check_dir(dir): - if not os.path.isdir(dir): - die("invalid directory: {0}".format(dir)) - + try: + pathlib.Path(dir).mkdir(parents=True, exist_ok=True) + except FileExistsError: + die("{} is not a directory".format(dir)) def die_atnode(msg, node): if debug: -- cgit v1.2.3-70-g09d2