17 #include "UnixUtils.H"
20 namespace GridConversion
27 std::string::size_type
x = filename.find(
"IR.dox");
28 if(x != std::string::npos)
30 x = filename.find(
"MakeProject.dox");
31 if(x != std::string::npos)
33 x = filename.find(
"ExistingProject.dox");
34 if(x != std::string::npos)
80 std::cout <<
"Usage:" << std::endl << std::endl
81 << argv[0] <<
" <template name> <new name> [verb level]" << std::endl
83 <<
"This program will read the project template from the <template name> "
85 <<
"directory and create a new \"blank\" IllinoisRocstar project"
87 <<
"named <new name>, in a directory named <new name>."
89 <<
"An optional verblevel of 1 or 2 can be given to make the process"
90 << std::endl <<
"more verbose." << std::endl;
93 std::string OriginalName(argv[1]);
94 std::string NewName(argv[2]);
98 int v = atoi(argv[3]);
102 std::vector<std::string> ProtectedFiles;
103 ProtectedFiles.push_back(
"AUTHORS");
104 ProtectedFiles.push_back(
"CTestConfig.cmake");
105 ProtectedFiles.push_back(
"LICENSE");
106 ProtectedFiles.push_back(
".svn");
107 std::vector<std::string> CommonFiles;
108 CommonFiles.push_back(
"CMakeLists.txt");
110 std::string olower(OriginalName);
111 std::string oupper(OriginalName);
112 std::string nlower(NewName);
113 std::string nupper(NewName);
114 std::transform(olower.begin(),olower.end(),olower.begin(),tolower);
115 std::transform(oupper.begin(),oupper.end(),oupper.begin(),toupper);
116 std::transform(nlower.begin(),nlower.end(),nlower.begin(),tolower);
117 std::transform(nupper.begin(),nupper.end(),nupper.begin(),toupper);
120 std::cout <<
"Creating a new project (" << NewName
121 <<
") from project template (" << OriginalName
122 <<
")." << std::endl << std::endl
123 <<
"Creating top level project directories...";
124 std::string dirname(NewName);
127 std::cout <<
" Creating directory " << dirname <<
"...";
130 std::cout <<
"Unable to create directory " << dirname <<
"."
135 std::cout <<
"done." << std::endl;
137 dirname +=
"/branches";
140 std::cout <<
" Creating directory " << dirname <<
"...";
143 std::cout <<
"Unable to create directory " << dirname <<
"."
148 std::cout <<
"done." << std::endl;
150 dirname = NewName+
"/tags";
153 std::cout <<
" Creating directory " << dirname <<
"...";
156 std::cout <<
"Unable to create directory " << dirname <<
"."
161 std::cout <<
"done." << std::endl;
163 dirname.assign(NewName+
"/examples");
166 std::cout <<
" Creating directory " << dirname <<
"...";
169 std::cout <<
"Unable to create directory " << dirname <<
"."
174 std::cout <<
"done." << std::endl;
176 bool protect_svn =
false;
177 dirname = NewName+
"/trunk";
178 std::vector<std::string>::iterator pfi = ProtectedFiles.begin();
179 while(pfi != ProtectedFiles.end()){
180 std::string ProtectThisFile(dirname+
"/"+*pfi++);
181 std::string ProtectedFile(ProtectThisFile+
".backup");
183 IRAD::Sys::Rename(ProtectThisFile,ProtectedFile);
185 pfi = CommonFiles.begin();
186 while(pfi != CommonFiles.end()){
187 std::string ProtectThisFile(dirname+
"/"+*pfi++);
188 std::string ProtectedFile(ProtectThisFile+
".backup");
190 IRAD::Sys::Rename(ProtectThisFile,ProtectedFile);
192 std::ostringstream ComStr;
195 std::cout <<
" Creating directory " << dirname <<
"...";
196 ComStr <<
"cp -r " << OriginalName <<
" " << dirname;
199 std::cout <<
" Making project files from template ...";
200 ComStr <<
"cp -r " << OriginalName <<
"/* " << dirname;
202 IRAD::Sys::InProcess System(ComStr.str());
204 while(std::getline(System,comline)){
206 std::cout << comline << std::endl;
209 std::cout <<
"done." << std::endl;
211 std::cout <<
"Cleaning up ...";
213 ComStr <<
"rm -rf " << dirname <<
"/.svn";
214 System.Execute(ComStr.str());
216 while(std::getline(System,comline))
218 pfi = ProtectedFiles.begin();
219 while(pfi != ProtectedFiles.end()){
220 std::string ProtectThisFile(dirname+
"/"+*pfi++);
221 std::string ProtectedFile(ProtectThisFile+
".backup");
224 IRAD::Sys::Remove(ProtectThisFile);
225 IRAD::Sys::Rename(ProtectedFile,ProtectThisFile);
228 pfi = CommonFiles.begin();
229 while(pfi != CommonFiles.end()){
230 std::string ProtectThisFile(dirname+
"/"+*pfi++);
231 std::string ProtectedFile(ProtectThisFile+
".backup");
232 std::string CommonFileTemplate(ProtectThisFile+
".template");
235 IRAD::Sys::Rename(ProtectThisFile,CommonFileTemplate);
236 IRAD::Sys::Rename(ProtectedFile,ProtectThisFile);
240 std::cout <<
"done." << std::endl;
242 std::cout <<
"Done creating new project files."
245 std::cout <<
"Renaming project...";
246 if(IRAD::Sys::ChDir(dirname)){
247 std::cout <<
"Something went wrong, cannot find new project directory."
252 ComStr <<
"grep -i " << OriginalName <<
" -r * | cut -d \":\" -f 1 | sort | uniq";
254 std::cout <<
" " << ComStr.str() << std::endl;
255 System.Execute(ComStr.str());
256 std::vector<std::string> filenames;
258 std::cout <<
" Files to change:" << std::endl;
259 while(std::getline(System,comline)){
261 filenames.push_back(comline);
263 std::cout <<
" " << comline << std::endl;
266 std::vector<std::string>::iterator fni = filenames.begin();
268 std::cout <<
" Processing files....";
269 while(fni != filenames.end()){
270 std::string filename(*fni++);
272 std::cout <<
" File: " << filename << std::endl;
274 ComStr <<
"sed -i 's/" << OriginalName <<
"/" << NewName <<
"/g' " << filename;
276 std::cout <<
" " << ComStr.str() << std::endl;
277 System.Execute(ComStr.str());
279 while(std::getline(System,comline))
282 ComStr <<
"sed -i 's/" << oupper <<
"/" << nupper <<
"/g' " << filename;
284 std::cout <<
" " << ComStr.str() << std::endl;
286 System.Execute(ComStr.str());
287 while(std::getline(System,comline))
290 ComStr <<
"sed -i 's/" << olower <<
"/" << nlower <<
"/g' " << filename;
292 std::cout <<
" " << ComStr.str() << std::endl;
294 System.Execute(ComStr.str());
295 while(std::getline(System,comline))
299 std::cout <<
" Done processing file contents." << std::endl
300 <<
" Renaming files..." << std::endl;
303 ComStr <<
"find . -name \"*" << OriginalName <<
"*\"";
304 System.Execute(ComStr.str());
305 std::string::size_type olen = OriginalName.length();
306 std::string::size_type nlen = NewName.length();
307 while(std::getline(System,comline)){
309 std::cout <<
" Renaming " << comline <<
" to ";
310 std::string newname(comline);
311 std::string::size_type
x = newname.find(OriginalName);
312 while(x != std::string::npos){
313 newname.replace(x,olen,NewName);
314 x = newname.find(OriginalName);
318 std::cout << newname << std::endl;
319 ComStr <<
"mv " << comline <<
" " << newname;
321 IRAD::Sys::InProcess MV(ComStr.str());
324 std::cout <<
"done." << std::endl;
329 int main(
int argc,
char *argv[])
int MakeProject(int argc, char *argv[])
Creates a new project from an GridConversion base.
bool FILEEXISTS(const std::string &fname)
bool Excluded(const std::string &filename)
Exclude certain template files from conversion in project creation.
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
int main(int argc, char *argv[])
int CreateDirectory(const std::string &fname)