From 15f3575b2ee51332e3be3302556f3821768057e4 Mon Sep 17 00:00:00 2001 From: Davide Madrisan Date: Wed, 14 Nov 2012 22:42:08 +0100 Subject: [PATCH] autospec, plugins: add the option '-C|--config' for selecting a different user configuration file or list of user configuration files Signed-off-by: Davide Madrisan --- ChangeLog | 5 +++++ autospec.in | 24 +++++++++++++++++------- lib/libcfg.lib.in | 38 +++++++++++++++++++++++++++----------- plugins/config-getvar.in | 30 +++++++++++++++--------------- plugins/pck-extract.in | 34 +++++++++++++++++++++------------- plugins/pck-update.in | 32 ++++++++++++++++++++------------ plugins/spec-create.in | 21 +++++++++++++++------ po/it/autospec_fe.po | 6 ++++++ po/it/config-getvar.po | 4 ++-- po/it/pck-extract.po | 9 +++++++++ po/it/pck-update.po | 9 +++++++++ po/it/spec-create.po | 12 +++++++++--- 12 files changed, 155 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index 396bc2c..07bc2e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,11 @@ Changes in version 1.14.3 * autospec - Davide Madrisan: Add some update debug messages. ++ improvement + * autospec, plugins/* - Davide Madrisan: + Add the option '-C|--config' for selecting a different user configuration + file or list of user configuration files. + ------------------------------------------------------------------------------- Changes in version 1.14.2 diff --git a/autospec.in b/autospec.in index 831ac7a..387c869 100644 --- a/autospec.in +++ b/autospec.in @@ -62,9 +62,12 @@ function autospec.usage() { -h, --help "$"Print this help, then exit"" -V, --version "$"Print version number, then exit"" -q, --quiet "$"Run in quiet mode"" - --colors "$"Select the theme to be used for the colorized output"" -D, --debug "$"Run in debugging mode (very verbose output)"" +"$"Common options"": + --colors "$"Select the theme to be used for the colorized output"" + -C, --config "$"Use an alternate user configuration file"" + "$"Usage"": "$"Use '-u -h', '-s -h', '-x -h', and '--eval -h' to display specific command line options."" @@ -91,7 +94,7 @@ notify.disable_colors exit 1; } . @libdir@/libcfg.lib - + # Little helper function for reading args from the commandline. # it automatically handles -a b and -a=b variants, and returns 1 if # we need to shift $3. @@ -132,21 +135,28 @@ while (($# > 0)); do notify.warning $"\ deprecated option"" \`-r|--colorize': "$"use \`--colors' instead" # for backward compatibility - color_scheme="default" ;; - --colors) - read_arg color_scheme "$@" || - { shift; args[${#args[*]}]="$1"; } ;; + selected_color_scheme="default" ;; -h|--help) let "print_help = 1" ;; -V|--version) let "print_version = 1" ;; + --colors) + read_arg selected_color_scheme "$@" || + { shift; args[${#args[*]}]="$1"; } ;; + -C|--config) + read_arg custom_cfgfile_list "$@" || + { shift; args[${#args[*]}]="$1"; } ;; *) ;; esac shift done notify.debug "[${me[0]}, "$"version"" ${me[1]}]" -notify.debug "color_scheme = \"$color_scheme\"" + +[ "$selected_color_scheme" ] || color_scheme="$selected_color_scheme" + +notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\"" +cfg_load_files "$custom_cfgfile_list" case "$(( $pck_update + $spec_create + $pck_extract + $config_getvar ))" in 0) [ "$print_help" = "1" ] && autospec.usage 0 diff --git a/lib/libcfg.lib.in b/lib/libcfg.lib.in index c19662d..083b333 100644 --- a/lib/libcfg.lib.in +++ b/lib/libcfg.lib.in @@ -17,7 +17,7 @@ fi TEXTDOMAIN="libcfg"; export TEXTDOMAIN # list of the configuration file(s) -default_cfg=(\ +default_cfg_list=(\ `ls /etc/@package@.conf /etc/@package@.d/*.conf \ ~/.@package@ ~/.@package@.d/*.conf 2>/dev/null`) @@ -100,16 +100,32 @@ missing variable in the configuration file"" -- \`$cfg_var'" done } -cfg_files_num=0 -for cfg_file in ${default_cfg[*]}; do - if [ -e "$cfg_file" ]; then - cfg_files_num=$(($cfg_files_num + 1)) - notify.debug $"loading"": \`$cfg_file'..." - [ -r "$cfg_file" ] || notify.error $"cannot read"" \`$cfg_file'" - . "$cfg_file" +# load configuration files +function cfg_load_files() { + notify.debug "$FUNCNAME: loading configuration files..." + if [ "$1" ]; then + # select a different list of user configuration files + cfgfile_list=(\ +`ls /etc/@package@.conf /etc/@package@.d/*.conf` $1) + else + # default configuration files + cfgfile_list=(${default_cfg_list[@]}) fi -done -[ "$cfg_files_num" = 0 ] && notify.error $"configuration file not found" + notify.debug "$FUNCNAME: cfgfile_list = (${cfgfile_list[*]})" -unset cfg_file + local cfg_file + local cfg_files_num=0 + for cfg_file in ${cfgfile_list[*]}; do + if [ -e "$cfg_file" ]; then + cfg_files_num=$(($cfg_files_num + 1)) + notify.debug $"loading"": \`$cfg_file'..." + [ -r "$cfg_file" ] || notify.error $"cannot read"" \`$cfg_file'" + . "$cfg_file" + else + notify.error $"configuration file not found"": $cfg_file" + fi + done + + [ "$cfg_files_num" = 0 ] && notify.error $"configuration file not found" +} diff --git a/plugins/config-getvar.in b/plugins/config-getvar.in index c747f3c..372f340 100644 --- a/plugins/config-getvar.in +++ b/plugins/config-getvar.in @@ -52,20 +52,20 @@ function usage() { @frontend@ [-C ] --eval= "$"where the above options mean"": - --eval "$"Print the value of the configuration variable "" - -C, --config "$"Use an alternate configuration file"" "" - "$"Default files:"" $default_cfg_strlist"" - "$"Default user files:"" $default_cfg_user_strlist"" + --eval "$"Print the value of the configuration variable "" + --colors "$"Select the theme to be used for the colorized output"" + -C, --config "$"Use an alternate user configuration file"" "" + "$"Default files:"" $default_cfg_strlist"" + "$"Default user files:"" $default_cfg_user_strlist"" "$"Operation modes"": - -h, --help "$"Print this help, then exit"" - -V, --version "$"Print version number, then exit"" - -q, --quiet "$"Run in quiet mode"" - --colors "$"Select the theme to be used for the colorized output"" - -D, --debug "$"Run in debugging mode (very verbose output)"" + -h, --help "$"Print this help, then exit"" + -V, --version "$"Print version number, then exit"" + -q, --quiet "$"Run in quiet mode"" + -D, --debug "$"Run in debugging mode (very verbose output)"" "$"Samples"": - @frontend@ -q -C ${default_cfg[0]} --eval=\"logging_dir\" + @frontend@ -q -C ${default_cfg_list[0]} --eval=\"logging_dir\" "$"Report bugs to ." @@ -104,16 +104,16 @@ eval set -- "$exec_options" while :; do case $1 in - -C|--config) - cfg_file=$2; shift ;; --eval) autospecvar="$2"; shift ;; + --colors) + color_scheme="$2"; shift ;; + -C|--config) + cfg_file=$2; shift ;; -D|--debug) let "verbose = 2" ;; -q|--quiet) let "verbose = 0" ;; - --colors) - color_scheme="$2"; shift ;; -h|--help) usage 0 ;; -V|--version) @@ -149,7 +149,7 @@ function config.getvar() { notify.error $"configuration file not found"" -- \`$cfg_file'" cfg_file_lst="$cfg_file" else - cfg_file_lst="${default_cfg[*]}" + cfg_file_lst="${default_cfg_list[*]}" fi notify.debug "cfg_file_lst = \"$cfg_file_lst\"" diff --git a/plugins/pck-extract.in b/plugins/pck-extract.in index 61592cb..146a678 100644 --- a/plugins/pck-extract.in +++ b/plugins/pck-extract.in @@ -54,19 +54,22 @@ function usage() { "$"Extract a given file or list of files from a srpm archive"". "$"Usage"": - @frontend@ -x -F [--destdir=] + @frontend@ -x -F [-C ] [--destdir=] "$"where the above options mean"": - -x, --extract "$"Extract from the srpm package ..."" - -F, --files "$"...the specified file or list of files "" - --destdir "$"Save extracted files in the directory "" + -x, --extract "$"Extract from the srpm package ..."" + -F, --files "$"...the specified file or list of files "" + --destdir "$"Save extracted files in the directory "" + --colors "$"Select the theme to be used for the colorized output"" + -C, --config "$"Use an alternate user configuration file"" "" + "$"Default files:"" $default_cfg_strlist"" + "$"Default user files:"" $default_cfg_user_strlist"" "$"Operation modes"": - -h, --help "$"Print this help, then exit"" - -V, --version "$"Print version number, then exit"" - -q, --quiet "$"Run in quiet mode"" - --colors "$"Select the theme to be used for the colorized output"" - -D, --debug "$"Run in debugging mode (very verbose output)"" + -h, --help "$"Print this help, then exit"" + -V, --version "$"Print version number, then exit"" + -q, --quiet "$"Run in quiet mode"" + -D, --debug "$"Run in debugging mode (very verbose output)"" "$"Samples"": @frontend@ -x @package@-@version@-1mamba.src.rpm -F \\*.spec --destdir=/tmp/specs @@ -96,10 +99,10 @@ for arg in $@; do done exec_options=`LC_ALL=C getopt \ - -o xF:DqrhV \ + -o xF:C:DqrhV \ --long \ extract,files:,destdir:,\ -debug,quiet,colors:,help,version,\ +debug,quiet,colors:,config:,help,version,\ frontend_opts: \ -n "$me" -- "$@"` [ $? = 0 ] || exit 1 @@ -114,12 +117,14 @@ while :; do filelst="$2"; shift ;; --destdir) destdir="$2"; shift ;; + --colors) + color_scheme="$2"; shift ;; + -C|--config) + custom_cfgfile_list="$2"; shift ;; -D|--debug) let "verbose = 2" ;; -q|--quiet) let "verbose = 0" ;; - --colors) - color_scheme="$2"; shift ;; -h|--help) usage 0 ;; -V|--version) @@ -137,6 +142,9 @@ done notify.enable_colors "$color_scheme" +notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\"" +cfg_load_files "$custom_cfgfile_list" + # s_rpm_pck : the name of the srpm package (local or remote) # (i.e. /usr/src/RPM/SRPMS/automake-1.9-1qilnx.src.rpm) # filelst : list of file to extract (default is '*.spec', that is the specfile) diff --git a/plugins/pck-update.in b/plugins/pck-update.in index 432f621..f226a46 100644 --- a/plugins/pck-update.in +++ b/plugins/pck-update.in @@ -97,7 +97,7 @@ function usage() { [--changelog \"msg\" ] [--nosrpm|--norpm] \\ [--force-update] [--force-build] [--force-install] \\ [--force-download] [--ignore-test t1[,t2,...]] \\ - [-c] [-f] [-L] [-R] + [-c] [-f] [-L] [-R] [-C ] "$"where the above options mean"": -u, --update "$"Update the package to version and release "" @@ -146,22 +146,25 @@ function usage() { -L, --log "$"Unable logging to file (logging dir: \`\$logging_dir')"" -R, --rebuild "$"Enable rebuilding mode and settings (action 4 only)"" --root "$"Specify an alternative root directory to rpm"" + --colors "$"Select the theme to be used for the colorized output"" + -C, --config "$"Use an alternate user configuration file"" "" + "$"Default files:"" $default_cfg_strlist"" + "$"Default user files:"" $default_cfg_user_strlist"" "$"Operation modes"": -h, --help "$"Print this help, then exit"" -V, --version "$"Print version number, then exit"" -q, --quiet "$"Run in quiet mode"" - --colors "$"Select the theme to be used for the colorized output"" -D, --debug "$"Run in debugging mode (very verbose output)"" "$"Samples"": - @frontend@ -u aPackage 0.1.2 -a4 -f --changelog \""$"changelog entry""\" - @frontend@ --log -u aPackage -a5,7:9 --force-build --define addons_ver=0.9 - @frontend@ -c -u -l usr:pswd aPackage 0.1.2 -a10 --server-upload=1 - @frontend@ -u aPackage -a1,4,5 --arch=noarch --rebuild --ignore-test=6,7 - @frontend@ -u aPackage -a10 --norpm -S /var/tmp/specs/aPackage.spec - @frontend@ -u aPackage -a11 --force-install - + @frontend@ -u apck 0.1.2 -a4 -f --changelog \""$"changelog entry""\" + @frontend@ --log -u apck -a5,7:9 --force-build --define addons_ver=0.9 + @frontend@ -c -u -l usr:pswd apck 0.1.2 -a10 --server-upload=1 + @frontend@ -u apck -a1,4-8 -A noarch --rebuild --ignore-test=6,7 --colors=web + @frontend@ -u apck -a10 --norpm -S /var/tmp/specs/aPackage.spec + @frontend@ -u apck -a11 --force-install -C ~/.autospec-alt.conf + "$"Report bugs to ." exit ${1:-1} @@ -187,15 +190,15 @@ for arg in $@; do done exec_options=`LC_ALL=C getopt \ - -o ua:d:l:S:A:bcfLRDqrhV \ + -o ua:d:l:S:A:bcfLRC:DqhV \ --long \ update,action:,define:,login:,specfile:,arch:,\ server-download:,server-upload:,server:,\ changelog:,nosrpm,norpm,list-check,update-autobuildreq,\ force-update,force-build,force-install,force-download,force,\ ignore-test:,clear,format,log,rebuild,root:,\ -debug,quiet,colors:,help,version,\ -frontend_opts: \ +frontend_opts:,colors:,config:,\ +debug,quiet,help,version \ -n "$me" -- "$@"` [ $? = 0 ] || exit 1 @@ -276,6 +279,8 @@ while :; do let "verbose = 0" ;; --colors) color_scheme="$2"; shift ;; + -C|--config) + custom_cfgfile_list="$2"; shift ;; -h|--help) usage 0 ;; -V|--version) @@ -309,6 +314,9 @@ fi [ "$logging" = "1" ] && color_scheme="none" notify.enable_colors "$color_scheme" +notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\"" +cfg_load_files "$custom_cfgfile_list" + # default values for non mandatory configuration variables [ "$logging_dir" ] || logging_dir="${tmppath_dir:-/var/tmp}/@package@" diff --git a/plugins/spec-create.in b/plugins/spec-create.in index 0ba19f4..fd34c66 100644 --- a/plugins/spec-create.in +++ b/plugins/spec-create.in @@ -94,7 +94,8 @@ function usage() { "$"Usage"": @frontend@ -s [-n ] [-v ] [-t ] \\ - [-o ] [--changelog \""$"message""\"] [<"$"git-opts"">] + [-o ] [--changelog \""$"message""\"] [<"$"git-opts"">] \\ + [-C ] "$"where the above options mean"": -s, --source "$"Try to create a specfile for the specified source archive"" @@ -110,15 +111,18 @@ function usage() { python : "$"specfile for python modules"" standard-daemon : "$"standard specfile for system/network services"" -o, --output "$"Redirect the output to the file "" - --changelog "$"Set change information for the package"" - --git-branch "$"Specify a git branch"" + --changelog "$"Set change information for the package"" + --git-branch "$"Specify a git branch"" --preserve-dot-git "$"Do not remove git files"" + --colors "$"Select the theme to be used for the colorized output"" + -C, --config "$"Use an alternate user configuration file"" "" + "$"Default files:"" $default_cfg_strlist"" + "$"Default user files:"" $default_cfg_user_strlist"" "$"Operation modes"": -h, --help "$"Print this help, then exit"" -V, --version "$"Print version number, then exit"" -q, --quiet "$"Run in quiet mode"" - --colors "$"Select the theme to be used for the colorized output"" -D, --debug "$"Run in debugging mode (very verbose output)"" "$"Samples"": @@ -156,11 +160,11 @@ done config.check4user exec_options=`LC_ALL=C getopt \ - -o s:n:v:t:o:DqrhV \ + -o s:n:v:t:o:C:DqrhV \ --long \ source:,pck-name:,pck-version:,type:,output:,changelog:,\ git-branch:,preserve-dot-git,\ -debug,quiet,colors:,help,version,\ +colors:,config:,debug,quiet,help,version,\ frontend_opts: \ -n "$me" -- "$@"` [ $? = 0 ] || exit 1 @@ -195,6 +199,8 @@ while :; do let "verbose = 0" ;; --colors) color_scheme="$2"; shift ;; + -C|--config) + custom_cfgfile_list="$2"; shift ;; -h|--help) usage 0 ;; -V|--version) @@ -211,6 +217,9 @@ for arg in $@; do notify.error $"unrecognized option"" -- \`$arg'" done +notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\"" +cfg_load_files "$custom_cfgfile_list" + function specfile.ckeck_defvalues() { # $1: name of the specfile local specfile="$1" currvalue diff --git a/po/it/autospec_fe.po b/po/it/autospec_fe.po index 7f06fd5..42c76dc 100644 --- a/po/it/autospec_fe.po +++ b/po/it/autospec_fe.po @@ -58,9 +58,15 @@ msgstr "Non stampa alcun dettaglio delle operazioni in esecuzione" msgid "Select the theme to be used for the colorized output" msgstr "Seleziona il tema da usare per generare l'output colorato" +msgid "Use an alternate user configuration file" +msgstr "Definisce uno o più file di configurazione utente alternativi" + msgid "Run in debugging mode (very verbose output)" msgstr "Attiva la modalità di debugging (output prolisso)" +msgid "Common options" +msgstr "Opzioni comuni" + msgid "Usage" msgstr "Utilizzo" diff --git a/po/it/config-getvar.po b/po/it/config-getvar.po index fef08d1..1089124 100644 --- a/po/it/config-getvar.po +++ b/po/it/config-getvar.po @@ -45,8 +45,8 @@ msgstr "dove le precedenti opzioni significano" msgid "Print the value of the configuration variable " msgstr "Stampa il valore che assume nei file di configurazione" -msgid "Use an alternate configuration file" -msgstr "Utilizza un file di configurazione alternativo" +msgid "Use an alternate user configuration file" +msgstr "Definisce uno o più file di configurazione utente alternativi" msgid "Default files:" msgstr "File di default:" diff --git a/po/it/pck-extract.po b/po/it/pck-extract.po index dcbc95a..4e4ac57 100644 --- a/po/it/pck-extract.po +++ b/po/it/pck-extract.po @@ -66,6 +66,15 @@ msgstr "Non stampa alcun dettaglio delle operazioni in esecuzione" msgid "Select the theme to be used for the colorized output" msgstr "Seleziona il tema da usare per generare l'output colorato" +msgid "Use an alternate user configuration file" +msgstr "Definisce uno o più file di configurazione utente alternativi" + +msgid "Default files:" +msgstr "File di default:" + +msgid "Default user files:" +msgstr "File di default utente:" + msgid "Run in debugging mode (very verbose output)" msgstr "Attiva la modalità di debugging (output prolisso)" diff --git a/po/it/pck-update.po b/po/it/pck-update.po index f78395c..79dd80a 100644 --- a/po/it/pck-update.po +++ b/po/it/pck-update.po @@ -168,6 +168,15 @@ msgstr "Attiva modalità ed impostazioni di rebuild (azione 4)" msgid "Specify an alternative root directory to rpm" msgstr "Definisce una root directory alternativa per rpm" +msgid "Use an alternate user configuration file" +msgstr "Definisce uno o più file di configurazione utente alternativi" + +msgid "Default files:" +msgstr "File di default:" + +msgid "Default user files:" +msgstr "File di default utente:" + msgid "Operation modes" msgstr "Modalità operative" diff --git a/po/it/spec-create.po b/po/it/spec-create.po index 73bb4c5..b844ce3 100644 --- a/po/it/spec-create.po +++ b/po/it/spec-create.po @@ -88,6 +88,15 @@ msgstr "Specifica un branch git" msgid "Do not remove git files" msgstr "Non rimuove i file git" +msgid "Use an alternate user configuration file" +msgstr "Definisce uno o più file di configurazione utente alternativi" + +msgid "Default files:" +msgstr "File di default:" + +msgid "Default user files:" +msgstr "File di default utente:" + msgid "Operation modes" msgstr "Modalità operative" @@ -100,9 +109,6 @@ msgstr "Stampa il numero di versione e termina il programma" msgid "Run in quiet mode" msgstr "Non stampa alcun dettaglio delle operazioni in esecuzione" -msgid "Select the theme to be used for the colorized output" -msgstr "Seleziona il tema da usare per generare l'output colorato" - msgid "Run in debugging mode (very verbose output)" msgstr "Attiva la modalità di debugging (output prolisso)"