includehandler: Fold GlobalIncludes into IncludeHandler class
No user for this abstraction in sight. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
parent
76e7339fdb
commit
5c28272d73
@ -57,10 +57,10 @@ class Config:
|
||||
Implements the kas configuration based on config files.
|
||||
"""
|
||||
def __init__(self, filename, target, task=None):
|
||||
from .includehandler import GlobalIncludes
|
||||
from .includehandler import IncludeHandler
|
||||
self._config = {}
|
||||
self.filename = os.path.abspath(filename)
|
||||
self.handler = GlobalIncludes(self.filename)
|
||||
self.handler = IncludeHandler(self.filename)
|
||||
self.repo_dict = self._get_repo_dict()
|
||||
self.context = None
|
||||
|
||||
|
@ -104,7 +104,20 @@ class IncludeException(Exception):
|
||||
|
||||
class IncludeHandler:
|
||||
"""
|
||||
Abstract class that defines the interface of an include handler.
|
||||
Implements a handler where every configuration file should
|
||||
contain a dictionary as the base type with and 'includes'
|
||||
key containing a list of includes.
|
||||
|
||||
The includes can be specified in two ways, as a string
|
||||
containing the relative path from the current file or as a
|
||||
dictionary. The dictionary should have a 'file' key, containing
|
||||
the relative path to the include file and optionally a 'repo'
|
||||
key, containing the key of the repository. If the 'repo' key is
|
||||
missing the value of the 'file' key is treated the same as if
|
||||
just a string was defined, meaning the path is relative to the
|
||||
current config file otherwise its relative to the repository path.
|
||||
|
||||
The includes are read and merged depth first from top to buttom.
|
||||
"""
|
||||
|
||||
def __init__(self, top_file):
|
||||
@ -121,31 +134,7 @@ class IncludeHandler:
|
||||
repos -- A list of missing repo names that are needed \
|
||||
to create a complete configuration
|
||||
"""
|
||||
# pylint: disable=no-self-use,unused-argument
|
||||
|
||||
logging.error('get_config is not implemented')
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class GlobalIncludes(IncludeHandler):
|
||||
"""
|
||||
Implements a handler where every configuration file should
|
||||
contain a dictionary as the base type with and 'includes'
|
||||
key containing a list of includes.
|
||||
|
||||
The includes can be specified in two ways, as a string
|
||||
containg the relative path from the current file or as a
|
||||
dictionary. The dictionary should have a 'file' key, containing
|
||||
the relative path to the include file and optionally a 'repo'
|
||||
key, containing the key of the repository. If the 'repo' key is
|
||||
missing the value of the 'file' key is threated the same as if
|
||||
just a string was defined, meaning the path is relative to the
|
||||
current config file otherwise its relative to the repository path.
|
||||
|
||||
The includes are read and merged depth first from top to buttom.
|
||||
"""
|
||||
|
||||
def get_config(self, repos=None):
|
||||
repos = repos or {}
|
||||
|
||||
def _internal_include_handler(filename):
|
||||
|
@ -129,7 +129,7 @@ class TestLoadConfig:
|
||||
includehandler.load_config('x.yml')
|
||||
|
||||
|
||||
class TestGlobalIncludes:
|
||||
class TestIncludes:
|
||||
header = '''
|
||||
header:
|
||||
version: 5
|
||||
@ -140,7 +140,7 @@ header:
|
||||
monkeypatch.setattr(includehandler, 'CONFIGSCHEMA', {})
|
||||
for test in testvector:
|
||||
with patch_open(includehandler, dictionary=test['fdict']):
|
||||
ginc = includehandler.GlobalIncludes('x.yml')
|
||||
ginc = includehandler.IncludeHandler('x.yml')
|
||||
config, missing = ginc.get_config(repos=test['rdict'])
|
||||
|
||||
# Remove header, because we dont want to compare it:
|
||||
@ -348,7 +348,7 @@ v: {v2: y, v3: y, v5: y}'''),
|
||||
os.path.abspath('z.yml'): header.format('''
|
||||
v: {v3: z, v4: z}''')}
|
||||
with patch_open(includehandler, dictionary=data):
|
||||
ginc = includehandler.GlobalIncludes('x.yml')
|
||||
ginc = includehandler.IncludeHandler('x.yml')
|
||||
config, _ = ginc.get_config()
|
||||
keys = list(config['v'].keys())
|
||||
index = {keys[i]: i for i in range(len(keys))}
|
||||
|
Loading…
Reference in New Issue
Block a user