From b107a6011847e41eadd76ffe4e9557b0621332c5 Mon Sep 17 00:00:00 2001 From: Paul Barker Date: Sat, 4 Jul 2020 09:53:39 +0200 Subject: [PATCH] config: Allow a default repo to be specified for patches Signed-off-by: Paul Barker [Jan: style fix] Signed-off-by: Jan Kiszka --- docs/format-changelog.rst | 5 +++-- docs/userguide.rst | 10 ++++++++++ kas/configschema.py | 11 ++++++++++- kas/repos.py | 19 ++++++++++++++----- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/docs/format-changelog.rst b/docs/format-changelog.rst index ecb0a61..7b3167f 100644 --- a/docs/format-changelog.rst +++ b/docs/format-changelog.rst @@ -83,5 +83,6 @@ Added ~~~~~ - ``defaults`` key can now be used to set a default value for the repository - property ``refspec``. This default value will be used if the appropriate - property is not defined for a given repository. + property ``refspec`` and the repository patch property ``repo``. These + default values will be used if the appropriate properties are not defined + for a given repository or patch. diff --git a/docs/userguide.rst b/docs/userguide.rst index e67857f..ab43cef 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -326,6 +326,16 @@ Configuration reference Sets the default ``refspec`` property applied to all repositories that do not override this. + * ``patches``: dict [optional] + This key can contain default values for some repository patch + properties. If a default value is set for a patch property it may + still be overridden by setting the same property to a different value + in a given patch. + + * ``repo``: string [optional] + Sets the default ``repo`` property applied to all repository + patches that do not override this. + * ``machine``: string [optional] Contains the value of the ``MACHINE`` variable that is written into the ``local.conf``. Can be overwritten by the ``KAS_MACHINE`` environment diff --git a/kas/configschema.py b/kas/configschema.py index 89522e8..da4d098 100644 --- a/kas/configschema.py +++ b/kas/configschema.py @@ -83,6 +83,15 @@ CONFIGSCHEMA = { 'refspec': { 'type': 'string', }, + 'patches': { + 'type': 'object', + 'additionalProperties': False, + 'properties': { + 'repo': { + 'type': 'string', + }, + }, + }, }, }, }, @@ -164,7 +173,7 @@ CONFIGSCHEMA = { { 'type': 'object', 'additionalProperties': False, - 'required': ['repo', 'path'], + 'required': ['path'], 'properties': { 'repo': { 'type': 'string' diff --git a/kas/repos.py b/kas/repos.py index a4dbb1c..fa10c0b 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -25,6 +25,7 @@ import re import os +import sys import logging from urllib.parse import urlparse from .context import get_context @@ -87,15 +88,23 @@ class Repo: str(laydict[x]).lower() not in ['disabled', 'excluded', 'n', 'no', '0', 'false'], layers_dict)) + default_patch_repo = repo_defaults.get('patches', {}).get('repo', None) patches_dict = repo_config.get('patches', {}) - patches = list( - { + patches = [] + for p in sorted(patches_dict): + if not patches_dict[p]: + continue + this_patch = { 'id': p, - 'repo': patches_dict[p]['repo'], + 'repo': patches_dict[p].get('repo', default_patch_repo), 'path': patches_dict[p]['path'], } - for p in sorted(patches_dict) - if patches_dict[p]) + if this_patch['repo'] is None: + logging.error('No repo specified for patch entry "%s" and no ' + 'default repo specified.', p) + sys.exit(1) + patches.append(this_patch) + url = repo_config.get('url', None) name = repo_config.get('name', name) typ = repo_config.get('type', 'git')