kiwi.partitioner

 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 abc import (
20    ABCMeta,
21    abstractmethod
22)
23import logging
24
25# project
26from kiwi.exceptions import KiwiPartitionerSetupError
27
28log = logging.getLogger('kiwi')
29
30
31class Partitioner(metaclass=ABCMeta):
32    """
33    **Partitioner factory**
34
35    :param string table_type: Table type name
36    :param object storage_provider: Instance of class based on DeviceProvider
37    :param int start_sector: sector number
38    :param bool extended_layout: support extended layout for msdos table
39    """
40    @abstractmethod
41    def __init__(self) -> None:
42        return None  # pragma: no cover
43
44    @staticmethod
45    def new(
46        table_type: str, storage_provider: object,
47        start_sector: int = None, extended_layout: bool = False
48    ):
49        name_map = {
50            'msdos': 'MsDos',
51            'gpt': 'Gpt',
52            'dasd': 'Dasd'
53        }
54        try:
55            partitioner = importlib.import_module(
56                'kiwi.partitioner.{0}'.format(table_type)
57            )
58            module_name = 'Partitioner{0}'.format(name_map[table_type])
59            if table_type == 'dasd' and start_sector:
60                log.warning(
61                    'disk start_sector value is ignored for dasd partitions'
62                )
63                start_sector = None
64            return partitioner.__dict__[module_name](
65                storage_provider, start_sector, extended_layout
66            )
67        except Exception as issue:
68            raise KiwiPartitionerSetupError(
69                'Support for {0} partitioner not implemented: {1}'.format(
70                    table_type, issue
71                )
72            )
log = <Logger kiwi (DEBUG)>
class Partitioner:
32class Partitioner(metaclass=ABCMeta):
33    """
34    **Partitioner factory**
35
36    :param string table_type: Table type name
37    :param object storage_provider: Instance of class based on DeviceProvider
38    :param int start_sector: sector number
39    :param bool extended_layout: support extended layout for msdos table
40    """
41    @abstractmethod
42    def __init__(self) -> None:
43        return None  # pragma: no cover
44
45    @staticmethod
46    def new(
47        table_type: str, storage_provider: object,
48        start_sector: int = None, extended_layout: bool = False
49    ):
50        name_map = {
51            'msdos': 'MsDos',
52            'gpt': 'Gpt',
53            'dasd': 'Dasd'
54        }
55        try:
56            partitioner = importlib.import_module(
57                'kiwi.partitioner.{0}'.format(table_type)
58            )
59            module_name = 'Partitioner{0}'.format(name_map[table_type])
60            if table_type == 'dasd' and start_sector:
61                log.warning(
62                    'disk start_sector value is ignored for dasd partitions'
63                )
64                start_sector = None
65            return partitioner.__dict__[module_name](
66                storage_provider, start_sector, extended_layout
67            )
68        except Exception as issue:
69            raise KiwiPartitionerSetupError(
70                'Support for {0} partitioner not implemented: {1}'.format(
71                    table_type, issue
72                )
73            )

Partitioner factory

Parameters
  • string table_type: Table type name
  • object storage_provider: Instance of class based on DeviceProvider
  • int start_sector: sector number
  • bool extended_layout: support extended layout for msdos table
@staticmethod
def new( table_type: str, storage_provider: object, start_sector: int = None, extended_layout: bool = False):
45    @staticmethod
46    def new(
47        table_type: str, storage_provider: object,
48        start_sector: int = None, extended_layout: bool = False
49    ):
50        name_map = {
51            'msdos': 'MsDos',
52            'gpt': 'Gpt',
53            'dasd': 'Dasd'
54        }
55        try:
56            partitioner = importlib.import_module(
57                'kiwi.partitioner.{0}'.format(table_type)
58            )
59            module_name = 'Partitioner{0}'.format(name_map[table_type])
60            if table_type == 'dasd' and start_sector:
61                log.warning(
62                    'disk start_sector value is ignored for dasd partitions'
63                )
64                start_sector = None
65            return partitioner.__dict__[module_name](
66                storage_provider, start_sector, extended_layout
67            )
68        except Exception as issue:
69            raise KiwiPartitionerSetupError(
70                'Support for {0} partitioner not implemented: {1}'.format(
71                    table_type, issue
72                )
73            )