From 3205fd5bbdda451532df0db18d53b08589400d73 Mon Sep 17 00:00:00 2001 From: Joel Capitao Date: Fri, 5 Apr 2024 17:58:07 +0200 Subject: [PATCH] Add ability to define DLRN driver in INI config file Currently, the patch_rebaser script only gets parameter from 'downstream_driver' section of the DLRN projects.ini file, which is hardcoded [1]. This patch aims to add support of defining the driver, thus the INI section, where we want to get the 'downstream_distro_branch' value. We set 'downstream_driver' as default value for 'dlrn_driver' key. [1] https://github.com/release-depot/patch_rebaser/blob/d81ca9a64acb6c0b8638373c3aea2ca15e796a77/patch_rebaser/patch_rebaser.py#L76 --- patch_rebaser/patch_rebaser.ini.example | 3 +++ patch_rebaser/patch_rebaser.py | 15 +++++++++------ tests/test_patch_rebaser.py | 8 ++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/patch_rebaser/patch_rebaser.ini.example b/patch_rebaser/patch_rebaser.ini.example index da882d0..686d689 100644 --- a/patch_rebaser/patch_rebaser.ini.example +++ b/patch_rebaser/patch_rebaser.ini.example @@ -9,6 +9,9 @@ git_email = you@example.com packages_to_process = # Location of DLRN projects.ini file (optional) dlrn_projects_ini = +# DLRN driver used, in order to get the parameters from the right +# section of the DLRN projects.ini file. (optional) +dlrn_driver = # Do not force-push to remotes or do other destructive operations # while in development mode dev_mode = true diff --git a/patch_rebaser/patch_rebaser.py b/patch_rebaser/patch_rebaser.py index b2b775d..6c0a48b 100755 --- a/patch_rebaser/patch_rebaser.py +++ b/patch_rebaser/patch_rebaser.py @@ -69,14 +69,14 @@ def create_patches_branch(repo, commit, remote, dev_mode=True): return branch_name -def get_downstream_distgit_branch(dlrn_projects_ini): +def get_downstream_distgit_branch(dlrn_projects_ini, dlrn_driver): """Get downstream distgit branch info from DLRN projects.ini""" config = configparser.ConfigParser() config.read(dlrn_projects_ini) - return config.get('downstream_driver', 'downstream_distro_branch') + return config.get(dlrn_driver, 'downstream_distro_branch') -def get_patches_branch(repo, remote, dlrn_projects_ini): +def get_patches_branch(repo, remote, dlrn_projects_ini, dlrn_driver): """Get the patches branch name""" branch_name = os.environ.get('PATCHES_BRANCH', None) if branch_name: @@ -87,7 +87,8 @@ def get_patches_branch(repo, remote, dlrn_projects_ini): return None else: # Get downstream distgit branch from DLRN config - distgit_branch = get_downstream_distgit_branch(dlrn_projects_ini) + distgit_branch = get_downstream_distgit_branch(dlrn_projects_ini, + dlrn_driver) LOGGER.warning("No PATCHES_BRANCH env var found, trying to guess it") # Guess at patches branch based on the distgit branch name return find_patches_branch(repo, remote, distgit_branch) @@ -188,7 +189,7 @@ def get_rebaser_config(defaults=None): """ default_options = ['dev_mode', 'remote_name', 'git_name', 'git_email', 'packages_to_process', 'dlrn_projects_ini', - 'create_patches_branch'] + 'create_patches_branch', 'dlrn_driver'] distroinfo_options = ['patches_repo_key'] RebaserConfig = namedtuple('RebaserConfig', @@ -426,6 +427,7 @@ def main(): # Default values for options in patch_rebaser.ini defaults = { + 'dlrn_driver': 'downstream_driver', 'remote_name': 'remote_name', 'git_name': 'Your Name', 'git_email': 'you@example.com', @@ -469,7 +471,8 @@ def main(): # Create local patches branch branch_name = get_patches_branch(repo, config.remote_name, - config.dlrn_projects_ini) + config.dlrn_projects_ini, + config.dlrn_driver) # Not every project has a -patches branch for every release if not branch_name: diff --git a/tests/test_patch_rebaser.py b/tests/test_patch_rebaser.py index fc20d61..547cfb6 100644 --- a/tests/test_patch_rebaser.py +++ b/tests/test_patch_rebaser.py @@ -306,10 +306,12 @@ def test_get_rebaser_config_with_fallback_value(mock_config): AND an option doesn't exist in the config THEN the value from the dictionary is returned """ - defaults = {'git_name': 'TEST', 'remote_name': 'Wrong_name'} + defaults = {'git_name': 'TEST', + 'dlrn_driver': 'downstream_driver'} config = get_rebaser_config(defaults) assert config.git_name == defaults['git_name'] + assert config.dlrn_driver == defaults['dlrn_driver'] def test_get_rebaser_config_defaults_dont_override_ini_values(mock_config): @@ -319,7 +321,9 @@ def test_get_rebaser_config_defaults_dont_override_ini_values(mock_config): AND an option exists both in the ini config and the defaults dictionary THEN the value from the ini config is returned """ - defaults = {'git_name': 'TEST', 'remote_name': 'Wrong_name'} + defaults = {'git_name': 'TEST', + 'dlrn_driver': 'downstream_driver', + 'remote_name': 'Wrong_name'} config = get_rebaser_config(defaults) assert config.remote_name == "test_remote_name"