summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Iacob <iacobcatalin@gmail.com>2012-08-06 22:15:24 +0200
committerCatalin Iacob <iacobcatalin@gmail.com>2012-08-06 22:15:24 +0200
commit6c4f45de554aa0fd57450960e7bb5e4a28613bff (patch)
treebcb53e294ca6a8c8927ed996382cfbf151433164
parentee919b6c8ce8ba1c85c96fb5cf7c707ae8f21529 (diff)
Add zypper plugin for openSUSE
This uses zypp_plugin, a Python helper for implementing the protocol between zypper and plugins.
-rw-r--r--Makefile3
-rw-r--r--etckeeper.conf2
-rwxr-xr-xzypper-etckeeper.py38
3 files changed, 42 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 677d59f..cb1ca18 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,9 @@ ifeq ($(HIGHLEVEL_PACKAGE_MANAGER),yum)
$(INSTALL_DATA) yum-etckeeper.py $(DESTDIR)$(prefix)/lib/yum-plugins/etckeeper.py
$(INSTALL_DATA) yum-etckeeper.conf $(DESTDIR)$(etcdir)/yum/pluginconf.d/etckeeper.conf
endif
+ifeq ($(HIGHLEVEL_PACKAGE_MANAGER),zypper)
+ $(INSTALL_DATA) zypper-etckeeper.py $(DESTDIR)$(prefix)/lib/zypp/plugins/commit/zypper-etckeeper.py
+endif
-./etckeeper-bzr/__init__.py install --root=$(DESTDIR) ${PYTHON_INSTALL_OPTS} || echo "** bzr support not installed"
echo "** installation successful"
diff --git a/etckeeper.conf b/etckeeper.conf
index c95f377..4d6dd8a 100644
--- a/etckeeper.conf
+++ b/etckeeper.conf
@@ -30,7 +30,7 @@ DARCS_COMMIT_OPTIONS="-a"
#AVOID_COMMIT_BEFORE_INSTALL=1
# The high-level package manager that's being used.
-# (apt, pacman-g2, yum etc)
+# (apt, pacman-g2, yum, zypper etc)
HIGHLEVEL_PACKAGE_MANAGER=apt
# The low-level package manager that's being used.
diff --git a/zypper-etckeeper.py b/zypper-etckeeper.py
new file mode 100755
index 0000000..b21f23d
--- /dev/null
+++ b/zypper-etckeeper.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+import errno
+import subprocess
+import zypp_plugin
+
+
+def _call_etckeeper(install_arg):
+ # zypper interprets the plugin's stdout as described in
+ # http://doc.opensuse.org/projects/libzypp/HEAD/zypp-plugins.html so it's
+ # important that we don't write anything to it. We therefore redirect
+ # etckeeper's stdout to the plugin's stderr. Since zypper writes the
+ # stderr of plugins to its log file, etckeeper's stdout will go there as
+ # well.
+
+ subprocess.call(['etckeeper', install_arg], stdout=2)
+
+
+class EtckeeperPlugin(zypp_plugin.Plugin):
+ def PLUGINBEGIN(self, headers, body):
+ _call_etckeeper('pre-install')
+ self.ack()
+
+ def PLUGINEND(self, headers, body):
+ try:
+ _call_etckeeper('post-install')
+ except OSError as e:
+ # if etckeeper was just removed, executing it will fail with
+ # ENOENT
+ if e.errno != errno.ENOENT:
+ # reraise so that we don't hide other errors than etckeeper
+ # not existing
+ raise
+ self.ack()
+
+
+plugin = EtckeeperPlugin()
+plugin.main()