Fix full paths bug in applysed and perform some code cleanups and fixes.

This commit is contained in:
Andrius Štikonas 2009-02-21 14:24:28 +02:00
parent 85f3e26852
commit fe6087bd52
3 changed files with 33 additions and 47 deletions

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt> # Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt>
# Copyright 2009, Andrius Štikonas <stikonas@gmail.com>
# #
# # # #
# # This script is free software; you can redistribute it and/or modify # # This script is free software; you can redistribute it and/or modify
@ -19,26 +20,15 @@
# ths-applysed.sh - apply a sed script to the whole project (the sed commands # ths-applysed.sh - apply a sed script to the whole project (the sed commands
# have to be supplied in an external file). # have to be supplied in an external file).
## example of the replacements file content (remove preceeding comment marks # source `dirname $0`/ths-variables
## and the ======== lines ):
# ==================
# s/bylai/failui/g
# s/bylą/failą/g
# s/byloje/faile/g
# ==================
function usage() { function usage() {
echo "Usage: `basename $0` <FULL-PATH-TO-file-with-replacement-list> <FULL-PATH-TO-base-directory>" echo "Usage: `basename $0` <file-with-replacement-list> <base-directory>"
echo "WARNING: "
echo "SPECIFY FULL PATHS, OTHERWISE ALL YOUR FILES WILL BE DELETED!"
echo "DO A BACKUP BEFORE USING THIS SCRIPT!"
echo echo
echo "Example of the replacements file content" echo "Example of the replacements file content:"
echo "======== file begins ========" echo "s/bylai/failui/"
echo "s/bylai/failui/g" echo "s/bylą/failą/"
echo "s/bylą/failą/g" echo "s/byloje/faile/"
echo "s/byloje/faile/g"
echo "======== file ends =========="
exit 1 exit 1
} }
@ -46,14 +36,7 @@ if [ $# -ne 2 ]; then
usage usage
fi fi
replacefile=$1 for po in `find $2 -name "*.po"`; do
directory=$2 echo -e $BLUE"$po"$ENDCOLOR
sed --file=$1 -i $po
cd $directory
for po in `find . -name "*.po" | sort`
do
echo "Working on $po ..."
sed --file=$replacefile -i $po
echo "...done."
done done

View File

@ -76,19 +76,20 @@ upd_dir=$1
tra_tree=$2 tra_tree=$2
tpl_tree=$3 tpl_tree=$3
total_files=`find $upd_dir -name "*.po" | wc -l` newtrans=`cd $upd_dir; find . -name "*.po"`
total_files=`echo $newtrans | wc -w`
skipped_files=0 skipped_files=0
merged_files=0 merged_files=0
changed_files=0 changed_files=0
if [ "$option_verbose" = "Y" ]; then if [ "$option_verbose" = "Y" ]; then
echo "Checking if updated files are in the specified directory ..." echo "Checking if updated files are in the specified directory ..."
else else
echo -ne "\r$merged_files/$total_files merged" echo -ne "\r$merged_files/$total_files merged"
fi fi
newtrans=`cd $upd_dir; find . -name "*.po"`
if [ "$newtrans" == "" ]; then if [ "$newtrans" == "" ]; then
echo " ... no updated files found in: $upd_dir" echo -e $RED"\t\t... no updated files found in: $upd_dir"$ENDCOLOR
exit 1 exit 1
else else
if [ "$option_verbose" = "Y" ]; then if [ "$option_verbose" = "Y" ]; then
@ -100,22 +101,25 @@ fi
## MAIN LOOP ## MAIN LOOP
for updfile in $newtrans for updfile in $newtrans
do do
if [ `cd $tpl_tree; find ${updfile}t 2> /dev/null | wc -l` -gt 1 ]; then if [ `cd $tpl_tree; find ${updfile}t 2> /dev/null | wc -l` -gt 1 ]; then
echo if [ "$option_verbose" = "Y" ]; then
echo "Strange, there is more than one template for `basename $updfile`," echo
echo "cannot determine the right one," echo "Strange, there is more than one template for `basename $updfile`,"
echo "SKIPPING..." echo "cannot determine the right one,"
echo "SKIPPING..."
fi
continue continue
fi fi
if [ `cd $tra_tree; find ${updfile} 2> /dev/null | wc -l` -gt 1 ]; then if [ `cd $tpl_tree; find ${updfile} 2> /dev/null | wc -l` -gt 1 ]; then
echo if [ "$option_verbose" = "Y" ]; then
echo "Strange, there is more than one version of translation `basename $updfile`," echo
echo "although there is only one translation template. There might be an extra" echo "Strange, there is more than one version of translation `basename $updfile`,"
echo "unneeded file in your translation tree, check it out!" echo "although there is only one translation template. There might be an extra"
echo "Cannot determine the right file to translate," echo "unneeded file in your translation tree, check it out!"
echo "SKIPPING..." echo "Cannot determine the right file to translate,"
echo "SKIPPING..."
fi
continue continue
fi fi
@ -173,8 +177,7 @@ if [ "`$DIFF $tra_tree/${trafile}.old $tra_tree/${trafile}.new`" ]; then
fi fi
fi fi
rm $tra_tree/${trafile}.new rm $tra_tree/${trafile}.old $tra_tree/${trafile}.new
rm $tra_tree/${trafile}.old
merged_files=$(($merged_files+1)) merged_files=$(($merged_files+1))
if [ ! "$option_verbose" = "Y" ]; then if [ ! "$option_verbose" = "Y" ]; then

View File

@ -25,7 +25,7 @@ MSGMERGE=`which msgmerge 2> /dev/null`
KDIFF3=`which kdiff3 2> /dev/null` KDIFF3=`which kdiff3 2> /dev/null`
#Colors #Colors
RED="\033[1;31m" RED="\033[0;31m"
GREEN="\033[1;32m" GREEN="\033[0;32m"
BLUE="\033[1;34m" BLUE="\033[0;34m"
ENDCOLOR="\033[0m" ENDCOLOR="\033[0m"