calcurse-caldav: add custom data directory support

Added the --datadir flag to calcurse-caldav which enables to specify a
custom calcurse data directory similarly to the -D flag in calcurse.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
vxid 2019-03-05 10:54:23 +01:00 committed by Lukas Fleischer
parent 528368932c
commit ccdd3391f3

View File

@ -36,6 +36,11 @@ def die(msg):
sys.exit(msgfmt(msg, "error: ")) sys.exit(msgfmt(msg, "error: "))
def check_dir(dir):
if not os.path.isdir(dir):
die("invalid directory: {0}".format(dir))
def die_atnode(msg, node): def die_atnode(msg, node):
if debug: if debug:
msg += '\n\n' msg += '\n\n'
@ -55,7 +60,7 @@ def calcurse_wipe():
if dry_run: if dry_run:
return return
command = [calcurse, '-F', '--filter-hash=XXX'] command = calcurse + ['-F', '--filter-hash=XXX']
if debug: if debug:
print('Running command: {}'.format(command)) print('Running command: {}'.format(command))
@ -64,8 +69,7 @@ def calcurse_wipe():
def calcurse_import(icaldata): def calcurse_import(icaldata):
command = [ command = calcurse + [
calcurse,
'-i', '-', '-i', '-',
'--dump-imported', '--dump-imported',
'-q', '-q',
@ -84,8 +88,7 @@ def calcurse_import(icaldata):
def calcurse_export(objhash): def calcurse_export(objhash):
command = [ command = calcurse + [
calcurse,
'-xical', '-xical',
'--export-uid', '--export-uid',
'--filter-hash=' + objhash '--filter-hash=' + objhash
@ -99,8 +102,7 @@ def calcurse_export(objhash):
def calcurse_hashset(): def calcurse_hashset():
command = [ command = calcurse + [
calcurse,
'-G', '-G',
'--filter-type', sync_filter, '--filter-type', sync_filter,
'--format-apt=%(hash)\\n', '--format-apt=%(hash)\\n',
@ -118,7 +120,7 @@ def calcurse_hashset():
def calcurse_remove(objhash): def calcurse_remove(objhash):
command = [calcurse, '-F', '--filter-hash=!' + objhash] command = calcurse + ['-F', '--filter-hash=!' + objhash]
if debug: if debug:
print('Running command: {}'.format(command)) print('Running command: {}'.format(command))
@ -127,7 +129,7 @@ def calcurse_remove(objhash):
def calcurse_version(): def calcurse_version():
command = [calcurse, '--version'] command = calcurse + ['--version']
if debug: if debug:
print('Running command: {}'.format(command)) print('Running command: {}'.format(command))
@ -521,6 +523,9 @@ parser.add_argument('--init', action='store', dest='init', default=None,
parser.add_argument('--config', action='store', dest='configfn', parser.add_argument('--config', action='store', dest='configfn',
default=configfn, default=configfn,
help='path to the calcurse-caldav configuration') help='path to the calcurse-caldav configuration')
parser.add_argument('--datadir', action='store', dest='datadir',
default=None,
help='path to the calcurse data directory')
parser.add_argument('--lockfile', action='store', dest='lockfn', parser.add_argument('--lockfile', action='store', dest='lockfn',
default=lockfn, default=lockfn,
help='path to the calcurse-caldav lock file') help='path to the calcurse-caldav lock file')
@ -546,6 +551,7 @@ init = args.init is not None
configfn = args.configfn configfn = args.configfn
lockfn = args.lockfn lockfn = args.lockfn
syncdbfn = args.syncdbfn syncdbfn = args.syncdbfn
datadir = args.datadir
hookdir = args.hookdir hookdir = args.hookdir
authcode = args.authcode authcode = args.authcode
verbose = args.verbose verbose = args.verbose
@ -576,9 +582,13 @@ else:
https = True https = True
if config.has_option('General', 'Binary'): if config.has_option('General', 'Binary'):
calcurse = config.get('General', 'Binary') calcurse = [config.get('General', 'Binary')]
else: else:
calcurse = 'calcurse' calcurse = ['calcurse']
if datadir:
check_dir(datadir)
calcurse += ['-D', datadir]
if config.has_option('General', 'DryRun'): if config.has_option('General', 'DryRun'):
dry_run = config.getboolean('General', 'DryRun') dry_run = config.getboolean('General', 'DryRun')