[PATCH RFC 5/8] aiaiai-email: add [defaults] section to config

Keller, Jacob E jacob.e.keller at intel.com
Thu Mar 6 17:29:09 PST 2014


This patch adds a [defaults] section for the configuration file which
allows setting shared project settings which might be overridden
per-project. This will be used more in a follow-on patch which adds
additional configuration options.

Signed-off-by: Jacob Keller <jacob.e.keller at intel.com>
---
 doc/email/example-aiaiai.cfg    | 68 ++++++++++++++++++-----------
 email/aiaiai-email-sh-functions | 97 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 133 insertions(+), 32 deletions(-)

diff --git a/doc/email/example-aiaiai.cfg b/doc/email/example-aiaiai.cfg
index 4a0b611ecb36..f921e611166c 100644
--- a/doc/email/example-aiaiai.cfg
+++ b/doc/email/example-aiaiai.cfg
@@ -38,26 +38,10 @@
 	# aiaiai will insert it for you.
 	built_preamble = I have tested your changes
 
-# The e-mail front-end may operate on several project. Each project has its
-# own kernel tree, kernel configuration, and some other settings. These are
-# configured in per-project sections. Section names have to start with "prj_"
-# and follow with the name of the project.
-
-# This is the "android" project section.
-[prj_android]
-	# Human-readable project name
-	name = Android
-
-	# Short, one line project description. Start it with a small letter.
-	description = the Android x86 kernel
-
-	# Path to the kernel tree of the project. Note, Aiaiai does treats this
-	# directory as read-only and never changes anything there. This means
-	# that you have to keep it up-to-date with other means. For example, you
-	# may setup a cron job which will periodically execute 'git fetch -f' in
-	# this directory in order to get the newest contents from the server.
-	path = /home/aiaiai/work/git/android-x86
-
+# The "defaults" section specifies various default settings for projects. These
+# values are overridden by the same values in the prj_* sections, so you may
+# customize the settings per project if desired.
+[defaults]
 	# The kernel configurations to test. You may specify more than one
 	# configuration using blanks as a delimiter. The configuration consists
 	# of the following comma-separated components: the defconfig file to
@@ -69,26 +53,27 @@
 	#
 	# means: use the "omap2_defconfig" defconfig, use ARCH="arm", use
 	# CROSS_COMPILE="arm-eabi-". The last component is optional.
-	configs = android_defconfig,i386 android_debug_defconfig,i386
+	configs = x86_64_defconfig,x86_64 i386_defconfig,i386
 
 	# Git refspec to validate the patches against. Usually this a the
 	# remote branch name. But may actually be any refspec.
 	#
 	# Note, the defconfig files specified in the "configs" option must be
 	# part of this git refspec.
-	branch = origin/3.0-mid
+	branch = origin/master
 
 	# Comma-separated list of e-mail addresses to always CC when replying.
 	# These are maintainers or other project supervisors. This may be a
-	# separate mailing list for replies from Aiaiai.
-	always_cc = "Artem Bityutskiy" <artem.bityutskiy at fake.domain.com>, "Aiaiai archives" <aiaiai-archives at fake.comain.com>
+	# separate mailing list for replies from Aiaiai. This is not inclusive
+	# with the prj_* settings so be careful.
+	always_cc = "Aiaiai archives" <aiaiai-archives at fake.domain.com>
 
 	# Reply only to the sender (0) or to everyone in To: and Cc: (1)
 	reply_to_all = 0
 
 	# Notify the sender that his/her e-mail has been accepted by the Aiaiai
 	# front-end and put to the queue for validation.
-	accept_notify = 1
+	accept_notify = 0
 
 	# Path to the file containing unwanted keywords (one keyword per line).
 	# Aiaiai will check the patch against this list and notify if any of
@@ -101,4 +86,37 @@
 	# "make" command. For example, W=2 KALLSYMS_EXTRA_PASS=1.
 	kmake_opts =
 
+# The e-mail front-end may operate on several project. Each project has its
+# own kernel tree, kernel configuration, and some other settings. These are
+# configured in per-project sections. Section names have to start with "prj_"
+# and follow with the name of the project.
+
+# This is the "android" project section.
+[prj_android]
+	# Human-readable project name.
+	name = Android
+
+	# Short, one line project description. Start it with a small letter.
+	description = the Android x86 kernel
+
+	# Path to the kernel tree of the project. Note, Aiaiai does treats this
+	# directory as read-only and never changes anything there. This means
+	# that you have to keep it up-to-date with other means. For example,
+	# you may setup a cron job which will periodically execute 'git fetch
+	# -f' in this directory in order to get the newest contents from the
+	# server. No default value.
+	path = /home/aiaiai/work/git/android-x86
+
+	# All the options below override settings from the [defaults] section
+	# of the configuration file. Setting them to empty will ignore the
+	# configuration default and actually set it to the empty value. See the
+	# [defaults] section for more details on each option.
+	configs = android_defconfig,i386 android_debug_defconfig,i386
+	branch = origin/3.0-mid
+	always_cc =
+	reply_to_all = 1
+	accept_notify = 1
+	unwanted_keywords =
+	kmake_opts = W=2 KALLSYMS_EXTRA_PASS=1
+
 # More "prj_xyz" sections may be added
diff --git a/email/aiaiai-email-sh-functions b/email/aiaiai-email-sh-functions
index 2e815bbf995d..32ceacbb7886 100644
--- a/email/aiaiai-email-sh-functions
+++ b/email/aiaiai-email-sh-functions
@@ -121,6 +121,42 @@ merge_addresses()
 		                           -e "s/,\+$//" -e "s/[[:blank:]]\+/ /g"
 }
 
+# A helper function based on ini_config_get which returns 0 if the config
+# option is set, and 1 otherwise. Should be used in an if block. This is
+# required in order to distinquish between a variable which is set empty vs one
+# that is not set at all.
+ini_config_is_set()
+{
+	local fn section var sect= str eof= n v
+	fn="$1" section="$2" var="$3"
+
+	while [ -z "$eof" ]; do
+		read -r str || eof=1
+
+		case "$str" in
+			"["*"]")
+				[ "$str" != "[$section]" ] ||
+					sect=1
+				;;
+			"$shell_ini_config_comment"*|'')
+				;;
+			*)
+				if [ -n "$sect" ]; then
+					shell_var_trim n "${str%%=*}"
+
+					if [ "$n" = "$var" ]; then
+						# Return success, since we found match.
+						return 0
+					fi
+				fi
+				;;
+		esac
+	done < "$fn"
+
+	# We did not find match, so return failure.
+	return 1
+}
+
 # A helper function for 'ini_config_get()' (from libshell) which fails when
 # unable to get the ini file option.
 ini_config_get_or_die()
@@ -169,16 +205,48 @@ parse_config()
 	cfg_ownmail_domain="$(printf "%s" "$cfg_ownmail" | LC_ALL=C sed "s/.*@//g")"
 }
 
+# Parse the "defaults" section of the config file. The result is a set of
+# per-option variables and their values are exactly as in the configuration
+# file:
+#
+# _dcfg_configs, _dcfg_branch, _dcfg_always_cc, _dcfg_reply_to_all,
+# _dcfg_accept_notify, _dcfg_unwanted_keywords, _dcfg_kmake_opts
+#
+# It is expected that this is used internally by the parse_prj_config and
+# should not normally be called outside of this file.
+#
+# Usage: _parse_defaults_config <cfgfile>
+_parse_default_config()
+{
+	local cfgfile="$1"; shift
+
+	_dcfg_configs="$(ini_config_get "$cfgfile" "defaults" "configs")"
+	_dcfg_branch="$(ini_config_get "$cfgfile" "defaults" "branch")"
+	_dcfg_always_cc="$(ini_config_get "$cfgfile" "defaults" "always_cc")"
+	_dcfg_reply_to_all="$(ini_config_get "$cfgfile" "defaults" "reply_to_all")"
+	_dcfg_accept_notify="$(ini_config_get "$cfgfile" "defaults" "accept_notify")"
+	_dcfg_unwanted_keywords="$(ini_config_get "$cfgfile" "defaults" "unwanted_keywords")"
+	_dcfg_kmake_opts="$(ini_config_get "$cfgfile" "defaults" "kmake_opts")"
+}
+
 # Similar to "parse_config", but parses a project configuration section. If the
 # project is found, the following variables are defined:
 #
-# cfg_name. pcfg_description, pcfg_path, pcfg_configs, pcfg_branch,
-# pcfg_reply_to_all, pcfg_accept_notify, pcfg_always_cc,
-# pcfg_unwanted_keywords, and pcfg_kmake_opts.
+# pcfg_name, pcfg_description, and pcfg_path.
+#
+# The following variables are defined, but receive default values from the
+# [defaults] section, if they are not specified in the project section:
+#
+# pcfg_configs, pcfg_branch, pcfg_reply_to_all, pcfg_accept_notify,
+# pcfg_always_cc, pcfg_unwanted_keywords, and pcfg_kmake_opts.
 #
 # If the project is not found, this function only defined an empty "pcfg_name"
 # variable.
 #
+# Note, this function implicitly uses _parse_defaults_config to grab the
+# default configurations, and if the variable is not defined in the project
+# section, it will use the default value.
+#
 # Usage: parse_prj_config <cfgfile> <prj>
 parse_prj_config()
 {
@@ -190,14 +258,29 @@ parse_prj_config()
 
 	ini_config_get_or_die pcfg_description   "$cfgfile" "prj_$prj" "description"
 	ini_config_get_or_die pcfg_path          "$cfgfile" "prj_$prj" "path"
-	ini_config_get_or_die pcfg_configs       "$cfgfile" "prj_$prj" "configs"
-	ini_config_get_or_die pcfg_branch        "$cfgfile" "prj_$prj" "branch"
-	ini_config_get_or_die pcfg_reply_to_all  "$cfgfile" "prj_$prj" "reply_to_all"
-	ini_config_get_or_die pcfg_accept_notify "$cfgfile" "prj_$prj" "accept_notify"
 
+	# The following options all take default value from the "defaults"
+	# section, and hence "override" those settings. First we need to populate those.
+	_parse_default_config "$cfgfile"
+
+	# ini_config_is_set is important here, so that defining a value as
+	# empty in the project section actually does define it as empty, rather
+	# than using the default. This allows defaults to only be used if the
+	# project config does not specify anything.
+	pcfg_configs="$(ini_config_get "$cfgfile" "prj_$prj" "configs")"
+	ini_config_is_set "$cfgfile" "prj_$prj" "configs" || pcfg_configs="$_dcfg_configs"
+	pcfg_branch="$(ini_config_get "$cfgfile" "prj_$prj" "branch")"
+	ini_config_is_set "$cfgfile" "prj_$prj" "branch" || pcfg_branch="$_dcfg_branch"
+	pcfg_reply_to_all="$(ini_config_get "$cfgfile" "prj_$prj" "reply_to_all")"
+	ini_config_is_set "$cfgfile" "prj_$prj" "reply_to_all" || pcfg_reply_to_all="$_dcfg_reply_to_all"
+	pcfg_accept_notify="$(ini_config_get "$cfgfile" "prj_$prj" "accept_notify")"
+	ini_config_is_set "$cfgfile" "prj_$prj" "accept_notify" || pcfg_accept_notify="$_dcfg_accept_notify"
 	pcfg_always_cc="$(ini_config_get "$cfgfile" "prj_$prj" "always_cc")"
+	ini_config_is_set "$cfgfile" "prj_$prj" "always_cc" || pcfg_always_cc="$_dcfg_always_cc"
 	pcfg_unwanted_keywords="$(ini_config_get "$cfgfile" "prj_$prj" "unwanted_keywords")"
+	ini_config_is_set "$cfgfile" "prj_$prj" "unwanted_keywords" || pcfg_unwanted_keywords="$_dcfg_unwanted_keywords"
 	pcfg_kmake_opts="$(ini_config_get "$cfgfile" "prj_$prj" "kmake_opts")"
+	ini_config_is_set "$cfgfile" "prj_$prj" "kmake_opts" || pcfg_kmake_opts="$_dcfg_kmake_opts"
 }
 
 # Compose (but not send) e-mail reply. This function assumes that the following
-- 
1.8.3.1




More information about the aiaiai mailing list