[opensuse-buildservice] [PATCH] teach osc to run post-command hooks
Yo Attached is a patch that enables osc to run post-command hooks. 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: #!/bin/sh 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. Michael.
Hi Michael, I like the idea, I just have one suggestion: make the name convention /hooks/%{command}.%{when} so it's /hooks/build.post that keeps it open for build.pre Also the post command IMHO should get the exit status of the command proper, if any, as "$1". S. -- Susanne Oberhauser +49-911-74053-574 SUSE -- a Novell Business OPS Engineering Maxfeldstraße 5 Processes and Infrastructure Nürnberg SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-buildservice+help@opensuse.org
On Fri, Sep 19, 2008 at 03:10:31PM -0500, Michael Wolf wrote:
Yo
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:
#!/bin/sh
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.
Michael.
From b27168d9c3de85422058db1db39a5ad2faa3766b Mon Sep 17 00:00:00 2001 From: Michael Wolf
Date: Fri, 12 Sep 2008 14:49:04 -0500 Subject: [PATCH] Add an ability to run post-command hooks: Override cmdln.py'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/commandline.py | 31 ++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/buildservice/src/clientlib/python/osc/osc/commandline.py b/buildservice/src/clientlib/python/osc/osc/commandline.py index 5e24d2a..d630854 100755 --- a/buildservice/src/clientlib/python/osc/osc/commandline.py +++ b/buildservice/src/clientlib/python/osc/osc/commandline.py @@ -36,6 +36,37 @@ class Osc(cmdln.Cmdln): cmdln.Cmdln.do_help.aliases.append('h')
+ 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 subcommand)"""
-- 1.5.6.5
Peter -- Contact: admin@opensuse.org (a.k.a. ftpadmin@suse.com) #opensuse-mirrors on freenode.net Info: http://en.opensuse.org/Mirror_Infrastructure SUSE LINUX Products GmbH Research & Development
Michael Wolf wrote:
Yo
Attached is a patch that enables osc to run post-command hooks.
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:
#!/bin/sh
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.
It would be cool to set some variables like OSC_PROJECT, OSC_PACKAGE, OSC_PACKAGE_DIR, OSC_PROJECT_DIR, OSC_REPOSITORY and so on to be able to get some context in the hooks: ~/.osc/hooks/build/fix-build #!/bin/sh if test "$OSC_EXIT_STATUS" != 0; then notify-send "please fix your stuff" gvim -o "$OSC_PACKAGE_DIR/$OSC_SPEC_NAME" \ "$OSC_BUILD_ROOT/.build.log" fi :-) Michal -- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-buildservice+help@opensuse.org
participants (4)
-
Michael Wolf
-
Michal Marek
-
Peter Poeml
-
Susanne Oberhauser