ALBS-334: Make the ability of Pungi to give module_defaults from remote sources
This commit is contained in:
parent
c60aaa31c0
commit
31c521196a
@ -44,6 +44,7 @@ def is_xz_file(first_two_bytes):
|
|||||||
initial_bytes=b'fd37',
|
initial_bytes=b'fd37',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RepoInfo:
|
class RepoInfo:
|
||||||
# path to a directory with repo directories. E.g. '/var/repos' contains
|
# path to a directory with repo directories. E.g. '/var/repos' contains
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import binascii
|
||||||
import gzip
|
import gzip
|
||||||
import lzma
|
import lzma
|
||||||
import os
|
import os
|
||||||
@ -12,11 +13,29 @@ import yaml
|
|||||||
import createrepo_c as cr
|
import createrepo_c as cr
|
||||||
from typing.io import BinaryIO
|
from typing.io import BinaryIO
|
||||||
|
|
||||||
from .create_packages_json import PackagesGenerator, is_gzip_file, is_xz_file
|
from pungi.scripts.create_packages_json import PackagesGenerator
|
||||||
|
|
||||||
EMPTY_FILE = '.empty'
|
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:
|
def read_modules_yaml(modules_yaml_path: Union[str, Path]) -> BytesIO:
|
||||||
with open(modules_yaml_path, 'rb') as fp:
|
with open(modules_yaml_path, 'rb') as fp:
|
||||||
return BytesIO(fp.read())
|
return BytesIO(fp.read())
|
||||||
@ -79,8 +98,6 @@ def read_modules_yaml_from_specific_repo(repo_path: AnyStr) -> List[BytesIO]:
|
|||||||
record.location_href,
|
record.location_href,
|
||||||
)
|
)
|
||||||
return [read_modules_yaml(modules_yaml_path=modules_yaml_path)]
|
return [read_modules_yaml(modules_yaml_path=modules_yaml_path)]
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
def collect_modules(
|
def collect_modules(
|
||||||
@ -95,13 +112,10 @@ def collect_modules(
|
|||||||
Returns:
|
Returns:
|
||||||
object:
|
object:
|
||||||
"""
|
"""
|
||||||
xor_flag = grep_only_modules_defaults_data is grep_only_modules_data
|
|
||||||
modules_path = os.path.join(target_dir, 'modules')
|
modules_path = os.path.join(target_dir, 'modules')
|
||||||
module_defaults_path = os.path.join(target_dir, 'module_defaults')
|
module_defaults_path = os.path.join(target_dir, 'module_defaults')
|
||||||
if grep_only_modules_data or xor_flag:
|
os.makedirs(modules_path, exist_ok=True)
|
||||||
os.makedirs(modules_path, exist_ok=True)
|
os.makedirs(module_defaults_path, exist_ok=True)
|
||||||
if grep_only_modules_defaults_data or xor_flag:
|
|
||||||
os.makedirs(module_defaults_path, exist_ok=True)
|
|
||||||
# Defaults modules can be empty, but pungi detects
|
# Defaults modules can be empty, but pungi detects
|
||||||
# empty folder while copying and raises the exception in this case
|
# empty folder while copying and raises the exception in this case
|
||||||
Path(os.path.join(module_defaults_path, EMPTY_FILE)).touch()
|
Path(os.path.join(module_defaults_path, EMPTY_FILE)).touch()
|
||||||
@ -113,6 +127,7 @@ def collect_modules(
|
|||||||
elif is_xz_file(data[:2]):
|
elif is_xz_file(data[:2]):
|
||||||
data = lzma.decompress(data)
|
data = lzma.decompress(data)
|
||||||
documents = yaml.load_all(data, Loader=yaml.BaseLoader)
|
documents = yaml.load_all(data, Loader=yaml.BaseLoader)
|
||||||
|
xor_flag = grep_only_modules_defaults_data is grep_only_modules_data
|
||||||
for doc in documents:
|
for doc in documents:
|
||||||
path = None
|
path = None
|
||||||
if doc['document'] == 'modulemd-defaults' and \
|
if doc['document'] == 'modulemd-defaults' and \
|
||||||
@ -175,22 +190,17 @@ def cli_main():
|
|||||||
help='Path to a directory which contains repodirs. E.g. /var/repos'
|
help='Path to a directory which contains repodirs. E.g. /var/repos'
|
||||||
)
|
)
|
||||||
path_group.add_argument(
|
path_group.add_argument(
|
||||||
'-rd', '--repodata-paths',
|
'-rd', '--repodata-path',
|
||||||
required=False,
|
required=False,
|
||||||
type=str,
|
type=str,
|
||||||
nargs='+',
|
default=None,
|
||||||
default=[],
|
help='Path/url to a directory with repodata dir',
|
||||||
help='Paths/urls to the directories with directory `repodata`',
|
|
||||||
)
|
)
|
||||||
parser.add_argument('-t', '--target', required=True)
|
parser.add_argument('-t', '--target', required=True)
|
||||||
|
|
||||||
namespace = parser.parse_args()
|
namespace = parser.parse_args()
|
||||||
if namespace.repodata_paths:
|
if namespace.repodata_path is not None:
|
||||||
modules = []
|
modules = read_modules_yaml_from_specific_repo(namespace.repodata_path)
|
||||||
for repodata_path in namespace.repodata_paths:
|
|
||||||
modules.extend(read_modules_yaml_from_specific_repo(
|
|
||||||
repodata_path,
|
|
||||||
))
|
|
||||||
elif namespace.path is not None:
|
elif namespace.path is not None:
|
||||||
modules = namespace.path
|
modules = namespace.path
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user