84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:
|
|
# License: GPL2 or later see COPYING
|
|
# Written by Jean-Philippe Pialasse
|
|
# Copyright (C) 2022 Jean-Philippe Pialasse <jpp@koozali.org>
|
|
|
|
|
|
"""
|
|
# The copy plugin is enabled by default.
|
|
# To disable it, use following option:
|
|
config_opts['plugin_conf']['copy'] = False
|
|
# To configure the copy plugin, for each file use following option:
|
|
config_opts['plugin_conf']['copy_opts']['files'].append(
|
|
("/usr/local/myfile", "/usr/bin/myfile_inchroot"))
|
|
# A real life example:
|
|
config_opts['plugin_conf']['copy_opts']['files'].append(
|
|
("/usr/lib/rpm/redhat/perl.prov", "/usr/lib/rpm/redhat/perl.prov"))
|
|
"""
|
|
import shutil
|
|
import os
|
|
from mockbuild.mounts import FileSystemMountPoint
|
|
from mockbuild.trace_decorator import getLog, traceLog
|
|
#from mockbuild.buildroot import make_chroot_path
|
|
from mockbuild import file_util
|
|
|
|
requires_api_version = "1.1"
|
|
|
|
|
|
# plugin entry point
|
|
@traceLog()
|
|
def init(plugins, conf, buildroot):
|
|
Copy(plugins, conf, buildroot)
|
|
|
|
|
|
class Copy(object):
|
|
"""copy files into chroot"""
|
|
# pylint: disable=too-few-public-methods
|
|
@traceLog()
|
|
def __init__(self, plugins, conf, buildroot):
|
|
self.buildroot = buildroot
|
|
self.config = buildroot.config
|
|
self.state = buildroot.state
|
|
self.opts = conf
|
|
# Skip copy user-specified files if we're in the boostrap chroot
|
|
if buildroot.is_bootstrap:
|
|
return
|
|
getLog().info(conf['files'])
|
|
getLog().info("enabled package copy")
|
|
plugins.add_hook("postinit", self._copyFiles)
|
|
plugins.add_hook('postyum', self._copyFiles)
|
|
self._copyFiles
|
|
#for ori_file, dest_file in self.opts['files']:
|
|
# getLog().info(ori_file)
|
|
# self._copyFiles
|
|
|
|
@traceLog()
|
|
def _copyFiles(self):
|
|
# pylint: disable=unused-variable
|
|
for ori_file, dest_file in self.opts['files']:
|
|
cdest_file = self.buildroot.make_chroot_path(dest_file)
|
|
try:
|
|
os.remove(cdest_file)
|
|
except FileNotFoundError:
|
|
pass
|
|
file_util.mkdirIfAbsent(os.path.dirname(cdest_file))
|
|
if os.path.exists(ori_file):
|
|
shutil.copy2(ori_file, cdest_file)
|
|
getLog().info("File %s copied to %s !",ori_file , cdest_file )
|
|
elif warn:
|
|
getlog.warning("File %s not present. It is not copied into the chroot.", ori_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|