--- /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.
+
+import os
+import sys
+import argparse
+
+def get_logger(appname, debug=False):
+ """Set up syslog logger."""
+ logger = logging.getLogger(appname)
+ logger.setLevel(logging.DEBUG)
+ formatter = logging.Formatter("%(name)s: %(levelname)s %(message)s")
+ if debug:
+ handler = logging.StreamHandler()
+ else:
+ if sys.platform == 'darwin':
+ syslog_socket = "/var/run/syslog"
+ else:
+ syslog_socket = "/dev/log"
+ handler = handlers.SysLogHandler(syslog_socket)
+ handler.setFormatter(formatter)
+ logger.addHandler(handler)
+ return logger
+
+
+def parse_cmdline(argv):
+ """Parse hook command line parameters."""
+ parser = argparse.ArgumentParser(
+ description="Gerrit patchset-created hook")
+ args = (
+ "--change", # <change id>
+ "--is-draft", # <boolean>
+ "--change-url", # <change url>
+ "--project", # <project name>
+ "--branch", # <branch>
+ "--topic", # <topic>
+ "--uploader", # <uploader>
+ "--commit", # <sha1>
+ "--patchset" #<patchset id>
+ )
+ for arg in args:
+ parser.add_argument(arg)
+ parser.add_argument("-d", "--debug", action="store_true")
+ return parser.parse_args(argv)
+
+
+def main():
+
+ # get parameters from command line
+ params = parse_cmdline(sys.argv[1:])
+
+ # set up logger
+ logger = get_logger(os.path.basename(argv[0]), params.debug)
+
+ logger.warning("processing project %s : branch %s, commit %s, change: %s (draft: %s url: %s) topic: %s uploader: %s patchset: %s",
+ params.project, params.branch, params.commit, params.change,
+ params.is_draft, params.change_url, params.topic,
+ params.uploader, params.patchset)
+
+ if not params.debug:
+ daemonize()
+
+
+ logger.info("done")
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))