89 Commits

Author SHA1 Message Date
Lukas Fleischer
e70b41bda9 calcurse-caldav: Add debug output for sync DB operations
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-08 16:22:00 +01:00
Lukas Fleischer
9fdb714aea calcurse-caldav: Avoid empty multiget
When there are no new objects to pull from the server, skip the import
routine instead of sending a query that requests zero items.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-08 16:22:00 +01:00
Lukas Fleischer
7b5602ae17 calcurse-caldav: Split object addition and removal
Instead of performing two synchronization steps (push/pull), split the
synchronization protocol into four steps:

1. Retrieve new objects from the server.
2. Delete local objects that no longer exist on the server.
3. Push new objects to the server.
4. Delete remote objects that no longer exist locally.

Each of the steps is performed by a separate function.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-08 16:22:00 +01:00
Lukas Fleischer
b6f95b380f calcurse-caldav: Encode the request body in UTF-8
When a string is passed to HTTPConnection.request(), it is automatically
ISO 8859-1 encoded. Therefore, since we already specify UTF-8 as
character set in the headers, we need to UTF-8 encode the request body
manually.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-06-18 10:30:30 +02:00
Lukas Fleischer
2c9ea341cf Document the hooks feature
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-04-01 08:35:14 +02:00
Lukas Fleischer
07954626c6 Support format strings when dumping imported items
In commit 3eae7ce (Add --list-imported command line option, 2016-01-12),
we added an option to print the hashes of imported items to stdout.
Extend this command line option such that it dumps the items using the
specified formatting strings. With the new behavior it is, for example,
easier to check items for import errors.

Also, rename the option from --list-imported to --dump-imported (it is
not part of any official release yet so we do not need to care about
backwards compatibility).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-11 18:33:57 +01:00
Lukas Fleischer
a3b0c8eed2 Install calcurse-caldav by default
Add a new Makefile to build and install calcurse-caldav and include it
in the top-level build process.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-09 22:22:12 +01:00
Lukas Fleischer
4ab6e75aa9 Improve example hooks
The post-save and post-sync hooks now automatically detect whether the
data directory contains a .git/ directory and skip the commit creation
process if it does not.

The post-save hook and the new pre-load hook now also run
calcurse-caldav in the background if that script is available and the
data directory contains a caldav/ directory.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-08 08:17:49 +01:00
Lukas Fleischer
e7a83118ea Do not put all files under version control in example hooks
Modify the Git hooks such they only add known data files to the index.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-07 13:38:52 +01:00
Lukas Fleischer
e5ba06ff5d calcurse-caldav: Add hook support
Introduce pre-sync and post-sync hooks which need to be located under
~/.calcurse/caldav/hooks/ and are executed before/after synchronization
with a CalDAV server.

Also, add an example post-sync hook and change the example post-save
hook such that it does not create tiny commits during synchronization.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-07 13:29:44 +01:00
Lukas Fleischer
812c6b1dd6 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>
2016-02-05 19:12:12 +01:00
Lukas Fleischer
8bdf0c0b3b calcurse-caldav: Reword dry-run warning
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-02 08:16:08 +01:00
Lukas Fleischer
4671a02846 calcurse-caldav: Modernize format strings
Replace %-style string formatting with format().

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-01 19:11:27 +01:00
Lukas Fleischer
2cf7023b37 calcurse-caldav: Make synchronization more robust
In addition to storing ETag-hash tuples in the synchronization database,
also store the URI of each object. This makes the synchronization
process a bit more robust as we do not need to depend on ETags being
globally unique. It also allows us to detect conflicts which occur when
an object is modified locally and on the server at the same time.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-01 19:11:27 +01:00
Lukas Fleischer
cb85175524 calcurse-caldav: Fix issues reported by pylint
Add missing parameter to remote_query() and fix various style issues.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-01 19:05:27 +01:00
Lukas Fleischer
fb54b56cac calcurse-caldav: Fix version check
Since commit 41389ab (args.c: Revise help/usage/version output,
2016-01-28), the version string starts with "calcurse" (lowercase).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-28 19:30:29 +01:00
Lukas Fleischer
3dbfc7c1f5 calcurse-caldav: Use calendar-multiget to obtain ETag
Some CalDAV servers do not support calendar-query with a UID filter. Use
a calendar-multiget request to obtain the ETag of submitted objects
instead.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-26 17:33:49 +01:00
Lukas Fleischer
304ff81836 calcurse-caldav: Fix property filter
Fix a TypeError that occurred during string formatting by putting
parentheses around the multi-line string.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-26 15:31:50 +01:00
Lukas Fleischer
bfafec3ebf calcurse-caldav: Handle missing ETag gracefully
This was partly fixed by 475c341 (calcurse-caldav: Fix late retrieval of
ETag, 2016-01-25). However, the case where the server does not return
ETag after creating a new item still wasn't handled properly. This patch
hopefully addresses this and also makes sure that the ETag header is
matched case-insensitively.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 21:55:10 +01:00
Lukas Fleischer
4fff8ae4fe calcurse-caldav: Improve version check
Make sure that at least a current Git build of calcurse is used.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 21:02:30 +01:00
Lukas Fleischer
1a45713d1d calcurse-caldav: Print XML dump in debug mode only
In die_atnode(), we currently print a full dump of the XML node if
verbose mode is enabled. Change this behavior such that a dump is only
created in debug mode.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 20:17:53 +01:00
Lukas Fleischer
c176b130bb contrib/caldav/README: Minor improvements
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 20:03:46 +01:00
Lukas Fleischer
5e6a61eee9 calcurse-caldav: Fix comment on certificate checks
Clarify that ssl._create_unverified_context() was added in Python 3.4.3.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 19:59:38 +01:00
Lukas Fleischer
849459c63f calcurse-caldav: Support custom HTTP headers
Add support for specifying additional HTTP headers, such as the
User-Agent, in the configuration file.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 19:58:41 +01:00
Lukas Fleischer
475c341686 calcurse-caldav: Fix late retrieval of ETag
Fixes another regression introduced in badbd71 (calcurse-caldav: Add a
debug mode, 2016-01-23).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 13:08:17 +01:00
Lukas Fleischer
5abef70ee5 calcurse-caldav: Fix --init=keep-local
Fixes a regression introduced in badbd71 (calcurse-caldav: Add a debug
mode, 2016-01-23).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 10:55:32 +01:00
Lukas Fleischer
4a14103d38 calcurse-caldav: Fix duplicate Content-Type prefix
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 10:24:02 +01:00
Lukas Fleischer
2f82457bbc calcurse-caldav: Fix MIME type in requests
Specify application/xml in the Content-Type of requests except for PUT,
where we actually submit calendar data.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 09:49:24 +01:00
Lukas Fleischer
7e7d21722a calcurse-caldav: Show debug output before checking status
Make sure we print the headers and the body of a HTTP response in debug
mode, even if the HTTP status code indicates failure.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-24 13:44:27 +01:00
Lukas Fleischer
b9d80c3cf4 calcurse-caldav: Add XML declaration to requests
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-24 02:26:02 +01:00
Lukas Fleischer
84c0f8b5f8 calcurse-caldav: Prefix error messages with "error:"
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-23 16:58:01 +01:00
Lukas Fleischer
03e149d4e1 calcurse-caldav: Check response status
Bail out if the HTTP status code of any of the replies starts with a
digit other than 2.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-23 16:58:01 +01:00
Lukas Fleischer
2f4ca3c9c8 calcurse-caldav: Include command/path in the debug output
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-23 15:08:58 +01:00
Lukas Fleischer
c2e6b31357 calcurse-caldav: Ensure path always starts/ends with a slash
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-23 15:05:53 +01:00
Lukas Fleischer
badbd71275 calcurse-caldav: Add a debug mode
Dump all communication with the server to stdout if --debug is
specified.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-23 12:55:25 +01:00
Lukas Fleischer
448d470b61 calcurse-caldav: Fix parsing of the Verbose config option
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-23 11:21:13 +01:00
Lukas Fleischer
439197dc4c calcurse-caldav: Make InsecureSSL optional 2016-01-23 08:35:36 +01:00
Lukas Fleischer
dcdc792178 calcurse-caldav: Add a workaround for Python <3.4
Python versions prior to 3.4 do not check certificates by default and
thus do not support ssl._create_unverified_context(). Add a workaround.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-23 08:22:49 +01:00
Lukas Fleischer
d516a8ff87 Add a script to synchronize with CalDAV servers
Introduce calcurse-caldav, a Python script that can be used to
synchronize calcurse instances with CalDAV servers.

The script was tested with an instance of the Radicale CalDAV server but
it is still alpha software. Make backups before giving it a try!

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-22 18:44:42 +01:00