Commit b7704930 authored by Guido Günther's avatar Guido Günther

git-buildpackage: Add support for sending notifications via libnotify

after the build finished.
parent 79ed2e0f
......@@ -15,7 +15,7 @@ Architecture: all
Depends: ${python:Depends}, ${shlibs:Depends}, ${misc:Depends}, devscripts (>= 2.10.66~),
git (>= 1:1.7.0.4-2) | git-core (>= 1:1.5.0.1-1), python-dateutil
Recommends: pristine-tar (>= 0.5), cowbuilder
Suggests: git-load-dirs
Suggests: git-load-dirs, python-notify
Description: Suite to help with Debian packages in Git repositories
This package contains the following tools:
* git-import-{dsc,dscs}: import existing Debian source packages into a git
......
......@@ -75,7 +75,7 @@ _git_buildpackage()
local options=$(_gbp_options git-buildpackage)
local branch_opts="--git-debian-branch\= --git-upstream-branch\="
local tag_opts="--git-debian-tag\= --git-upstream-tag\="
local tristate_opts="--git-color\="
local tristate_opts="--git-color\= --git-notify\="
_gbp_comp "$options" "$branch_opts" "$tag_opts" "$tristate_opts"
}
......
......@@ -22,6 +22,8 @@
<arg><option>--git-[no-]ignore-new</option></arg>
<arg><option>--git-tag</option></arg>
<arg><option>--git-verbose</option></arg>
<arg><option>--color=</option><replaceable>[auto|on|off]</replaceable></arg>
<arg><option>--notify=</option><replaceable>[auto|on|off]</replaceable></arg>
<arg><option>--git-upstream-branch=</option><replaceable>treeish</replaceable></arg>
<arg><option>--git-debian-branch=</option><replaceable>branch_name</replaceable></arg>
<arg><option>--git-ignore-branch</option></arg>
......@@ -154,6 +156,20 @@
<para>verbose execution</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--color=</option><replaceable>[auto|on|off]</replaceable>
</term>
<listitem>
<para>Wheter to use colored output.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--color=</option><replaceable>[auto|on|off]</replaceable>
</term>
<listitem>
<para>Wheter to send a desktop notification after the build.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--git-upstream-branch</option>=<replaceable>branch_name</replaceable>
</term>
......
......@@ -16,7 +16,7 @@
#pristine-tar = True
# don't check if debian-branch == current branch:
#ignore-branch = True
# Use color when on a terminal, alternatives: on, off
# Use color when on a terminal, alternatives: on/true, off/false or auto
#color = auto
# Options only affecting git-buildpackage
......@@ -41,6 +41,8 @@
#compression = bzip2
# use best compression
#compression-level = best
# Don't send notifications, alternatives: on/true, off/false or auto
#notify = off
# Options only affecting git-import-orig
[git-import-orig]
......
......@@ -94,6 +94,7 @@ class GbpOptionParser(OptionParser):
'customizations' : '',
'spawn-editor' : 'release',
'patch-numbers' : 'True',
'notify' : 'auto',
}
help = {
'debian-branch':
......@@ -145,9 +146,11 @@ class GbpOptionParser(OptionParser):
'color':
"color output, default is '%(color)s'",
'spawn-editor':
"Wether to spawn an editor after adding the changelog entry, default is '%(spawn-editor)s'",
"Whether to spawn an editor after adding the changelog entry, default is '%(spawn-editor)s'",
'patch-numbers':
"Wether to number patch files, default is %(patch-numbers)s",
"Whether to number patch files, default is %(patch-numbers)s",
'notify':
"Whether to send a desktop notification after the build, default is '%(notify)s'",
}
config_files = [ '/etc/git-buildpackage/gbp.conf',
os.path.expanduser('~/.gbp.conf'),
......
# vim: set fileencoding=utf-8 :
#
# (C) 2011 Guido Guenther <agx@sigxcpu.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import log
import warnings
notify_module = None
def enable_notifications():
global notify_module
with warnings.catch_warnings():
# Avoid GTK+ cannot open display warning:
warnings.simplefilter("ignore")
try:
import pynotify
notify_module = pynotify
except ImportError:
return False
return notify_module.init("git-buildpackage")
def build_msg(cp, success):
summary = "Gbp %s" % ["failed", "successful"][success]
msg = ("Build of %s %s %s" %
(cp['Source'], cp['Version'], ["failed", "succeeded"][success]))
return summary, msg
def send_notification(summary, msg):
n = notify_module.Notification(summary, msg)
try:
if not n.show():
return False
except:
return False
return True
def notify(cp, success, notify_opt):
"""
Send a notifications
@return: False on error
"""
if notify_opt.is_off():
return True
enable = enable_notifications()
if not enable:
return [True, False][notify_opt.is_on()]
summary, msg = build_msg(cp, success)
return notify_opt.do(send_notification, summary, msg)
......@@ -32,6 +32,7 @@ from gbp.config import (GbpOptionParser, GbpOptionGroup)
from gbp.errors import GbpError
from glob import glob
import gbp.log
import gbp.notifications
# when we want to reference the index in a treeish context we call it:
index_name = "INDEX"
......@@ -218,6 +219,7 @@ def main(argv):
changelog = 'debian/changelog'
retval = 0
prefix = "git-"
cp = None
args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == 0 ]
dpkg_args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == -1 ]
......@@ -248,6 +250,7 @@ def main(argv):
parser.add_option("--git-verbose", action="store_true", dest="verbose", default=False,
help="verbose command execution")
parser.add_config_file_option(option_name="color", dest="color", type='tristate')
parser.add_config_file_option(option_name="notify", dest="notify", type='tristate')
tag_group.add_option("--git-tag", action="store_true", dest="tag", default=False,
help="create a tag after a successful build")
tag_group.add_option("--git-tag-only", action="store_true", dest="tag_only", default=False,
......@@ -443,6 +446,10 @@ def main(argv):
if options.export_dir and options.purge and not retval:
RemoveTree(export_dir)()
if cp and not gbp.notifications.notify(cp, not retval, options.notify):
gbp.log.err("Failed to send notification")
retval = 1
return retval
if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment