summaryrefslogtreecommitdiff
path: root/zypper-etckeeper.py
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2012-08-06 17:16:29 -0400
committerJoey Hess <joey@kitenet.net>2012-08-06 17:16:29 -0400
commit16712188110cae8c247c25ed3450d3e714c2f5ba (patch)
treec93cf61f002c209f90f7dc4d56d3340cba1059d8 /zypper-etckeeper.py
parent312bc55934e49a9e91b142661f707aee1933ab87 (diff)
parent6c4f45de554aa0fd57450960e7bb5e4a28613bff (diff)
Merge git://github.com/cataliniacob/etckeeper
Diffstat (limited to 'zypper-etckeeper.py')
-rwxr-xr-xzypper-etckeeper.py38
1 files changed, 38 insertions, 0 deletions
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()