Mailinglist Archive: opensuse-buildservice (269 mails)

< Previous Next >
Re: [opensuse-buildservice] [PATCH] teach osc to run post-command hooks
  • From: Peter Poeml <poeml@xxxxxxx>
  • Date: Thu, 25 Sep 2008 16:11:07 +0200
  • Message-id: <20080925141104.GG6421@xxxxxxx>
On Fri, Sep 19, 2008 at 03:10:31PM -0500, Michael Wolf wrote:

Attached is a patch that enables osc to run post-command hooks.

Nice thing.

I have added a comment below:

To use it, create ~/.osc/hooks. Inside that directory, create a
directory for each command you'd like to hook. For instance,
~/.osc/hooks/build/. Everything in that directory will be run when the
command completes. It tries to ignore backup files and the like, but I
surely missed a few created by editors I don't use. :)

A script in ~/.osc/hooks/build might look like:


notify-send "osc build finished"

but of course they can be as simple or complicated as you wish. Of
course, they need to be executable.

Finally, directories need to be named for real command names, so, for
instance, create a hook in ~/.osc/hooks/checkout, even if you actually
always run "osc co ...".

I've been running with this patch for about two weeks and it seems to
work ok.

It would be cool to be able to send arguments to the hooks, but
currently the patch doesn't do that.


From b27168d9c3de85422058db1db39a5ad2faa3766b Mon Sep 17 00:00:00 2001
From: Michael Wolf <maw@xxxxxxxxxx>
Date: Fri, 12 Sep 2008 14:49:04 -0500
Subject: [PATCH] Add an ability to run post-command hooks:

Override's postcmd method and run hooks with it.

Don't fail if there are no hooks defined for a given command.

Don't run hooks that appear to be backup files.
.../src/clientlib/python/osc/osc/ | 31
1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/buildservice/src/clientlib/python/osc/osc/
index 5e24d2a..d630854 100755
--- a/buildservice/src/clientlib/python/osc/osc/
+++ b/buildservice/src/clientlib/python/osc/osc/
@@ -36,6 +36,37 @@ class Osc(cmdln.Cmdln):

+ def postcmd(self, argv):
+ """run user-defined hooks after a command completes"""
+ command_name = self._get_canonical_cmd_name(argv[0])
+ hookdir = os.path.expanduser("~/.osc/hooks/%s/" % command_name)
+ def not_backup_file(f):
+ # This could probably be improved
+ if f.endswith("~"):
+ return False
+ if f.startswith("#"):
+ return False
+ if f.startswith("."):
+ return False
+ return True

For that, you could use exclude_stuff from osc.core:

+ try:
+ hooks = os.listdir(hookdir)
+ except OSError, msg:
+ # No hooks for command_name; nothing to do
+ return
+ hooks.sort()
+ hooks = filter(not_backup_file, hooks)

hooks = [ i for i in hooks
for j in exclude_stuff
if not fnmatch.fnmatch(i, j) ]

exclude_stuff is [store, 'CVS', '*~', '.*', '_linkerror'], which means it isn't
a perfect match, but might do.

+ for hook in hooks:
+ os.system("%s/%s" % (hookdir, hook))
def get_optparser(self):
"""this is the parser for "global" options (not specific to


Contact: admin@xxxxxxxxxxxx (a.k.a. ftpadmin@xxxxxxxx)
#opensuse-mirrors on

SUSE LINUX Products GmbH
Research & Development
< Previous Next >