diff options
Diffstat (limited to 'contrib/caldav')
-rw-r--r-- | contrib/caldav/README.md | 5 | ||||
-rwxr-xr-x | contrib/caldav/calcurse-caldav.py | 35 |
2 files changed, 23 insertions, 17 deletions
diff --git a/contrib/caldav/README.md b/contrib/caldav/README.md index b464dc9..cd2d718 100644 --- a/contrib/caldav/README.md +++ b/contrib/caldav/README.md @@ -113,14 +113,15 @@ to "set a product name on the consent screen", click on *Configure consent screen* to do so. Any product name will do. Upon saving and returning to the "Create client ID" screen, choose *Other* as the Application type and click *Create*. You now have your Client ID and Client Secret to put into your -calcurse-caldav config file! +calcurse-caldav config file! Use `https://www.googleapis.com/auth/calendar` for +the Scope field. The following options should also be changed in your config file: ``` Hostname = apidata.googleusercontent.com Path = /caldav/v2/*your_calendar_id_here*/events/ -Scope = https://www.googleapis.com/auth/calendar +AuthMethod = oauth2 SyncFilter = cal ``` diff --git a/contrib/caldav/calcurse-caldav.py b/contrib/caldav/calcurse-caldav.py index f9488e6..a88cda7 100755 --- a/contrib/caldav/calcurse-caldav.py +++ b/contrib/caldav/calcurse-caldav.py @@ -3,6 +3,7 @@ import argparse import base64 import configparser +import fcntl import os import pathlib import re @@ -77,7 +78,7 @@ class Config: for key, val in config.items(sec): if key not in self._map[sec]: die('Unexpected config key in section {}: {}'.format(sec, key)) - if type(self._map[sec][key]) == bool: + if isinstance(self._map[sec][key], bool): self._map[sec][key] = config.getboolean(sec, key) else: self._map[sec][key] = val @@ -248,7 +249,7 @@ def init_auth(client_id, client_secret, scope, redirect_uri, authcode): credentials = oauth2_client.step2_exchange(authcode) # Setup storage file and store credentials - storage = Storage(oauth_file) + storage = Storage(oauthfn) credentials.set_store(storage) storage.put(credentials) @@ -257,10 +258,10 @@ def init_auth(client_id, client_secret, scope, redirect_uri, authcode): def run_auth(authcode): # Check if credentials file exists - if os.path.isfile(oauth_file): + if os.path.isfile(oauthfn): # Retrieve token from file - storage = Storage(oauth_file) + storage = Storage(oauthfn) credentials = storage.get() # Set file to store it in for future functions @@ -598,7 +599,7 @@ if os.path.isdir(os.path.expanduser("~/.calcurse")): configfn = os.path.join(caldav_path, "config") hookdir = os.path.join(caldav_path, "hooks") - oauth_file = os.path.join(caldav_path, "oauth2_cred") + oauthfn = os.path.join(caldav_path, "oauth2_cred") lockfn = os.path.join(caldav_path, "lock") syncdbfn = os.path.join(caldav_path, "sync.db") else: @@ -611,7 +612,7 @@ else: configfn = os.path.join(caldav_config, "config") hookdir = os.path.join(caldav_config, "hooks") - oauth_file = os.path.join(caldav_config, "oauth2_cred") + oauthfn = os.path.join(caldav_config, "oauth2_cred") lockfn = os.path.join(caldav_data, "lock") syncdbfn = os.path.join(caldav_data, "sync.db") @@ -633,6 +634,9 @@ parser.add_argument('--lockfile', action='store', dest='lockfn', parser.add_argument('--syncdb', action='store', dest='syncdbfn', default=syncdbfn, help='path to the calcurse-caldav sync DB') +parser.add_argument('--oauthfile', action='store', dest='oauthfn', + default=oauthfn, + help='path to the OAuth2 credentials file') parser.add_argument('--hookdir', action='store', dest='hookdir', default=hookdir, help='path to the calcurse-caldav hooks directory') @@ -652,6 +656,7 @@ init = args.init is not None configfn = args.configfn lockfn = args.lockfn syncdbfn = args.syncdbfn +oauthfn = args.oauthfn datadir = args.datadir hookdir = args.hookdir authcode = args.authcode @@ -680,7 +685,8 @@ elif config.get('Auth', 'Password'): password = config.get('Auth', 'Password') elif config.get('Auth', 'PasswordCommand'): tokenized_cmd = shlex.split(config.get('Auth', 'PasswordCommand')) - password = subprocess.run(tokenized_cmd, capture_output=True).stdout.decode('UTF-8') + password = subprocess.run( + tokenized_cmd, capture_output=True).stdout.decode('UTF-8').rstrip('\n') else: password = None @@ -731,12 +737,12 @@ elif ver < (4, 0, 0, 96): # Run the pre-sync hook. run_hook('pre-sync') -# Create lock file. -if os.path.exists(lockfn): - die('Leftover lock file detected. If there is no other synchronization ' + - 'instance running, please remove the lock file manually and try ' + - 'again.') -open(lockfn, 'w') +# Obtain lock. +try: + lockfile = open(lockfn, 'w') + fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) +except OSError: + die('Another synchronization instance is already running.') try: # Connect to the server. @@ -810,8 +816,7 @@ try: conn.clear_credentials() finally: - # Remove lock file. - os.remove(lockfn) + pass # Run the post-sync hook. run_hook('post-sync') |