From 0263251ecf105a5a9b630d59552f46d96c65ee63 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 11 Jun 2016 10:34:18 +0200 Subject: [PATCH] Add hook for storage changes --- config | 4 ++++ radicale/__init__.py | 11 +++++++++++ radicale/config.py | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config b/config index 7ded009..ab922b2 100644 --- a/config +++ b/config @@ -112,6 +112,10 @@ # Folder for storing local collections, created if not present #filesystem_folder = ~/.config/radicale/collections +# Command that is run after changes to storage +#hook = +# Example: git add -A && (git diff --cached --quiet || git commit -m "Changes by "%(user)s) + [logging] diff --git a/radicale/__init__.py b/radicale/__init__.py index 4f2e26d..d64d037 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -30,10 +30,12 @@ import os import pprint import base64 import contextlib +import shlex import socket import socketserver import ssl import threading +import subprocess import wsgiref.simple_server import re import zlib @@ -348,6 +350,15 @@ class Application: status, headers, answer = function( environ, read_allowed_items, write_allowed_items, content, user) + hook = self.configuration.get("storage", "hook") + if lock_mode == "w" and hook: + self.logger.debug("Running hook") + folder = os.path.expanduser( + self.configuration.get("storage", + "filesystem_folder")) + subprocess.check_call( + hook % {"user": shlex.quote(user or "Anonymous")}, + shell=True, cwd=folder) else: status, headers, answer = NOT_ALLOWED else: diff --git a/radicale/config.py b/radicale/config.py index 7886c3b..8ca1677 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -60,7 +60,8 @@ INITIAL_CONFIG = { "storage": { "type": "multifilesystem", "filesystem_folder": os.path.expanduser( - "~/.config/radicale/collections")}, + "~/.config/radicale/collections"), + "hook": ""}, "logging": { "config": "/etc/radicale/logging", "debug": "False",