Skip to content

Commit 9d0b3f7

Browse files
committed
Add ability to define DLRN driver in INI config file
We set 'downstream_driver' as default value for 'driver' key.
1 parent d81ca9a commit 9d0b3f7

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

patch_rebaser/patch_rebaser.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def create_patches_branch(repo, commit, remote, dev_mode=True):
6969
return branch_name
7070

7171

72-
def get_downstream_distgit_branch(dlrn_projects_ini):
72+
def get_downstream_distgit_branch(dlrn_projects_ini, driver):
7373
"""Get downstream distgit branch info from DLRN projects.ini"""
7474
config = configparser.ConfigParser()
7575
config.read(dlrn_projects_ini)
76-
return config.get('downstream_driver', 'downstream_distro_branch')
76+
return config.get(driver, 'downstream_distro_branch')
7777

7878

79-
def get_patches_branch(repo, remote, dlrn_projects_ini):
79+
def get_patches_branch(repo, remote, dlrn_projects_ini, driver):
8080
"""Get the patches branch name"""
8181
branch_name = os.environ.get('PATCHES_BRANCH', None)
8282
if branch_name:
@@ -87,7 +87,8 @@ def get_patches_branch(repo, remote, dlrn_projects_ini):
8787
return None
8888
else:
8989
# Get downstream distgit branch from DLRN config
90-
distgit_branch = get_downstream_distgit_branch(dlrn_projects_ini)
90+
distgit_branch = get_downstream_distgit_branch(dlrn_projects_ini,
91+
driver)
9192
LOGGER.warning("No PATCHES_BRANCH env var found, trying to guess it")
9293
# Guess at patches branch based on the distgit branch name
9394
return find_patches_branch(repo, remote, distgit_branch)
@@ -188,7 +189,7 @@ def get_rebaser_config(defaults=None):
188189
"""
189190
default_options = ['dev_mode', 'remote_name', 'git_name', 'git_email',
190191
'packages_to_process', 'dlrn_projects_ini',
191-
'create_patches_branch']
192+
'create_patches_branch', 'driver']
192193
distroinfo_options = ['patches_repo_key']
193194

194195
RebaserConfig = namedtuple('RebaserConfig',
@@ -426,6 +427,7 @@ def main():
426427

427428
# Default values for options in patch_rebaser.ini
428429
defaults = {
430+
'driver': 'downstream_driver',
429431
'remote_name': 'remote_name',
430432
'git_name': 'Your Name',
431433
'git_email': 'you@example.com',
@@ -469,7 +471,8 @@ def main():
469471
# Create local patches branch
470472
branch_name = get_patches_branch(repo,
471473
config.remote_name,
472-
config.dlrn_projects_ini)
474+
config.dlrn_projects_ini,
475+
config.driver)
473476

474477
# Not every project has a -patches branch for every release
475478
if not branch_name:

tests/test_patch_rebaser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ def test_get_rebaser_config_with_fallback_value(mock_config):
306306
AND an option doesn't exist in the config
307307
THEN the value from the dictionary is returned
308308
"""
309-
defaults = {'git_name': 'TEST', 'remote_name': 'Wrong_name'}
309+
defaults = {'git_name': 'TEST',
310+
'remote_name': 'Wrong_name',
311+
'driver': 'downstream_driver'}
310312
config = get_rebaser_config(defaults)
311313

312314
assert config.git_name == defaults['git_name']
@@ -319,7 +321,9 @@ def test_get_rebaser_config_defaults_dont_override_ini_values(mock_config):
319321
AND an option exists both in the ini config and the defaults dictionary
320322
THEN the value from the ini config is returned
321323
"""
322-
defaults = {'git_name': 'TEST', 'remote_name': 'Wrong_name'}
324+
defaults = {'git_name': 'TEST',
325+
'remote_name': 'Wrong_name',
326+
'driver': 'downstream_driver'}
323327
config = get_rebaser_config(defaults)
324328

325329
assert config.remote_name == "test_remote_name"

0 commit comments

Comments
 (0)