From 8fffc9dc8e5dd930785ef00e58000e5b1b2afd25 Mon Sep 17 00:00:00 2001 From: Nitroretro Date: Tue, 28 Apr 2020 23:10:25 +0300 Subject: calcurse-caldav: Ensure config and data dirs exist Fixes #283. Signed-off-by: Lukas Fleischer --- contrib/caldav/calcurse-caldav.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'contrib') diff --git a/contrib/caldav/calcurse-caldav.py b/contrib/caldav/calcurse-caldav.py index cb777d8..7c9b89b 100755 --- a/contrib/caldav/calcurse-caldav.py +++ b/contrib/caldav/calcurse-caldav.py @@ -522,20 +522,28 @@ nsmap = {"D": "DAV:", "C": "urn:ietf:params:xml:ns:caldav"} # Initialize default values. if os.path.isdir(os.path.expanduser("~/.calcurse")): - configfn = os.path.expanduser("~/.calcurse/caldav/config") - lockfn = os.path.expanduser("~/.calcurse/caldav/lock") - syncdbfn = os.path.expanduser("~/.calcurse/caldav/sync.db") - hookdir = os.path.expanduser("~/.calcurse/caldav/hooks/") - oauth_file = os.path.expanduser("~/.calcurse/caldav/oauth2_cred") + caldav_path = os.path.expanduser("~/.calcurse/caldav") + check_dir(caldav_path) + + configfn = os.path.join(caldav_path, "config") + hookdir = os.path.join(caldav_path, "hooks") + oauth_file = os.path.join(caldav_path, "oauth2_cred") + lockfn = os.path.join(caldav_path, "lock") + syncdbfn = os.path.join(caldav_path, "sync.db") else: - calcurse_data = os.getenv("XDG_DATA_HOME", os.path.expanduser("~/.local/share")) + "/calcurse" - calcurse_config = os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config")) + "/calcurse" - - configfn = os.path.expanduser(calcurse_config + "/caldav/config") - lockfn = os.path.expanduser(calcurse_data + "/caldav/lock") - syncdbfn = os.path.expanduser(calcurse_data + "/caldav/sync.db") - hookdir = os.path.expanduser(calcurse_config + "/caldav/hooks/") - oauth_file = os.path.expanduser(calcurse_config + "/caldav/oauth2_cred") + xdg_config_home = os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config")) + xdg_data_home = os.getenv("XDG_DATA_HOME", os.path.expanduser("~/.local/share")) + caldav_config = os.path.join(xdg_config_home, "calcurse", "caldav") + caldav_data = os.path.join(xdg_data_home, "calcurse", "caldav") + check_dir(caldav_config) + check_dir(caldav_data) + + configfn = os.path.join(caldav_config, "config") + hookdir = os.path.join(caldav_config, "hooks") + oauth_file = os.path.join(caldav_config, "oauth2_cred") + + lockfn = os.path.join(caldav_data, "lock") + syncdbfn = os.path.join(caldav_data, "sync.db") # Parse command line arguments. parser = argparse.ArgumentParser('calcurse-caldav') -- cgit v1.2.3-70-g09d2