--- /dev/null
+#!/usr/bin/env
+# -*- coding: UTF-8 -*-
+# vim: sw=4 ts=4 expandtab ai
+#
+# Copyright (c) 2013 Intel, Inc.
+# License: GPLv2
+# Author: Alexander Kanevskiy <alexander.kanevskiy@intel.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License, version 2,
+# as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+"""
+Common code to run hooks from plugins
+"""
+import os
+import sys
+import ConfigParser
+
+from gerrithooks.misc import find_config, configure_logging, daemonize
+
+from pkg_resources import iter_entry_points
+
+def run_plugin_hooks(hook, params, logger):
+ """
+ Common code for every hook. Must provide parsed params and logger
+ """
+
+ if not 'debug' in params or not params.debug:
+ logger.debug("Daemonizing...")
+ daemonize()
+
+ logger.debug("looking for config")
+ confname = "gerrit-hooks.conf"
+ conf = find_config(confname, subdir="gerrit-hooks")
+ if not conf:
+ logger.error("Log configuration file %s not found or not readable",
+ confname)
+ return 1
+
+ # read rules from configuration file
+ config = ConfigParser.RawConfigParser()
+ #config.optionxform = str
+
+ logger.debug("runner: reading config from %s", conf)
+ config.read(conf)
+
+ entry_point_group = "gerrit-hooks"
+ logger.debug("runner: looking for plugins in entry %s", entry_point_group)
+
+ for entry_point in iter_entry_points(group=entry_point_group, name=hook):
+ logger.debug("Loading plugin %s from %s",
+ entry_point.name, entry_point.module)
+ plugin = entry_point.load()
+ logger.debug("Executing plugin %s", entry_point.name)
+ plugin(hook=hook, params=params, config=config)
+
+ logger.info("done")
+ return 0
+
+if __name__ == "__main__":
+ raise SystemExit("This module does not supposed to be run directly!")