File: compress_logs.py

package info (click to toggle)
mock 1.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,572 kB
  • ctags: 533
  • sloc: python: 4,816; sh: 429; ansic: 66; makefile: 47
file content (37 lines) | stat: -rw-r--r-- 1,245 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
# -*- coding: utf-8 -*-
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:
# License: GPL2 or later see COPYING

import os.path

from mockbuild import util
from mockbuild.trace_decorator import getLog, traceLog

requires_api_version = "1.1"


class CompressLogsPlugin(object):
    """Compress logs in resultdir."""
    @traceLog()
    def __init__(self, plugins, conf, buildroot):
        self.buildroot = buildroot
        self.config = buildroot.config
        self.state = buildroot.state
        self.conf = conf
        self.command = self.conf['command']
        plugins.add_hook("postbuild", self._compress_logs)
        getLog().info("compress_logs: initialized")

    @traceLog()
    def _compress_logs(self):
        logger = getLog()
        for f_name in ('root.log', 'build.log', 'state.log', 'available_pkgs', 'installed_pkgs'):
            f_path = os.path.join(self.buildroot.resultdir, f_name)
            if os.path.exists(f_path):
                command = "{0} {1}".format(self.command, f_path)
                logger.debug("Running %s", command)
                util.do(command, shell=True)


def init(plugins, compress_conf, buildroot):
    CompressLogsPlugin(plugins, compress_conf, buildroot)