2015-02-10 13:19:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2016-09-21 12:49:13 +00:00
|
|
|
# along with this program; if not, see <https://gnu.org/licenses/>.
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import copy
|
|
|
|
import fnmatch
|
|
|
|
|
2019-11-01 08:10:34 +00:00
|
|
|
from productmd.extra_files import ExtraFiles
|
|
|
|
|
2016-05-12 11:44:42 +00:00
|
|
|
from pungi.util import get_arch_variant_data, pkg_is_rpm, copy_all
|
2015-03-12 21:12:38 +00:00
|
|
|
from pungi.arch import split_name_arch
|
|
|
|
from pungi.wrappers.scm import get_file_from_scm, get_dir_from_scm
|
2016-05-12 11:50:34 +00:00
|
|
|
from pungi.phases.base import ConfigGuardedPhase
|
2019-11-01 08:10:34 +00:00
|
|
|
from pungi import metadata
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
|
2016-05-12 11:50:34 +00:00
|
|
|
class ExtraFilesPhase(ConfigGuardedPhase):
|
2015-02-10 13:19:34 +00:00
|
|
|
"""EXTRA_FILES"""
|
|
|
|
name = "extra_files"
|
|
|
|
|
|
|
|
def __init__(self, compose, pkgset_phase):
|
2016-05-12 11:50:34 +00:00
|
|
|
super(ExtraFilesPhase, self).__init__(compose)
|
|
|
|
# pkgset_phase provides package_sets
|
2015-02-10 13:19:34 +00:00
|
|
|
self.pkgset_phase = pkgset_phase
|
2019-11-01 08:10:34 +00:00
|
|
|
# Prepare metadata
|
|
|
|
self.metadata = ExtraFiles()
|
|
|
|
self.metadata.compose.id = self.compose.compose_id
|
|
|
|
self.metadata.compose.type = self.compose.compose_type
|
|
|
|
self.metadata.compose.date = self.compose.compose_date
|
|
|
|
self.metadata.compose.respin = self.compose.compose_respin
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
def run(self):
|
2019-09-02 12:52:19 +00:00
|
|
|
for variant in self.compose.get_variants():
|
|
|
|
if variant.is_empty:
|
|
|
|
continue
|
|
|
|
for arch in variant.arches + ["src"]:
|
2016-05-12 12:19:14 +00:00
|
|
|
cfg = get_arch_variant_data(self.compose.conf, self.name, arch, variant)
|
|
|
|
if cfg:
|
2019-11-01 08:10:34 +00:00
|
|
|
copy_extra_files(
|
|
|
|
self.compose,
|
|
|
|
cfg,
|
|
|
|
arch,
|
|
|
|
variant,
|
|
|
|
self.pkgset_phase.package_sets,
|
|
|
|
self.metadata,
|
|
|
|
)
|
2016-05-12 12:19:14 +00:00
|
|
|
else:
|
|
|
|
self.compose.log_info('[SKIP ] No extra files (arch: %s, variant: %s)'
|
|
|
|
% (arch, variant.uid))
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2019-11-01 08:10:34 +00:00
|
|
|
metadata_path = self.compose.paths.compose.metadata("extra_files.json")
|
|
|
|
self.compose.log_info("Writing global extra files metadata: %s" % metadata_path)
|
|
|
|
self.metadata.dump(metadata_path)
|
|
|
|
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2019-11-01 08:10:34 +00:00
|
|
|
def copy_extra_files(
|
|
|
|
compose, cfg, arch, variant, package_sets, extra_metadata, checksum_type=None
|
|
|
|
):
|
2017-04-20 06:58:27 +00:00
|
|
|
checksum_type = checksum_type or compose.conf['media_checksums']
|
2015-02-10 13:19:34 +00:00
|
|
|
var_dict = {
|
|
|
|
"arch": arch,
|
|
|
|
"variant_id": variant.id,
|
|
|
|
"variant_id_lower": variant.id.lower(),
|
|
|
|
"variant_uid": variant.uid,
|
|
|
|
"variant_uid_lower": variant.uid.lower(),
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = "Getting extra files (arch: %s, variant: %s)" % (arch, variant)
|
|
|
|
compose.log_info("[BEGIN] %s" % msg)
|
|
|
|
|
|
|
|
os_tree = compose.paths.compose.os_tree(arch, variant)
|
|
|
|
extra_files_dir = compose.paths.work.extra_files_dir(arch, variant)
|
|
|
|
|
2016-05-12 12:19:14 +00:00
|
|
|
for scm_dict in cfg:
|
2015-02-10 13:19:34 +00:00
|
|
|
scm_dict = copy.deepcopy(scm_dict)
|
2016-05-12 11:56:55 +00:00
|
|
|
# if scm is "rpm" and repo contains only a package name, find the
|
|
|
|
# package(s) in package set
|
|
|
|
if scm_dict["scm"] == "rpm" and not _is_external(scm_dict["repo"]):
|
2015-02-10 13:19:34 +00:00
|
|
|
rpms = []
|
2016-11-10 08:38:50 +00:00
|
|
|
pattern = scm_dict["repo"] % var_dict
|
|
|
|
pkg_name, pkg_arch = split_name_arch(pattern)
|
2019-07-25 08:15:14 +00:00
|
|
|
for package_set in package_sets:
|
|
|
|
for pkgset_file in package_set[arch]:
|
|
|
|
pkg_obj = package_set[arch][pkgset_file]
|
|
|
|
if pkg_is_rpm(pkg_obj) and _pkg_matches(pkg_obj, pkg_name, pkg_arch):
|
|
|
|
rpms.append(pkg_obj.file_path)
|
2016-11-10 08:38:50 +00:00
|
|
|
if not rpms:
|
|
|
|
raise RuntimeError('No package matching %s in the package set.' % pattern)
|
2015-02-10 13:19:34 +00:00
|
|
|
scm_dict["repo"] = rpms
|
|
|
|
|
2016-05-12 11:56:55 +00:00
|
|
|
getter = get_file_from_scm if 'file' in scm_dict else get_dir_from_scm
|
extra-files: Write a metadata file enumerating extra files
Introduces a new metadata file to track arbitrary files added during the
extra-files phase. This file is placed in the root of each tree and is
called ``extra_files.json``. It is a JSON file containing a single
object, which contains a "header" key with an object describing the
metadata, and a "data" key, which is an array of objects, where each
object represents a file. Each object contains the "file", "checksums",
and "size" keys. "file" is the relative path from the tree root to the
extra file. "checksums" is an object containing one or more checksums,
where the key is the digest type and the value of that key is the hex
digest. Finally, the size is the size of the file in bytes.
For example:
{
"header": {"version": "1.0},
"data": [
{
"file": "GPL",
"checksums": {
"sha256": "8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643"
},
"size": 18092
},
{
"file": "release-notes/notes.html",
"checksums": {
"sha256": "82b1ba8db522aadf101dca6404235fba179e559b95ea24ff39ee1e5d9a53bdcb"
},
"size": 1120
}
]
}
Signed-off-by: Jeremy Cline <jeremy@jcline.org>
Fixes: #295
2016-05-31 13:40:20 +00:00
|
|
|
target_path = os.path.join(extra_files_dir, scm_dict.get('target', '').lstrip('/'))
|
2019-10-07 10:26:22 +00:00
|
|
|
getter(scm_dict, target_path, compose=compose)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
if os.listdir(extra_files_dir):
|
2019-11-01 08:10:34 +00:00
|
|
|
metadata.populate_extra_files_metadata(
|
|
|
|
extra_metadata,
|
|
|
|
variant,
|
|
|
|
arch,
|
|
|
|
os_tree,
|
|
|
|
copy_all(extra_files_dir, os_tree),
|
|
|
|
compose.conf["media_checksums"],
|
|
|
|
relative_root=compose.paths.compose.topdir(),
|
|
|
|
)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
compose.log_info("[DONE ] %s" % msg)
|
2016-05-12 11:56:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _pkg_matches(pkg_obj, name_glob, arch):
|
|
|
|
"""Check if `pkg_obj` matches name and arch."""
|
|
|
|
return (fnmatch.fnmatch(pkg_obj.name, name_glob) and
|
|
|
|
(arch is None or arch == pkg_obj.arch))
|
|
|
|
|
|
|
|
|
|
|
|
def _is_external(rpm):
|
|
|
|
"""Check if path to rpm points outside of the compose: i.e. it is an
|
|
|
|
absolute path or a URL."""
|
|
|
|
return rpm.startswith('/') or '://' in rpm
|