calcurse-caldav: Add SyncFilter config option

The SyncFilter option filters the types of items synced from/to a CalDAV
server by making use of the --filter-type command line argument.

Signed-off-by: Satvik Sharma <satvik.sharma2@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Satvik Sharma 2017-10-25 11:52:22 +11:00 committed by Lukas Fleischer
parent 2fa1511898
commit b96e175192
3 changed files with 53 additions and 12 deletions

View File

@ -108,6 +108,7 @@ The following options should also be changed in your config file:
Hostname = apidata.googleusercontent.com Hostname = apidata.googleusercontent.com
Path = /caldav/v2/*your_calendar_id_here*/events/ Path = /caldav/v2/*your_calendar_id_here*/events/
Scope = https://www.googleapis.com/auth/calendar Scope = https://www.googleapis.com/auth/calendar
SyncFilter = cal
``` ```
Your Calendar ID for "*Path*" should be your email for the default calendar. Your Calendar ID for "*Path*" should be your email for the default calendar.
@ -127,6 +128,7 @@ A complete config file for example@gmail.com would have the following options:
Hostname = apidata.googleusercontent.com Hostname = apidata.googleusercontent.com
Path = /caldav/v2/example@gmail.com/events/ Path = /caldav/v2/example@gmail.com/events/
AuthMethod = oauth2 AuthMethod = oauth2
SyncFilter = cal
... ...

View File

@ -44,6 +44,11 @@ def die_atnode(msg, node):
die(msg) die(msg)
def validate_sync_filter():
valid_sync_filter_values = {'event', 'apt', 'recur-event', 'recur-apt', 'todo', 'recur', 'cal'}
return set(sync_filter.split(',')) - valid_sync_filter_values
def calcurse_wipe(): def calcurse_wipe():
if verbose: if verbose:
print('Removing all local calcurse objects...') print('Removing all local calcurse objects...')
@ -53,13 +58,20 @@ def calcurse_wipe():
def calcurse_import(icaldata): def calcurse_import(icaldata):
p = subprocess.Popen([calcurse, '-i', '-', '--dump-imported', '-q', command = [
'--format-apt=%(hash)\\n', calcurse,
'--format-recur-apt=%(hash)\\n', '-i', '-',
'--format-event=%(hash)\\n', '--dump-imported',
'--format-recur-event=%(hash)\\n', '-q',
'--format-todo=%(hash)\\n'], '--filter-type', sync_filter,
stdin=subprocess.PIPE, stdout=subprocess.PIPE) '--format-apt=%(hash)\\n',
'--format-recur-apt=%(hash)\\n',
'--format-event=%(hash)\\n',
'--format-recur-event=%(hash)\\n',
'--format-todo=%(hash)\\n'
]
p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
return p.communicate(icaldata.encode('utf-8'))[0].decode('utf-8').rstrip() return p.communicate(icaldata.encode('utf-8'))[0].decode('utf-8').rstrip()
@ -70,11 +82,18 @@ def calcurse_export(objhash):
def calcurse_hashset(): def calcurse_hashset():
p = subprocess.Popen([calcurse, '-G', '--format-apt=%(hash)\\n', command = [
'--format-recur-apt=%(hash)\\n', calcurse,
'--format-event=%(hash)\\n', '-G',
'--format-recur-event=%(hash)\\n', '--filter-type', sync_filter,
'--format-todo=%(hash)\\n'], stdout=subprocess.PIPE) '--format-apt=%(hash)\\n',
'--format-recur-apt=%(hash)\\n',
'--format-event=%(hash)\\n',
'--format-recur-event=%(hash)\\n',
'--format-todo=%(hash)\\n'
]
p = subprocess.Popen(command, stdout=subprocess.PIPE)
return set(p.communicate()[0].decode('utf-8').rstrip().splitlines()) return set(p.communicate()[0].decode('utf-8').rstrip().splitlines())
@ -533,6 +552,16 @@ if config.has_option('General', 'AuthMethod'):
else: else:
authmethod = 'basic' authmethod = 'basic'
if config.has_option('General', 'SyncFilter'):
sync_filter = config.get('General', 'SyncFilter')
invalid_filter_values = validate_sync_filter()
if len(invalid_filter_values):
die('Invalid value(s) in SyncFilter option: ' + ', '.join(invalid_filter_values))
else:
sync_filter = 'cal,todo'
if config.has_option('Auth', 'UserName'): if config.has_option('Auth', 'UserName'):
username = config.get('Auth', 'UserName') username = config.get('Auth', 'UserName')
else: else:

View File

@ -18,6 +18,16 @@ Path = /path/to/calendar/on/the/server/
# Enable this if you want to skip SSL certificate checks. # Enable this if you want to skip SSL certificate checks.
InsecureSSL = No InsecureSSL = No
# This option allows you to filter the types of tasks synced. To this end, the
# value of this option should be a comma-separated list of item types, where
# each item type is either "event", "apt", "recur-event", "recur-apt", "todo",
# "recur" or "cal". Note that the comma-separated list must not contain any
# spaces. Refer to the documentation of the --filter-type command line argument
# of calcurse for more details. Set this option to "cal" if the configured
# CalDAV server doesn't support tasks, such as is the case with Google
# Calendar.
SyncFilter = cal,todo
# Disable this option to actually enable synchronization. If it is enabled, # Disable this option to actually enable synchronization. If it is enabled,
# nothing is actually written to the server or to the local data files. If you # nothing is actually written to the server or to the local data files. If you
# combine DryRun = Yes with Verbose = Yes, you get a log of what would have # combine DryRun = Yes with Verbose = Yes, you get a log of what would have