Salome HOME
Merge from V6_main 01/04/2013
[modules/yacs.git] / src / wrappergen / src / renameSalomeModule
1 #! /bin/bash
2 # Copyright (C) 2006-2013  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 usage()
22 {
23     echo
24     echo Usage :
25     echo "  renameSalomeModule  oldName newName dirModule"
26     echo
27     echo "  -> replace any occurence of oldName by newName in module dirModule"
28     echo 
29     echo "    (nex name cannot contain old name)"
30     echo
31     echo Example :
32     echo
33     echo "  cp -r HELLO_SRC CALCULATOR_SRC"
34     echo "  renameSalomeModule  HELLO CALCULATOR CALCULATOR_SRC"
35     echo
36     exit 1
37 }
38
39 rename_dir()
40 {
41     # Rename the first directory containing $oldName in their file name
42     liste=`find . -type d -name "*${oldName}*"`
43     for file in $liste
44     do
45         newFile=`echo $file | sed "s/${oldName}/${newName}/g"`
46         echo "mv -f $file $newFile"
47         mv -f $file $newFile
48         return 1
49     done
50     return 0
51 }
52
53 if [ "$1" == "-i" ]
54 then
55     # mode interactif
56     if [ $# -ne 4 ]
57     then
58         usage
59     fi
60     oldName=$2
61     newName=$3
62     moduleName=$4
63 else
64     if [ $# -ne 3 ]
65     then
66         usage
67     fi
68     oldName=$1
69     newName=$2
70     moduleName=$3
71 fi
72
73 # check names for restriction
74 echo $newName | grep $oldName > /dev/null
75 if [ $? -eq 0 ]
76 then
77     echo -e "Sorry : There is a restriction!\nNew name cannot contain old name.\n"
78     usage 
79 fi
80
81 today=`date +%d%m%y`
82
83 # Check arguments
84 if [ "$1" == "-i" ] # mode interactif
85 then
86     echo replace any occurence of $oldName by $newName in module $moduleName
87 else
88     clear
89     echo "Do you want to replace any occurence of $oldName by $newName in module $moduleName ?"
90     echo
91     read rep
92     case $rep in
93
94       y* | Y* | o* | O* )       ;;
95       * )                 usage ;;
96     esac
97 fi
98
99 cd ${moduleName}
100 echo
101 echo Renamed Directories:
102 echo
103
104 # rename directories one by one
105 rename_dir
106 while [ $? -eq 1 ]
107 do
108     rename_dir
109 done
110
111 # rename files containing ${oldName} in their name
112 echo
113 echo Renamed Files:
114 echo
115 liste=`find . -name "*${oldName}*"`
116 for file in $liste
117 do
118     newFile=`echo $file | sed "s/${oldName}/${newName}/g"`
119     echo "mv -f $file $newFile"
120     mv -f $file $newFile
121 done
122
123 echo
124 echo Modified Files:
125 echo
126 # modify all files containing $oldName, replace occurences by $newName
127 liste=`find -name "*"`
128 for file in $liste
129 do
130     if [ -f $file ]
131     then
132         grep $oldName $file > /dev/null 2>&1
133         if [ $? -eq 0 ]
134         then
135             echo $file
136             cat $file | sed "s/${oldName}/${newName}/g" > fic_temp_${today}
137             cp -f fic_temp_${today} $file
138         fi
139     fi
140 done
141 rm -f fic_temp_${today}
142 cd -