calcurse-caldav: Use -G and %(hash) to list hashes

Instead of reimplementing the code to generate object hashes in the
synchronization script, use format strings to print the hashes in grep
mode.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lukas Fleischer 2016-02-05 18:21:27 +01:00
parent 4ada3deda2
commit 812c6b1dd6

View File

@ -3,7 +3,6 @@
import argparse import argparse
import base64 import base64
import configparser import configparser
import hashlib
import http.client import http.client
import os import os
import re import re
@ -58,17 +57,12 @@ def calcurse_export(objhash):
def calcurse_hashset(): def calcurse_hashset():
p = subprocess.Popen([calcurse, '-G'], stdout=subprocess.PIPE) p = subprocess.Popen([calcurse, '-G', '--format-apt=%(hash)\\n',
out = p.communicate()[0] '--format-recur-apt=%(hash)\\n',
'--format-event=%(hash)\\n',
hashes = set() '--format-recur-event=%(hash)\\n',
for line in out.split(b'\n'): '--format-todo=%(hash)\\n'], stdout=subprocess.PIPE)
if not line: return set(p.communicate()[0].decode('utf-8').rstrip().splitlines())
continue
sha1 = hashlib.new('sha1')
sha1.update(line)
hashes.add(sha1.hexdigest())
return hashes
def calcurse_remove(objhash): def calcurse_remove(objhash):
@ -451,7 +445,7 @@ ver = calcurse_version()
if ver is None: if ver is None:
die('Invalid calcurse binary. Make sure that the file specified in ' + die('Invalid calcurse binary. Make sure that the file specified in ' +
'the configuration is a valid and up-to-date calcurse binary.') 'the configuration is a valid and up-to-date calcurse binary.')
elif ver < (4, 0, 0, 73): elif ver < (4, 0, 0, 96):
die('Incompatible calcurse binary detected. Version >=4.1.0 is required ' + die('Incompatible calcurse binary detected. Version >=4.1.0 is required ' +
'to synchronize with CalDAV servers.') 'to synchronize with CalDAV servers.')