aboutsummaryrefslogtreecommitdiff
path: root/tools/patman/settings.py
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-12-20 00:38:41 -0500
committerSimon Glass <sjg@chromium.org>2023-01-05 19:21:57 -0700
commit8f8d3f72f28732bff0dc6362a18e3ec55fba2ac1 (patch)
treec394a22cfbba42891732f9d27f94428164da53a4 /tools/patman/settings.py
parentdb16edd8ced27c06c075999ef95c6a1a57db98e0 (diff)
downloadu-boot-8f8d3f72f28732bff0dc6362a18e3ec55fba2ac1.zip
u-boot-8f8d3f72f28732bff0dc6362a18e3ec55fba2ac1.tar.gz
u-boot-8f8d3f72f28732bff0dc6362a18e3ec55fba2ac1.tar.bz2
patman: additionally honor a local .patman config file
This enables versioning a project specific patman configuration file. It also makes it possible to declare the project name, which is not a useful thing to do in $HOME/.patman. A new test is added, along updated documentation. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/settings.py')
-rw-r--r--tools/patman/settings.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/tools/patman/settings.py b/tools/patman/settings.py
index c05efd2..636983e 100644
--- a/tools/patman/settings.py
+++ b/tools/patman/settings.py
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2011 The Chromium OS Authors.
+# Copyright (c) 2022 Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
#
try:
@@ -336,6 +337,12 @@ def GetItems(config, section):
def Setup(parser, project_name, config_fname=None):
"""Set up the settings module by reading config files.
+ Unless `config_fname` is specified, a `.patman` config file local
+ to the git repository is consulted, followed by the global
+ `$HOME/.patman`. If none exists, the later is created. Values
+ defined in the local config file take precedence over those
+ defined in the global one.
+
Args:
parser: The parser to update.
project_name: Name of project that we're working on; we'll look
@@ -352,12 +359,21 @@ def Setup(parser, project_name, config_fname=None):
if not config_fname:
config_fname = '%s/.patman' % os.getenv('HOME')
+ has_config = os.path.exists(config_fname)
- if not os.path.exists(config_fname):
- print("No config file found ~/.patman\nCreating one...\n")
- CreatePatmanConfigFile(config_fname)
+ git_local_config_fname = os.path.join(gitutil.get_top_level(), '.patman')
+ has_git_local_config = os.path.exists(git_local_config_fname)
- config.read(config_fname)
+ # Read the git local config last, so that its values override
+ # those of the global config, if any.
+ if has_config:
+ config.read(config_fname)
+ if has_git_local_config:
+ config.read(git_local_config_fname)
+
+ if not (has_config or has_git_local_config):
+ print("No config file found.\nCreating ~/.patman...\n")
+ CreatePatmanConfigFile(config_fname)
for name, value in GetItems(config, 'alias'):
alias[name] = value.split(',')