diff options
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | debian/git-buildpackage.bash-completion | 2 | ||||
-rw-r--r-- | docs/manpages/git-buildpackage.sgml | 16 | ||||
-rw-r--r-- | gbp.conf | 4 | ||||
-rw-r--r-- | gbp/config.py | 7 | ||||
-rw-r--r-- | gbp/notifications.py | 71 | ||||
-rwxr-xr-x | git-buildpackage | 7 |
7 files changed, 104 insertions, 5 deletions
diff --git a/debian/control b/debian/control index e7db98e5..8fcd5c5c 100644 --- a/debian/control +++ b/debian/control @@ -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 diff --git a/debian/git-buildpackage.bash-completion b/debian/git-buildpackage.bash-completion index 8c61170d..1b855040 100644 --- a/debian/git-buildpackage.bash-completion +++ b/debian/git-buildpackage.bash-completion @@ -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" } diff --git a/docs/manpages/git-buildpackage.sgml b/docs/manpages/git-buildpackage.sgml index 64d552c7..7839d92d 100644 --- a/docs/manpages/git-buildpackage.sgml +++ b/docs/manpages/git-buildpackage.sgml @@ -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> @@ -155,6 +157,20 @@ </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> <listitem> @@ -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] diff --git a/gbp/config.py b/gbp/config.py index e623c3b2..8448762c 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -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'), diff --git a/gbp/notifications.py b/gbp/notifications.py new file mode 100644 index 00000000..b2534e3f --- /dev/null +++ b/gbp/notifications.py @@ -0,0 +1,71 @@ +# 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) + diff --git a/git-buildpackage b/git-buildpackage index a7a0cec5..78212bfb 100755 --- a/git-buildpackage +++ b/git-buildpackage @@ -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__': |