File: zypper-etckeeper.py

package info (click to toggle)
etckeeper 1.15
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 412 kB
  • ctags: 41
  • sloc: sh: 1,072; python: 64; makefile: 58
file content (39 lines) | stat: -rwxr-xr-x 1,173 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python

import errno
import subprocess
import zypp_plugin
import os

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()


os.environ["LANG"] = "C"
plugin = EtckeeperPlugin()
plugin.main()