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 <davide.madrisan@gmail.com>
This commit is contained in:
Davide Madrisan 2012-11-14 22:42:08 +01:00
parent 8eee8ae037
commit 15f3575b2e
12 changed files with 155 additions and 69 deletions

View File

@ -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

View File

@ -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.""
@ -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

View File

@ -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"
}

View File

@ -52,20 +52,20 @@ function usage() {
@frontend@ [-C <conf_file>] --eval=<var>
"$"where the above options mean"":
--eval "$"Print the value of the configuration variable <var>""
-C, --config "$"Use an alternate configuration file"" <conf_file>""
"$"Default files:"" $default_cfg_strlist""
"$"Default user files:"" $default_cfg_user_strlist""
--eval "$"Print the value of the configuration variable <var>""
--colors "$"Select the theme to be used for the colorized output""
-C, --config "$"Use an alternate user configuration file"" <conf_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 <davide.madrisan@gmail.com>."
@ -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\""

View File

@ -54,19 +54,22 @@ function usage() {
"$"Extract a given file or list of files from a srpm archive"".
"$"Usage"":
@frontend@ -x -F <file(s)> [--destdir=<dir>] <srpm_pck>
@frontend@ -x -F <file(s)> [-C <conf_file>] [--destdir=<dir>] <srpm_pck>
"$"where the above options mean"":
-x, --extract "$"Extract from the srpm package <srpm_pck>...""
-F, --files "$"...the specified file or list of files <file(s)>""
--destdir "$"Save extracted files in the directory <dir>""
-x, --extract "$"Extract from the srpm package <srpm_pck>...""
-F, --files "$"...the specified file or list of files <file(s)>""
--destdir "$"Save extracted files in the directory <dir>""
--colors "$"Select the theme to be used for the colorized output""
-C, --config "$"Use an alternate user configuration file"" <conf_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)

View File

@ -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 <conf_file>]
"$"where the above options mean"":
-u, --update "$"Update the package <pck> to version <ver> and release <rel>""
@ -146,21 +146,24 @@ 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"" <conf_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 <davide.madrisan@gmail.com>."
@ -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@"

View File

@ -94,7 +94,8 @@ function usage() {
"$"Usage"":
@frontend@ -s <source-archive> [-n <name>] [-v <ver>] [-t <type>] \\
[-o <outfile>] [--changelog \""$"message""\"] [<"$"git-opts"">]
[-o <outfile>] [--changelog \""$"message""\"] [<"$"git-opts"">] \\
[-C <conf_file>]
"$"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 <outfile>""
--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"" <conf_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

View File

@ -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"

View File

@ -45,8 +45,8 @@ msgstr "dove le precedenti opzioni significano"
msgid "Print the value of the configuration variable <var>"
msgstr "Stampa il valore che <var> 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:"

View File

@ -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)"

View File

@ -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"

View File

@ -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)"