1 #! /usr/bin/env python2
3 """Example post-receive hook based on git-multimail.
5 This script is a simple example of a post-receive hook implemented
6 using git_multimail.py as a Python module. It is intended to be
7 customized before use; see the comments in the script to help you get
10 It is possible to use git_multimail.py itself as a post-receive or
11 update hook, configured via git config settings and/or command-line
12 parameters. But for more flexibility, it can also be imported as a
13 Python module by a custom post-receive script as done here. The
14 latter has the following advantages:
16 * The tool's behavior can be customized using arbitrary Python code,
17 without having to edit git_multimail.py.
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.
24 This script is a very basic example of how to use git_multimail.py as
25 a module. The comments below explain some of the points at which the
26 script's behavior could be changed or customized.
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
38 #LIBDIR = 'path/to/directory/containing/module'
39 #sys.path.insert(0, LIBDIR)
44 # It is possible to modify the output templates here; e.g.:
46 #git_multimail.FOOTER_TEMPLATE = """\
49 #This email was generated by the wonderful git-multimail tool.
53 # Specify which "git config" section contains the configuration for
55 config = git_multimail.Config('multimailhook')
58 # Select the type of environment:
59 environment = git_multimail.GenericEnvironment(config=config)
60 #environment = git_multimail.GitoliteEnvironment(config=config)
63 # Choose the method of sending emails based on the git config:
64 mailer = git_multimail.choose_mailer(config, environment)
66 # Alternatively, you may hardcode the mailer using code like one of
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',
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',
84 # OutputMailer is intended only for testing; it writes the emails to
85 # the specified file stream.
86 #mailer = git_multimail.OutputMailer(sys.stdout)
89 # Read changes from stdin and send notification emails:
90 git_multimail.run_as_post_receive_hook(environment, mailer)