kiwi.markup

 1# Copyright (c) 2020 SUSE LLC.  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 KiwiAnyMarkupPluginError
27
28log = logging.getLogger('kiwi')
29
30
31class Markup(metaclass=ABCMeta):
32    """
33    **Markup factory**
34
35    :param str description: path to description file
36    """
37    @abstractmethod
38    def __init__(self) -> None:
39        return None  # pragma: no cover
40
41    @staticmethod
42    def new(description: str, name: str='any'):  # noqa: E252
43        try:
44            markup = Markup._load_markup_by_name(name, description)
45            log.info('Support for multiple markup descriptions available')
46        except KiwiAnyMarkupPluginError:
47            markup = Markup._load_markup_by_name('xml', description)
48            log.info('Support for XML markup available')
49        return markup
50
51    @staticmethod
52    def _load_markup_by_name(name, description):
53        name_map = {
54            'any': 'Any',
55            'xml': 'XML'
56        }
57        markup = importlib.import_module('kiwi.markup.{0}'.format(name))
58        return markup.__dict__['Markup{0}'.format(name_map[name])](
59            description
60        )
log = <Logger kiwi (DEBUG)>
class Markup:
32class Markup(metaclass=ABCMeta):
33    """
34    **Markup factory**
35
36    :param str description: path to description file
37    """
38    @abstractmethod
39    def __init__(self) -> None:
40        return None  # pragma: no cover
41
42    @staticmethod
43    def new(description: str, name: str='any'):  # noqa: E252
44        try:
45            markup = Markup._load_markup_by_name(name, description)
46            log.info('Support for multiple markup descriptions available')
47        except KiwiAnyMarkupPluginError:
48            markup = Markup._load_markup_by_name('xml', description)
49            log.info('Support for XML markup available')
50        return markup
51
52    @staticmethod
53    def _load_markup_by_name(name, description):
54        name_map = {
55            'any': 'Any',
56            'xml': 'XML'
57        }
58        markup = importlib.import_module('kiwi.markup.{0}'.format(name))
59        return markup.__dict__['Markup{0}'.format(name_map[name])](
60            description
61        )

Markup factory

Parameters
  • str description: path to description file
@staticmethod
def new(description: str, name: str = 'any'):
42    @staticmethod
43    def new(description: str, name: str='any'):  # noqa: E252
44        try:
45            markup = Markup._load_markup_by_name(name, description)
46            log.info('Support for multiple markup descriptions available')
47        except KiwiAnyMarkupPluginError:
48            markup = Markup._load_markup_by_name('xml', description)
49            log.info('Support for XML markup available')
50        return markup