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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
# -*- coding: utf-8 -*-
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:
# License: GPL2 or later see COPYING
# Written by Clark Williams
# Copyright (C) 2013 Clark Williams <clark.williams@gmail.com>
# python library imports
import os
import os.path
import re
import subprocess
# our imports
from mockbuild.trace_decorator import getLog, traceLog
import mockbuild.util
requires_api_version = "1.1"
# plugin entry point
@traceLog()
def init(plugins, conf, buildroot):
ChrootScan(plugins, conf, buildroot)
class ChrootScan(object):
"""scan chroot for files of interest, copying to resultdir with relative paths"""
@traceLog()
def __init__(self, plugins, conf, buildroot):
self.buildroot = buildroot
self.config = buildroot.config
self.state = buildroot.state
self.scan_opts = conf
self.resultdir = os.path.join(buildroot.resultdir, "chroot_scan")
plugins.add_hook("postbuild", self._scanChroot)
getLog().info("chroot_scan: initialized")
def _only_failed(self):
""" Returns boolean value if option 'only_failed' is set. """
return str(self.scan_opts['only_failed']) == 'True'
@traceLog()
def _scanChroot(self):
is_failed = self.state.result != "success"
if (self._only_failed() and is_failed) or not self._only_failed():
self.__scanChroot()
def __scanChroot(self):
regexstr = "|".join(self.scan_opts['regexes'])
regex = re.compile(regexstr)
chroot = self.buildroot.make_chroot_path()
mockbuild.util.mkdirIfAbsent(self.resultdir)
count = 0
logger = getLog()
logger.debug("chroot_scan: Starting scan of %s", chroot)
copied = []
for root, _, files in os.walk(chroot):
for f in files:
m = regex.search(f)
if m:
srcpath = os.path.join(root, f)
subprocess.call("cp --parents %s %s" % (srcpath, self.resultdir), shell=True)
count += 1
copied.append(srcpath)
logger.debug("chroot_scan: finished with %d files found", count)
if count:
logger.info("chroot_scan: %d files copied to %s", count, self.resultdir)
logger.info("\n".join(copied))
|