kiwi.filesystem
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 Dict 20from abc import ( 21 ABCMeta, 22 abstractmethod 23) 24 25# project 26from kiwi.storage.device_provider import DeviceProvider 27from kiwi.exceptions import KiwiFileSystemSetupError 28 29 30class FileSystem(metaclass=ABCMeta): 31 """ 32 **FileSystem factory** 33 34 :param string name: filesystem name 35 :param object device_provider: Instance of DeviceProvider 36 :param string root_dir: root directory path name 37 :param dict custom_args: dict of custom filesystem arguments 38 """ 39 @abstractmethod 40 def __init__(self) -> None: 41 return None # pragma: no cover 42 43 @staticmethod 44 def new( 45 name: str, device_provider: DeviceProvider, 46 root_dir: str=None, custom_args: Dict=None # noqa: E252 47 ): 48 name_map = { 49 'ext2': 'Ext2', 50 'ext3': 'Ext3', 51 'ext4': 'Ext4', 52 'btrfs': 'Btrfs', 53 'xfs': 'Xfs', 54 'fat16': 'Fat16', 55 'fat32': 'Fat32', 56 'squashfs': 'SquashFs', 57 'swap': 'Swap', 58 'erofs': 'EroFs' 59 } 60 try: 61 filesystem = importlib.import_module( 62 'kiwi.filesystem.{0}'.format(name) 63 ) 64 return filesystem.__dict__['FileSystem{0}'.format(name_map[name])]( 65 device_provider, root_dir, custom_args 66 ) 67 except Exception as issue: 68 raise KiwiFileSystemSetupError( 69 'Support for {0} filesystem not implemented: {1}'.format( 70 name, issue 71 ) 72 )
class
FileSystem:
31class FileSystem(metaclass=ABCMeta): 32 """ 33 **FileSystem factory** 34 35 :param string name: filesystem name 36 :param object device_provider: Instance of DeviceProvider 37 :param string root_dir: root directory path name 38 :param dict custom_args: dict of custom filesystem arguments 39 """ 40 @abstractmethod 41 def __init__(self) -> None: 42 return None # pragma: no cover 43 44 @staticmethod 45 def new( 46 name: str, device_provider: DeviceProvider, 47 root_dir: str=None, custom_args: Dict=None # noqa: E252 48 ): 49 name_map = { 50 'ext2': 'Ext2', 51 'ext3': 'Ext3', 52 'ext4': 'Ext4', 53 'btrfs': 'Btrfs', 54 'xfs': 'Xfs', 55 'fat16': 'Fat16', 56 'fat32': 'Fat32', 57 'squashfs': 'SquashFs', 58 'swap': 'Swap', 59 'erofs': 'EroFs' 60 } 61 try: 62 filesystem = importlib.import_module( 63 'kiwi.filesystem.{0}'.format(name) 64 ) 65 return filesystem.__dict__['FileSystem{0}'.format(name_map[name])]( 66 device_provider, root_dir, custom_args 67 ) 68 except Exception as issue: 69 raise KiwiFileSystemSetupError( 70 'Support for {0} filesystem not implemented: {1}'.format( 71 name, issue 72 ) 73 )
FileSystem factory
Parameters
- string name: filesystem name
- object device_provider: Instance of DeviceProvider
- string root_dir: root directory path name
- dict custom_args: dict of custom filesystem arguments
@staticmethod
def
new( name: str, device_provider: kiwi.storage.device_provider.DeviceProvider, root_dir: str = None, custom_args: Dict = None):
44 @staticmethod 45 def new( 46 name: str, device_provider: DeviceProvider, 47 root_dir: str=None, custom_args: Dict=None # noqa: E252 48 ): 49 name_map = { 50 'ext2': 'Ext2', 51 'ext3': 'Ext3', 52 'ext4': 'Ext4', 53 'btrfs': 'Btrfs', 54 'xfs': 'Xfs', 55 'fat16': 'Fat16', 56 'fat32': 'Fat32', 57 'squashfs': 'SquashFs', 58 'swap': 'Swap', 59 'erofs': 'EroFs' 60 } 61 try: 62 filesystem = importlib.import_module( 63 'kiwi.filesystem.{0}'.format(name) 64 ) 65 return filesystem.__dict__['FileSystem{0}'.format(name_map[name])]( 66 device_provider, root_dir, custom_args 67 ) 68 except Exception as issue: 69 raise KiwiFileSystemSetupError( 70 'Support for {0} filesystem not implemented: {1}'.format( 71 name, issue 72 ) 73 )