Warn if the configured VCS is different from the detected VCS.
[jelmer/etckeeper.git] / zypper-etckeeper.py
1 #!/usr/bin/env python
2
3 import errno
4 import subprocess
5 import zypp_plugin
6
7
8 def _call_etckeeper(install_arg):
9     # zypper interprets the plugin's stdout as described in
10     # http://doc.opensuse.org/projects/libzypp/HEAD/zypp-plugins.html so it's
11     # important that we don't write anything to it. We therefore redirect
12     # etckeeper's stdout to the plugin's stderr. Since zypper writes the
13     # stderr of plugins to its log file, etckeeper's stdout will go there as
14     # well.
15
16     subprocess.call(['etckeeper', install_arg], stdout=2)
17
18
19 class EtckeeperPlugin(zypp_plugin.Plugin):
20     def PLUGINBEGIN(self, headers, body):
21         _call_etckeeper('pre-install')
22         self.ack()
23
24     def PLUGINEND(self, headers, body):
25         try:
26             _call_etckeeper('post-install')
27         except OSError as e:
28             # if etckeeper was just removed, executing it will fail with
29             # ENOENT
30             if e.errno != errno.ENOENT:
31                 # reraise so that we don't hide other errors than etckeeper
32                 # not existing
33                 raise
34         self.ack()
35
36
37 plugin = EtckeeperPlugin()
38 plugin.main()