OSC is a powerful tool for packaging experts, exposing all the latest and greats features of the Build Service. It’s written on python and easy in studying and using. However there are situations when its functionality is not enough; sometimes we need something special. In this case to us will help plug-in mechanism, which in osc is realised very simply.
Plugin can use all of the features, which already implemented osc, as well as provide an output in a convenient format for you. For example, if I want to check changes in kdelibs4 between openSUSE:11.3 and openSUSE:11.4, I can do something like this:
> osc rdiff openSUSE:11.3 kdelibs4 openSUSE:Factory kdelibs4
After that I will receive a detailed output about all changes. Yes, that’s great… but not always it’s convenient. For example, in this case output will contain more than 2000 strings, and I need time to find, say, a *.changes file if I want quickly to understand that has been changed. In case if I want to transfer output to processing to another program (as often happens in practice), I have to shape this data. Unfortunately osc is not as intelligent and can’t show changes from one file (from *.changes, for example) only…
Let’s me show how we can create a very simple osc-plugin. In the derectory /var/lib/osc-plugins/ we create a new file tell_me_something.py with such content:
@cmdln.alias('say') def do_say_something(self, subcmd, opts, *args): if sys.argv == "something": print "openSUSE rulezzz" else: print sys.argv
At start, osc will check this directory and will register all found there plugins. In that case, if in the plugin’s content there are errors, osc will report about it immediately. If now we run
> osc help
we will see in the list our function say_something and the key to start it – say. Let’s test:
> osc say "hello" hello > osc say GNU/Linux GNU/Linux > osc say something openSUSE rulezzz >
As you can see, it’s very easy – just python and nothing else. Let’s go back to the output of the function rdiff(), which we mentioned at the beginning.
show me changes
In output of rdiff() nothing wrong, but I would like to immediately get information about what exactly has been done and, for example, which bugzilla-reports (related to this package) have been closed, etc. All what I need, are in rdiff’s output. It means that all what I have to do is just to shape this output.
In 40 minutes of hacking I got such output:
and between 11.4 and factory:
> osc changes kdelibs4 openSUSE:11.4 openSUSE:Factory PACKAGE: kdelibs4 CHANGES: - update to 4.6.1 * Bugfixes over KDE 4.6.0 * see http://kde.org/announcements/changelogs/changelog4_6_0to4_6_1.php for details - remove upstreamed patches
aha… and what’s about vim between 11.2 and 11.3?
> osc changes vim openSUSE:11.2 openSUSE:11.3 PACKAGE: vim BUGZILLA_NOVELL: 598903 CHANGES: - Add screen control sequences to inputrc (bnc#598903) - Use the icon from the tarball instead of our custom icon. It looks much better. - Drop gvim.png from the source package. - build data subpackage as noarch - updated patches to apply with fuzz=0
Now we can see exactly what was has been done and which bugzilla-reports was fixed/closed. Yes, we have bnc# and bko# reports: reports from bugzilla.novell.com and bugs.kde.org (it cut be also bugs.kernel.org). Second group will be always different (KDE/Gnome/Mozilla/Kernel…).
Source code of plugin is here, and I hope this post will be useful for you if you’ve never written a plugin before.
Both comments and pings are currently closed.