kiwi.repository
1# Copyright (c) 2015 SUSE Linux GmbH. All rights reserved. 2# 3# This file is part of kiwi. 4# 5# kiwi is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9# 10# kiwi is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with kiwi. If not, see <http://www.gnu.org/licenses/> 17# 18import importlib 19from typing import List 20from abc import ( 21 ABCMeta, 22 abstractmethod 23) 24 25# project 26from kiwi.exceptions import KiwiRepositorySetupError 27 28 29class Repository(metaclass=ABCMeta): 30 """ 31 **Repository factory** 32 33 :param object root_bind: instance of RootBind 34 :param str package_manager: package manager name 35 :param list custom_args: list of custom package manager arguments 36 to setup the repository 37 38 :raises KiwiRepositorySetupError: if package_manager is not supported 39 """ 40 @abstractmethod 41 def __init__(self) -> None: 42 return None # pragma: no cover 43 44 @staticmethod 45 def new( 46 root_bind: object, package_manager: str, 47 custom_args: List=None # noqa: E252 48 ): 49 name_map = { 50 'zypper': ['zypper', 'Zypper'], 51 'dnf': ['dnf', 'Dnf'], 52 'dnf5': ['dnf5', 'Dnf5'], 53 'dnf4': ['dnf4', 'Dnf4'], 54 'microdnf': ['dnf4', 'Dnf4'], 55 'apt': ['apt', 'Apt'], 56 'pacman': ['pacman', 'Pacman'], 57 'apk': ['apk', 'Apk'] 58 } 59 try: 60 repository = importlib.import_module( 61 'kiwi.repository.{0}'.format(name_map[package_manager][0]) 62 ) 63 module_name = 'Repository{0}'.format(name_map[package_manager][1]) 64 return repository.__dict__[module_name]( 65 root_bind, custom_args 66 ) 67 except Exception as issue: 68 raise KiwiRepositorySetupError( 69 'Support for {0} repository not implemented: {1}'.format( 70 package_manager, issue 71 ) 72 )
class
Repository:
30class Repository(metaclass=ABCMeta): 31 """ 32 **Repository factory** 33 34 :param object root_bind: instance of RootBind 35 :param str package_manager: package manager name 36 :param list custom_args: list of custom package manager arguments 37 to setup the repository 38 39 :raises KiwiRepositorySetupError: if package_manager is not supported 40 """ 41 @abstractmethod 42 def __init__(self) -> None: 43 return None # pragma: no cover 44 45 @staticmethod 46 def new( 47 root_bind: object, package_manager: str, 48 custom_args: List=None # noqa: E252 49 ): 50 name_map = { 51 'zypper': ['zypper', 'Zypper'], 52 'dnf': ['dnf', 'Dnf'], 53 'dnf5': ['dnf5', 'Dnf5'], 54 'dnf4': ['dnf4', 'Dnf4'], 55 'microdnf': ['dnf4', 'Dnf4'], 56 'apt': ['apt', 'Apt'], 57 'pacman': ['pacman', 'Pacman'], 58 'apk': ['apk', 'Apk'] 59 } 60 try: 61 repository = importlib.import_module( 62 'kiwi.repository.{0}'.format(name_map[package_manager][0]) 63 ) 64 module_name = 'Repository{0}'.format(name_map[package_manager][1]) 65 return repository.__dict__[module_name]( 66 root_bind, custom_args 67 ) 68 except Exception as issue: 69 raise KiwiRepositorySetupError( 70 'Support for {0} repository not implemented: {1}'.format( 71 package_manager, issue 72 ) 73 )
Repository factory
Parameters
- object root_bind: instance of RootBind
- str package_manager: package manager name
- list custom_args: list of custom package manager arguments to setup the repository
Raises
- KiwiRepositorySetupError: if package_manager is not supported
@staticmethod
def
new(root_bind: object, package_manager: str, custom_args: List = None):
45 @staticmethod 46 def new( 47 root_bind: object, package_manager: str, 48 custom_args: List=None # noqa: E252 49 ): 50 name_map = { 51 'zypper': ['zypper', 'Zypper'], 52 'dnf': ['dnf', 'Dnf'], 53 'dnf5': ['dnf5', 'Dnf5'], 54 'dnf4': ['dnf4', 'Dnf4'], 55 'microdnf': ['dnf4', 'Dnf4'], 56 'apt': ['apt', 'Apt'], 57 'pacman': ['pacman', 'Pacman'], 58 'apk': ['apk', 'Apk'] 59 } 60 try: 61 repository = importlib.import_module( 62 'kiwi.repository.{0}'.format(name_map[package_manager][0]) 63 ) 64 module_name = 'Repository{0}'.format(name_map[package_manager][1]) 65 return repository.__dict__[module_name]( 66 root_bind, custom_args 67 ) 68 except Exception as issue: 69 raise KiwiRepositorySetupError( 70 'Support for {0} repository not implemented: {1}'.format( 71 package_manager, issue 72 ) 73 )