contrib / hooks / multimail / post-receiveon commit Merge branch 'rr/rebase-autostash' (c8686e5)
   1#! /usr/bin/env python2
   2
   3"""Example post-receive hook based on git-multimail.
   4
   5This script is a simple example of a post-receive hook implemented
   6using git_multimail.py as a Python module.  It is intended to be
   7customized before use; see the comments in the script to help you get
   8started.
   9
  10It is possible to use git_multimail.py itself as a post-receive or
  11update hook, configured via git config settings and/or command-line
  12parameters.  But for more flexibility, it can also be imported as a
  13Python module by a custom post-receive script as done here.  The
  14latter has the following advantages:
  15
  16* The tool's behavior can be customized using arbitrary Python code,
  17  without having to edit git_multimail.py.
  18
  19* Configuration settings can be read from other sources; for example,
  20  user names and email addresses could be read from LDAP or from a
  21  database.  Or the settings can even be hardcoded in the importing
  22  Python script, if this is preferred.
  23
  24This script is a very basic example of how to use git_multimail.py as
  25a module.  The comments below explain some of the points at which the
  26script's behavior could be changed or customized.
  27
  28"""
  29
  30import sys
  31import os
  32
  33# If necessary, add the path to the directory containing
  34# git_multimail.py to the Python path as follows.  (This is not
  35# necessary if git_multimail.py is in the same directory as this
  36# script):
  37
  38#LIBDIR = 'path/to/directory/containing/module'
  39#sys.path.insert(0, LIBDIR)
  40
  41import git_multimail
  42
  43
  44# It is possible to modify the output templates here; e.g.:
  45
  46#git_multimail.FOOTER_TEMPLATE = """\
  47#
  48#-- \n\
  49#This email was generated by the wonderful git-multimail tool.
  50#"""
  51
  52
  53# Specify which "git config" section contains the configuration for
  54# git-multimail:
  55config = git_multimail.Config('multimailhook')
  56
  57
  58# Select the type of environment:
  59environment = git_multimail.GenericEnvironment(config=config)
  60#environment = git_multimail.GitoliteEnvironment(config=config)
  61
  62
  63# Choose the method of sending emails based on the git config:
  64mailer = git_multimail.choose_mailer(config, environment)
  65
  66# Alternatively, you may hardcode the mailer using code like one of
  67# the following:
  68
  69# Use "/usr/sbin/sendmail -t" to send emails.  The envelopesender
  70# argument is optional:
  71#mailer = git_multimail.SendMailer(
  72#    command=['/usr/sbin/sendmail', '-t'],
  73#    envelopesender='git-repo@example.com',
  74#    )
  75
  76# Use Python's smtplib to send emails.  Both arguments are required.
  77#mailer = git_multimail.SMTPMailer(
  78#    envelopesender='git-repo@example.com',
  79#    # The smtpserver argument can also include a port number; e.g.,
  80#    #     smtpserver='mail.example.com:25'
  81#    smtpserver='mail.example.com',
  82#    )
  83
  84# OutputMailer is intended only for testing; it writes the emails to
  85# the specified file stream.
  86#mailer = git_multimail.OutputMailer(sys.stdout)
  87
  88
  89# Read changes from stdin and send notification emails:
  90git_multimail.run_as_post_receive_hook(environment, mailer)