From 5b540e60d0ecefab64dc0444437b7291685f1aef Mon Sep 17 00:00:00 2001 From: soksanichenko Date: Fri, 29 Apr 2022 21:39:51 +0300 Subject: [PATCH] ALBS-334: Make the ability of Pungi to give module_defaults from remote sources --- pungi/scripts/create_packages_json.py | 18 +++++++++++++++++- pungi/scripts/gather_modules.py | 21 +-------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/pungi/scripts/create_packages_json.py b/pungi/scripts/create_packages_json.py index dc51a1eb..f4143453 100644 --- a/pungi/scripts/create_packages_json.py +++ b/pungi/scripts/create_packages_json.py @@ -16,6 +16,7 @@ import tempfile from collections import defaultdict from typing import AnyStr, Dict, List, Optional +import binascii import createrepo_c as cr import dnf.subject import hawkey @@ -25,8 +26,23 @@ import yaml from createrepo_c import Package from dataclasses import dataclass -from .gather_modules import is_gzip_file, is_xz_file +def _is_compressed_file(first_two_bytes: bytes, initial_bytes: bytes): + return binascii.hexlify(first_two_bytes) == initial_bytes + + +def is_gzip_file(first_two_bytes): + return _is_compressed_file( + first_two_bytes=first_two_bytes, + initial_bytes=b'1f8b', + ) + + +def is_xz_file(first_two_bytes): + return _is_compressed_file( + first_two_bytes=first_two_bytes, + initial_bytes=b'fd37', + ) @dataclass class RepoInfo: diff --git a/pungi/scripts/gather_modules.py b/pungi/scripts/gather_modules.py index adcfeccb..11e38e42 100644 --- a/pungi/scripts/gather_modules.py +++ b/pungi/scripts/gather_modules.py @@ -1,4 +1,3 @@ -import binascii import gzip import lzma import os @@ -13,29 +12,11 @@ import yaml import createrepo_c as cr from typing.io import BinaryIO -from .create_packages_json import PackagesGenerator +from .create_packages_json import PackagesGenerator, is_gzip_file, is_xz_file EMPTY_FILE = '.empty' -def _is_compressed_file(first_two_bytes: bytes, initial_bytes: bytes): - return binascii.hexlify(first_two_bytes) == initial_bytes - - -def is_gzip_file(first_two_bytes): - return _is_compressed_file( - first_two_bytes=first_two_bytes, - initial_bytes=b'1f8b', - ) - - -def is_xz_file(first_two_bytes): - return _is_compressed_file( - first_two_bytes=first_two_bytes, - initial_bytes=b'fd37', - ) - - def read_modules_yaml(modules_yaml_path: Union[str, Path]) -> BytesIO: with open(modules_yaml_path, 'rb') as fp: return BytesIO(fp.read())