diff options
Diffstat (limited to 'contrib/caldav/calcurse-caldav.py')
-rwxr-xr-x | contrib/caldav/calcurse-caldav.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/contrib/caldav/calcurse-caldav.py b/contrib/caldav/calcurse-caldav.py index 3f57fdf..5efd306 100755 --- a/contrib/caldav/calcurse-caldav.py +++ b/contrib/caldav/calcurse-caldav.py @@ -6,6 +6,7 @@ import configparser import os import pathlib import re +import shlex import subprocess import sys import textwrap @@ -30,6 +31,7 @@ class Config: self._map = { 'Auth': { 'Password': None, + 'PasswordCommand': None, 'Username': None, }, 'CustomHeaders': {}, @@ -75,7 +77,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 @@ -657,9 +659,6 @@ verbose = args.verbose debug = args.debug debug_raw = args.debug_raw -# Read environment variables -password = os.getenv('CALCURSE_CALDAV_PASSWORD') - # Read configuration. config = Config(configfn) @@ -674,7 +673,18 @@ path = config.get('General', 'Path') sync_filter = config.get('General', 'SyncFilter') verbose = verbose or config.get('General', 'Verbose') -password = password or config.get('Auth', 'Password') +if os.getenv('CALCURSE_CALDAV_PASSWORD'): + # This approach is deprecated, but preserved for backwards compatibility + password = os.getenv('CALCURSE_CALDAV_PASSWORD') +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').rstrip('\n') +else: + password = None + username = config.get('Auth', 'Username') client_id = config.get('OAuth2', 'ClientID') @@ -733,9 +743,7 @@ try: # Connect to the server. if verbose: print('Connecting to ' + hostname + '...') - conn = httplib2.Http() - if insecure_ssl: - conn.disable_ssl_certificate_validation = True + conn = httplib2.Http(disable_ssl_certificate_validation=insecure_ssl) if authmethod == 'oauth2': # Authenticate with OAuth2 and authorize HTTP object |