Git 2.7.3
[git/debian.git] / contrib / hooks / multimail / post-receive.example
blob9975df7107ac29be2b2ac861b90dfc0730ec7b97
1 #! /usr/bin/env python
3 """Example post-receive hook based on git-multimail.
5 The simplest way to use git-multimail is to use the script
6 git_multimail.py directly as a post-receive hook, and to configure it
7 using Git's configuration files and command-line parameters. You can
8 also write your own Python wrapper for more advanced configurability,
9 using git_multimail.py as a Python module.
11 This script is a simple example of such a post-receive hook. It is
12 intended to be customized before use; see the comments in the script
13 to help you get started.
15 Using git-multimail as a Python module as done here provides more
16 flexibility. It has the following advantages:
18 * The tool's behavior can be customized using arbitrary Python code,
19 without having to edit git_multimail.py.
21 * Configuration settings can be read from other sources; for example,
22 user names and email addresses could be read from LDAP or from a
23 database. Or the settings can even be hardcoded in the importing
24 Python script, if this is preferred.
26 This script is a very basic example of how to use git_multimail.py as
27 a module. The comments below explain some of the points at which the
28 script's behavior could be changed or customized.
30 """
32 import sys
33 import os
35 # If necessary, add the path to the directory containing
36 # git_multimail.py to the Python path as follows. (This is not
37 # necessary if git_multimail.py is in the same directory as this
38 # script):
40 #LIBDIR = 'path/to/directory/containing/module'
41 #sys.path.insert(0, LIBDIR)
43 import git_multimail
45 # It is possible to modify the output templates here; e.g.:
47 #git_multimail.FOOTER_TEMPLATE = """\
49 #-- \n\
50 #This email was generated by the wonderful git-multimail tool.
51 #"""
54 # Specify which "git config" section contains the configuration for
55 # git-multimail:
56 config = git_multimail.Config('multimailhook')
59 # Select the type of environment:
60 try:
61 environment = git_multimail.GenericEnvironment(config=config)
62 #environment = git_multimail.GitoliteEnvironment(config=config)
63 except git_multimail.ConfigurationException:
64 sys.stderr.write('*** %s\n' % sys.exc_info()[1])
65 sys.exit(1)
68 # Choose the method of sending emails based on the git config:
69 mailer = git_multimail.choose_mailer(config, environment)
71 # Alternatively, you may hardcode the mailer using code like one of
72 # the following:
74 # Use "/usr/sbin/sendmail -oi -t" to send emails. The envelopesender
75 # argument is optional:
76 #mailer = git_multimail.SendMailer(
77 # command=['/usr/sbin/sendmail', '-oi', '-t'],
78 # envelopesender='git-repo@example.com',
79 # )
81 # Use Python's smtplib to send emails. Both arguments are required.
82 #mailer = git_multimail.SMTPMailer(
83 # envelopesender='git-repo@example.com',
84 # # The smtpserver argument can also include a port number; e.g.,
85 # # smtpserver='mail.example.com:25'
86 # smtpserver='mail.example.com',
87 # )
89 # OutputMailer is intended only for testing; it writes the emails to
90 # the specified file stream.
91 #mailer = git_multimail.OutputMailer(sys.stdout)
94 # Read changes from stdin and send notification emails:
95 git_multimail.run_as_post_receive_hook(environment, mailer)