Skip to Content.
Sympa Menu

sm-commit - [SM-Commit] GIT changes to master sorcery by Jaka Kranjc (29ca10035490f05082b9b7802c30680533373269)

sm-commit AT lists.ibiblio.org

Subject: Source Mage code commit list

List archive

Chronological Thread  
  • From: Jaka Kranjc <scm AT sourcemage.org>
  • To: sm-commit AT lists.ibiblio.org
  • Subject: [SM-Commit] GIT changes to master sorcery by Jaka Kranjc (29ca10035490f05082b9b7802c30680533373269)
  • Date: Mon, 4 Feb 2008 06:53:07 -0600

GIT changes to master sorcery by Jaka Kranjc <lynxlynxlynx AT sourcemage.org>:

ChangeLog | 5 +
usr/sbin/confmeld | 264
+++++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 208 insertions(+), 61 deletions(-)

New commits:
commit 29ca10035490f05082b9b7802c30680533373269
Author: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>
Commit: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>

confmeld: don't output anything when listing and there is nothing
to show;
support passing spells or configs as arguments and only working on
them

the wierd removal code needs a cleanup

commit 65894221b564fa2e6bd9fe24cb432f9e450060e3
Author: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>
Commit: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>

confmeld: added options to just list all spells, configs or both

diff --git a/ChangeLog b/ChangeLog
index 9708bb1..71dccf0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-04 Jaka Kranjc <lynxlynxlynx AT sourcemage.org>
+ * confmeld: added options to just list all spells, configs or both
+ don't output anything when listing and there is nothing to show;
+ support passing spells or configs as arguments and only working on
them
+
2008-02-03 Jaka Kranjc <lynxlynxlynx AT sourcemage.org>
* libunpack: return 1 when no algorithm is allowed
* cast: call clean_resources in cast_cleanup
diff --git a/usr/sbin/confmeld b/usr/sbin/confmeld
index f0a9b88..9283294 100755
--- a/usr/sbin/confmeld
+++ b/usr/sbin/confmeld
@@ -11,14 +11,23 @@
function help()
{
cat << EOF
-
Melds the staged config files from $CONFIG_STAGE_DIRECTORY

-Example: confmeld
+Examples:
+confmeld
+confmeld -l
+confmeld nano
+confmeld /etc/sysconfig/facilities

Optional Parameters:
+-l, --list will just list all the spells and their staged configs
+-c, --list-configs will just list all the staged configs
+-s, --list-spells will just list all the spells with staged configs
+-q, --no-column don't column the output

-none
+Optional arguments:
+You can invoke confmeld with a spell name or a staged config as an argument.
+Confmeld will then work only on that argument.

EOF
exit 1
@@ -31,21 +40,19 @@ EOF
#--------------------------------------------------------------------
function all_config_files()
{
- find $CONFIG_STAGE_DIRECTORY
+ find $CONFIG_STAGE_DIRECTORY -type f
}

#--------------------------------------------------------------------
-## List all uniq config files in the config stage directory
+## List all uniq config *filenames* in the config stage directory
##
## @stdout a list of all uniq configs in the stage directory
#--------------------------------------------------------------------
function all_uniq_config_files()
{
all_config_files |
- while read file
- do
- echo ${file%.*}
- done | uniq
+ sed "s#^$CONFIG_STAGE_DIRECTORY/[^/]*/[^/]*##" |
+ sort -u
}

#--------------------------------------------------------------------
@@ -56,8 +63,71 @@ function all_uniq_config_files()
function all_spells_with_staged_configs()
{
all_config_files |
- sed "s#$CONFIG_STAGE_DIRECTORY/##g" |
- cut -d/ -f1 | uniq
+ sed "s#$CONFIG_STAGE_DIRECTORY/*##g" |
+ cut -s -d/ -f1 | uniq
+}
+
+#-----
+## override column so that we can pass -q to not columnate. Adapted from gaze
+#-----
+function maybe_column() {
+ if [[ $USE_COLUMN == no ]]; then
+ cat
+ else
+ column "$@"
+ fi
+}
+
+#--------------------------------------------------------------------
+## nicely list all spells that have staged configs and exit
+##
+## @stdout list of spells that have staged configs
+#--------------------------------------------------------------------
+function list_spells_with_staged_configs()
+{
+ local spells=$(all_spells_with_staged_configs)
+
+ if [[ -n $spells ]]; then
+ message "${MESSAGE_COLOR}Spells with staged configuration
files:$SPELL_COLOR"
+ echo "$spells" | maybe_column
+ message "$DEFAULT_COLOR"
+ fi
+ exit 0
+}
+
+#--------------------------------------------------------------------
+## nicely list all staged configs and exit
+##
+## @stdout list of staged configs
+#--------------------------------------------------------------------
+function list_staged_configs()
+{
+ local configs=$(all_uniq_config_files)
+
+ if [[ -n $configs ]]; then
+ message "${MESSAGE_COLOR}Staged configuration files:$FILE_COLOR"
+ echo "$configs" | maybe_column
+ message "$DEFAULT_COLOR"
+ fi
+ exit 0
+}
+
+#--------------------------------------------------------------------
+## nicely list all spells and their staged configs
+##
+## @stdout list of spells and their staged configs
+#--------------------------------------------------------------------
+function list_all()
+{
+ local spell config
+ for spell in $(all_spells_with_staged_configs); do
+ message "${SPELL_COLOR}$spell:$FILE_COLOR"
+ all_config_files |
+ sed -n "s,^$CONFIG_STAGE_DIRECTORY/$spell/[^/]*,,p" |
+ maybe_column
+ message "$DEFAULT_COLOR"
+ done
+ exit 0
}

#--------------------------------------------------------------------
@@ -81,17 +151,135 @@ function parse_stage_config_path()
eval "$4=\"$__path\""
}

+#--------------------------------------------------------------------
+## merge only the passed file
+##
+## @param config
+#--------------------------------------------------------------------
+function merge_single_file()
+{
+ local file=$1 spell sdate target
+
+ parse_stage_config_path $file spell sdate target &&
+ if [[ -f $file && $target ]]
+ then
+ message "${SPELL_COLOR}$spell$DEFAULT_COLOR cast on $sdate has config"
+ message "${FILE_COLOR}$file$DEFAULT_COLOR"
+ message "to be merged with $FILE_COLOR/$target${DEFAULT_COLOR}\n"
+ tablet_set_spell $spell &&
+ install_config_file $file $INSTALL_ROOT/$target
+ #
+ # since we use find we need to remove empty directories
+ # so if the spell or the date changes then we remove the directory so
+ # CONFIG_STAGE_DIRECTORY should always be empty after you complete the
+ # call to confmeld
+ #
+ # find does a preorder traversal of the directory tree keeping the path
+ # (esentially a stack) of where its been in the tree. If a particular
date
+ # or spell name changes at the same level in the tree we can safely
assume
+ # the previous date or spell has been walked and all files have been delt
+ # with accordingly so we can safely remove them.
+ #
+ if [[ $last_sdate && $last_sdate != $sdate ]]
+ then
+ message "${MESSAGE_COLOR}Removing stale dirs and files in the config
stage area.${DEFAULT_COLOR}"
+ rm_source_dir $CONFIG_STAGE_DIRECTORY/$last_spell/$last_sdate
+ fi
+ if [[ $last_spell && $last_spell != $spell ]]
+ then
+ message "${MESSAGE_COLOR}Removing stale dirs and files in the config
stage area.${DEFAULT_COLOR}"
+ rm_source_dir $CONFIG_STAGE_DIRECTORY/$last_spell
+ fi
+ last_sdate="$sdate"
+ last_spell="$spell"
+ echo -e "\n"
+ fi
+}
+
+#--------------------------------------------------------------------
+## merge only the passed files or spells
+##
+## @param spell/config
+## @param ...
+#--------------------------------------------------------------------
+function confmeld_partial()
+{
+ local thing config configs rc=0
+
+ for thing in "$@"; do
+ if codex_does_spell_exist $thing &> /dev/null; then
+ # we got a spell
+ configs=$(find $CONFIG_STAGE_DIRECTORY/$thing -type f)
+ else
+ # we got a config or three
+ configs=$(find $CONFIG_STAGE_DIRECTORY -type f -wholename "*$thing")
+ if [[ -z $configs ]]; then
+ error_message "${PROBLEM_COLOR}No such spell or
config:$DEFAULT_COLOR $thing"
+ rc=1
+ break
+ fi
+ fi
+ for config in $configs; do
+ merge_single_file "$config"
+ done
+ done
+ #
+ # final check for removing spell directories this is mainly a check so that
+ # empty directories will get removed
+ #
+ if [[ $last_spell ]]
+ then
+ message "${MESSAGE_COLOR}Removing any remaining stale dirs and files in
the config stage area.${DEFAULT_COLOR}"
+ rm_source_dir $CONFIG_STAGE_DIRECTORY/$last_spell
+ fi
+ find $CONFIG_STAGE_DIRECTORY -mindepth 1 -maxdepth 2 -type d -empty -delete
+ exit $rc
+}
+
+#--------------------------------------------------------------------
+## merge all the staged configs
+#--------------------------------------------------------------------
+function confmeld_all()
+{
+ local spell
+
+ for file in $(all_config_files)
+ do
+ merge_single_file "$file"
+ done
+ #
+ # final check for removing spell directories this is mainly a check so that
+ # empty directories will get removed
+ #
+ if [[ $last_spell ]]
+ then
+ message "${MESSAGE_COLOR}Removing any remaining stale dirs and files in
the config stage area.${DEFAULT_COLOR}"
+ rm_source_dir $CONFIG_STAGE_DIRECTORY/$last_spell
+ fi
+ find $CONFIG_STAGE_DIRECTORY -mindepth 1 -maxdepth 2 -type d -empty -delete
+}
+
function process_parameters()
{
+ local subroutine arguments
while [[ -n $1 ]]; do
if [[ ${1:0:1} == "-" ]]; then
case "$1" in
- --help|-h) help ;;
- *) help ;;
+ --help|-h) help ;;
+ --no-column|-q) USE_COLUMN=no ;;
+ --list-configs|-c) subroutine=list_staged_configs ;;
+ --list-spells|-s) subroutine=list_spells_with_staged_configs ;;
+ --list|-l) subroutine=list_all ;;
+ *) help ;;
esac
- else shift 1
+ else
+ arguments="$1 $arguments"
fi
+ shift
done
+ $subroutine
+
+ [[ $arguments ]] && confmeld_partial "${arguments% }"
}

#--------------------------------------------------------------------
@@ -108,53 +296,7 @@ function main()

process_parameters "$@"

- for file in $(all_config_files)
- do
- parse_stage_config_path $file spell sdate target &&
- if [[ -f $file && $target ]]
- then
- message "${SPELL_COLOR}$spell$DEFAULT_COLOR cast on $sdate has config"
- message "${FILE_COLOR}$file$DEFAULT_COLOR"
- message "to be merged with $FILE_COLOR/$target${DEFAULT_COLOR}\n"
- tablet_set_spell $spell &&
- install_config_file $file $INSTALL_ROOT/$target
- #
- # since we use find we need to remove empty directories
- # so if the spell or the date changes then we remove the directory so
- # CONFIG_STAGE_DIRECTORY should always be empty after you complete the
- # call to confmeld
- #
- # find does a preorder traversal of the directory tree keeping the path
- # (esentially a stack) of where its been in the tree. If a particular
date
- # or spell name changes at the same level in the tree we can safely
assume
- # the previous date or spell has been walked and all files have been
delt
- # with accordingly so we can safely remove them.
- #
- if [[ $last_sdate && $last_sdate != $sdate ]]
- then
- message "${MESSAGE_COLOR}Removing stale dirs and files in the config
stage area.${DEFAULT_COLOR}"
- rm_source_dir $CONFIG_STAGE_DIRECTORY/$last_spell/$last_sdate
- fi
- if [[ $last_spell && $last_spell != $spell ]]
- then
- message "${MESSAGE_COLOR}Removing stale dirs and files in the config
stage area.${DEFAULT_COLOR}"
- rm_source_dir $CONFIG_STAGE_DIRECTORY/$last_spell
- fi
- last_sdate="$sdate"
- last_spell="$spell"
- echo -e "\n"
- fi
- done
- #
- # final check for removing spell directories this is mainly a check so that
- # empty directories will get removed
- #
- if [[ $last_spell ]]
- then
- message "${MESSAGE_COLOR}Removing any remaining stale dirs and files in
the config stage area.${DEFAULT_COLOR}"
- rm_source_dir $CONFIG_STAGE_DIRECTORY/$last_spell
- fi
- find $CONFIG_STAGE_DIRECTORY -mindepth 1 -maxdepth 2 -type d -empty -delete
+ confmeld_all
}





  • [SM-Commit] GIT changes to master sorcery by Jaka Kranjc (29ca10035490f05082b9b7802c30680533373269), Jaka Kranjc, 02/04/2008

Archive powered by MHonArc 2.6.24.

Top of Page