From: Clark Williams on gitlab.com Merge Request: https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2117
Replace the (still functioning) merge.pl in redhat/configs with a python version (merge.py) for ease of maintenance.
Signed-off-by: Clark Williams williams@redhat.com
--- redhat/configs/build_configs.sh | 2 +- redhat/configs/merge.py | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletions(-)
From: Clark Williams williams@redhat.com
redhat: python replacement for merge.pl
Replace the (still functioning) merge.pl in redhat/configs with a python version (merge.py) for ease of maintenance.
Signed-off-by: Clark Williams williams@redhat.com
diff --git a/redhat/configs/build_configs.sh b/redhat/configs/build_configs.sh index blahblah..blahblah 100755 --- a/redhat/configs/build_configs.sh +++ b/redhat/configs/build_configs.sh @@ -84,7 +84,7 @@ function merge_configs()
test -n "$skip_if_missing" && test ! -e "$cfile" && continue
- if ! perl merge.pl "$cfile" config-merging."$count" > config-merged."$count"; then + if ! ./merge.py "$cfile" config-merging."$count" > config-merged."$count"; then die "Failed to merge $cfile" fi mv config-merged."$count" config-merging."$count" diff --git a/redhat/configs/merge.py b/redhat/configs/merge.py new file mode 100755 index blahblah..blahblah 100755 --- /dev/null +++ b/redhat/configs/merge.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: GPL-2.0 +# Author: Clark Williams williams@redhat.com +# Copyright (C) 2022 Red Hat, Inc. +# +# merge.py - a direct replacement for merge.pl in the redhat/configs directory +# +# invocation: python merge.py overrides baseconfig +# +# Both input files are kernel config files, where overides is config overides +# to the baseconfig file. Both are read into python dictionaries with the +# keys being the config name and the values being the config file text + +# The script iterates through the overrides keys adding/replacing the contents +# of the baseconfig values and then outputs the new baseconfig to stdout. +# + +import sys +import os.path + +def usage(msg): + print(msg) + print("usage: merge.py overrides baseconfig") + sys.exit(1) + +# read a config file and return a dictionary of the contents +def read_config_file(cfgfile): + configs = {} + for l in open(cfgfile).readlines(): + if len(l) == 0: continue + if l.startswith("# CONFIG_"): + configs[l.split()[1]] = l + continue + if l.startswith("CONFIG_"): + configs[l.split('=')[0]] = l + continue + return configs + + +if len(sys.argv) < 3: usage("must have two input files") + +# read in the overides file +if not os.path.exists(sys.argv[1]): + usage("overrides config file %s does not exist!" % sys.argv[1]) +overrides = read_config_file(sys.argv[1]) + +# read in the base config file +if not os.path.exists(sys.argv[2]): + usage("base config file %s does not exist!" % sys.argv[2]) +baseconfigs = read_config_file(sys.argv[2]) + +# iterate over the overrides, replacing values in the base config +for v in overrides.keys(): + baseconfigs[v] = overrides[v] + +# print the new config to stdout +for v in baseconfigs.keys(): + print(baseconfigs[v])
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2117
From: Clark Williams williams@redhat.com
redhat: automatically strip newlines in merge.py
When reading configfiles call strip() to remove newlines, so that we can easily find blank lines
Signed-off-by: Clark Williams williams@redhat.com
diff --git a/redhat/configs/merge.py b/redhat/configs/merge.py index blahblah..blahblah 100755 --- a/redhat/configs/merge.py +++ b/redhat/configs/merge.py @@ -26,7 +26,7 @@ def usage(msg): # read a config file and return a dictionary of the contents def read_config_file(cfgfile): configs = {} - for l in open(cfgfile).readlines(): + for l in [ n.strip() for n in open(cfgfile).readlines()]: if len(l) == 0: continue if l.startswith("# CONFIG_"): configs[l.split()[1]] = l
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2117
From: Patrick Talbert ptalbert@redhat.com
redhat: Use a context manager in merge.py for opening the config file for reading
Signed-off-by: Clark Williams williams@redhat.com
diff --git a/redhat/configs/merge.py b/redhat/configs/merge.py index blahblah..blahblah 100755 --- a/redhat/configs/merge.py +++ b/redhat/configs/merge.py @@ -26,14 +26,15 @@ def usage(msg): # read a config file and return a dictionary of the contents def read_config_file(cfgfile): configs = {} - for l in [ n.strip() for n in open(cfgfile).readlines()]: - if len(l) == 0: continue - if l.startswith("# CONFIG_"): - configs[l.split()[1]] = l - continue - if l.startswith("CONFIG_"): - configs[l.split('=')[0]] = l - continue + with open(cfgfile) as f: + for l in [n.strip() for n in f.readlines()]: + if not l: continue + if l.startswith("# CONFIG_"): + configs[l.split()[1]] = l + continue + if l.startswith("CONFIG_"): + configs[l.split('=')[0]] = l + continue return configs
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2117
From: Patrick Talbert ptalbert@redhat.com
redhat: use 'update' method in merge.py
Use the update method to update our baseconfigs dictionary rather than iterating
Signed-off-by: Clark Williams williams@redhat.com
diff --git a/redhat/configs/merge.py b/redhat/configs/merge.py index blahblah..blahblah 100755 --- a/redhat/configs/merge.py +++ b/redhat/configs/merge.py @@ -50,9 +50,8 @@ if not os.path.exists(sys.argv[2]): usage("base config file %s does not exist!" % sys.argv[2]) baseconfigs = read_config_file(sys.argv[2])
-# iterate over the overrides, replacing values in the base config -for v in overrides.keys(): - baseconfigs[v] = overrides[v] +# update baseconfigs with the overrides values +baseconfigs.update(overrides)
# print the new config to stdout for v in baseconfigs.keys():
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2117
From: Patrick Talbert ptalbert@redhat.com
redhat: method.py: change the output loop to use 'values' method
We don't need the key values when printing the output file so just use the values method to fetch them
Signed-off-by: Clark Williams williams@redhat.com
diff --git a/redhat/configs/merge.py b/redhat/configs/merge.py index blahblah..blahblah 100755 --- a/redhat/configs/merge.py +++ b/redhat/configs/merge.py @@ -54,5 +54,5 @@ baseconfigs = read_config_file(sys.argv[2]) baseconfigs.update(overrides)
# print the new config to stdout -for v in baseconfigs.keys(): - print(baseconfigs[v]) +for v in baseconfigs.values(): + print(v)
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2117
From: Clark Williams on gitlab.com https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2117#note_1151697...
Backed out the specfile BuildRequires and modified merge.py to be executable and have a shbang of /usr/bin/python3, modified build_configs.sh to execute ./merge.py rather than calling python.
kernel@lists.fedoraproject.org