repos: move more of the complexity from config to Repo.factory

This commit just moved some code around, to a place where it seems to
fit better.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
This commit is contained in:
Henning Schild 2018-01-05 16:00:29 +01:00 committed by Daniel Wagner
parent 0c7db599fd
commit 6a85296836
2 changed files with 27 additions and 32 deletions

View File

@ -177,38 +177,9 @@ class Config:
repo_config_dict = self._config.get('repos', {})
repo_dict = {}
for repo in repo_config_dict:
repo_config_dict[repo] = repo_config_dict[repo] or {}
layers_dict = repo_config_dict[repo].get('layers', {})
layers = list(filter(lambda x, laydict=layers_dict:
str(laydict[x]).lower() not in
['disabled', 'excluded', 'n', 'no', '0',
'false'],
layers_dict))
url = repo_config_dict[repo].get('url', None)
name = repo_config_dict[repo].get('name', repo)
typ = repo_config_dict[repo].get('type', 'git')
refspec = repo_config_dict[repo].get('refspec', None)
path = repo_config_dict[repo].get('path', None)
dis_ops = False
repo_dict[repo] = Repo.factory(repo, repo_config_dict[repo], self)
if url is None:
# No git operation on repository
if path is None:
path = Repo.get_root_path(os.path.dirname(self.filename),
self.environ)
logging.info('Using %s as root for repository %s', path,
name)
url = path
dis_ops = True
else:
path = path or os.path.join(self.kas_work_dir, name)
rep = Repo.factory(url=url, path=path, typ=typ,
refspec=refspec, layers=layers,
disable_operations=dis_ops)
repo_dict[repo] = rep
return repo_dict
def get_bitbake_targets(self):

View File

@ -69,11 +69,35 @@ class Repo:
self.path, self._layers)
@staticmethod
def factory(url, path, typ, refspec, layers, disable_operations):
def factory(name, repo_config, config):
"""
Return an instance Repo depending on params.
"""
# pylint: disable=too-many-arguments
layers_dict = repo_config.get('layers', {})
layers = list(filter(lambda x, laydict=layers_dict:
str(laydict[x]).lower() not in
['disabled', 'excluded', 'n', 'no', '0', 'false'],
layers_dict))
url = repo_config.get('url', None)
name = repo_config.get('name', name)
typ = repo_config.get('type', 'git')
refspec = repo_config.get('refspec', None)
path = repo_config.get('path', None)
disable_operations = False
if url is None:
# No git operation on repository
if path is None:
path = Repo.get_root_path(os.path.dirname(config.filename),
config.environ)
logging.info('Using %s as root for repository %s', path,
name)
url = path
disable_operations = True
else:
path = path or os.path.join(config.kas_work_dir, name)
if typ == 'git':
return GitRepo(url, path, refspec, layers, disable_operations)
raise NotImplementedError('Repo typ "%s" not supported.' % typ)