17 #include "UnixUtils.H"
20 namespace ElmerModuleDriver
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 <<
"ElmerModuleDriver:MakeProject: " << std::endl <<
"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 <<
"ElmerModuleDriver:MakeProject:" << std::endl
121 <<
" Creating a new project (" << NewName
122 <<
") from project template (" << OriginalName
123 <<
")." << std::endl << std::endl
124 <<
"Creating top level project directories...";
125 std::string dirname(NewName);
126 if(!IRAD::Sys::FILEEXISTS(NewName)){
128 std::cout <<
"ElmerModuleDriver:MakeProject: Creating directory " << dirname <<
"...";
129 syserr = IRAD::Sys::CreateDirectory(dirname);
131 std::cout <<
"ElmerModuleDriver:MakeProject: Unable to create directory " << dirname <<
"."
136 std::cout <<
"done." << std::endl;
138 dirname +=
"/branches";
139 if(!IRAD::Sys::FILEEXISTS(dirname)){
141 std::cout <<
"ElmerModuleDriver:MakeProject: Creating directory " << dirname <<
"...";
142 syserr = IRAD::Sys::CreateDirectory(dirname);
144 std::cout <<
"ElmerModuleDriver:MakeProject: Unable to create directory " << dirname <<
"."
149 std::cout <<
"ElmerModuleDriver:MakeProject: done." << std::endl;
151 dirname = NewName+
"/tags";
152 if(!IRAD::Sys::FILEEXISTS(dirname)){
154 std::cout <<
"ElmerModuleDriver:MakeProject: Creating directory " << dirname <<
"...";
155 syserr = IRAD::Sys::CreateDirectory(dirname);
157 std::cout <<
"ElmerModuleDriver:MakeProject: Unable to create directory " << dirname <<
"."
162 std::cout <<
"ElmerModuleDriver:MakeProject: done." << std::endl;
164 dirname.assign(NewName+
"/examples");
165 if(!IRAD::Sys::FILEEXISTS(dirname)){
167 std::cout <<
"ElmerModuleDriver:MakeProject: Creating directory " << dirname <<
"...";
168 syserr = IRAD::Sys::CreateDirectory(dirname);
170 std::cout <<
"ElmerModuleDriver:MakeProject: Unable to create directory " << dirname <<
"."
175 std::cout <<
"ElmerModuleDriver:MakeProject: done." << std::endl;
177 bool protect_svn =
false;
178 dirname = NewName+
"/trunk";
179 std::vector<std::string>::iterator pfi = ProtectedFiles.begin();
180 while(pfi != ProtectedFiles.end()){
181 std::string ProtectThisFile(dirname+
"/"+*pfi++);
182 std::string ProtectedFile(ProtectThisFile+
".backup");
183 if(IRAD::Sys::FILEEXISTS(ProtectThisFile))
184 IRAD::Sys::Rename(ProtectThisFile,ProtectedFile);
186 pfi = CommonFiles.begin();
187 while(pfi != CommonFiles.end()){
188 std::string ProtectThisFile(dirname+
"/"+*pfi++);
189 std::string ProtectedFile(ProtectThisFile+
".backup");
190 if(IRAD::Sys::FILEEXISTS(ProtectThisFile))
191 IRAD::Sys::Rename(ProtectThisFile,ProtectedFile);
193 std::ostringstream ComStr;
194 if(!IRAD::Sys::FILEEXISTS(dirname)){
196 std::cout <<
"ElmerModuleDriver:MakeProject: Creating directory " << dirname <<
"...";
197 ComStr <<
"cp -r " << OriginalName <<
" " << dirname;
200 std::cout <<
"ElmerModuleDriver:MakeProject: Making project files from template ...";
201 ComStr <<
"cp -r " << OriginalName <<
"/* " << dirname;
203 IRAD::Sys::InProcess System(ComStr.str());
205 while(std::getline(System,comline)){
207 std::cout << comline << std::endl;
210 std::cout <<
"ElmerModuleDriver:MakeProject: done." << std::endl;
212 std::cout <<
"ElmerModuleDriver:MakeProject: Cleaning up ...";
214 ComStr <<
"rm -rf " << dirname <<
"/.svn";
215 System.Execute(ComStr.str());
217 while(std::getline(System,comline))
219 pfi = ProtectedFiles.begin();
220 while(pfi != ProtectedFiles.end()){
221 std::string ProtectThisFile(dirname+
"/"+*pfi++);
222 std::string ProtectedFile(ProtectThisFile+
".backup");
223 if(IRAD::Sys::FILEEXISTS(ProtectedFile)){
224 if(IRAD::Sys::FILEEXISTS(ProtectThisFile))
225 IRAD::Sys::Remove(ProtectThisFile);
226 IRAD::Sys::Rename(ProtectedFile,ProtectThisFile);
229 pfi = CommonFiles.begin();
230 while(pfi != CommonFiles.end()){
231 std::string ProtectThisFile(dirname+
"/"+*pfi++);
232 std::string ProtectedFile(ProtectThisFile+
".backup");
233 std::string CommonFileTemplate(ProtectThisFile+
".template");
234 if(IRAD::Sys::FILEEXISTS(ProtectedFile)){
235 if(IRAD::Sys::FILEEXISTS(ProtectThisFile))
236 IRAD::Sys::Rename(ProtectThisFile,CommonFileTemplate);
237 IRAD::Sys::Rename(ProtectedFile,ProtectThisFile);
241 std::cout <<
"ElmerModuleDriver:MakeProject: done." << std::endl;
243 std::cout <<
"ElmerModuleDriver:MakeProject: Done creating new project files."
246 std::cout <<
"ElmerModuleDriver:MakeProject: Renaming project...";
247 if(IRAD::Sys::ChDir(dirname)){
248 std::cout <<
"ElmerModuleDriver:MakeProject: Something went wrong, cannot find new project directory."
253 ComStr <<
"grep -i " << OriginalName <<
" -r * | cut -d \":\" -f 1 | sort | uniq";
255 std::cout <<
" " << ComStr.str() << std::endl;
256 System.Execute(ComStr.str());
257 std::vector<std::string> filenames;
259 std::cout <<
"ElmerModuleDriver:MakeProject: Files to change:" << std::endl;
260 while(std::getline(System,comline)){
262 filenames.push_back(comline);
264 std::cout <<
" " << comline << std::endl;
267 std::vector<std::string>::iterator fni = filenames.begin();
269 std::cout <<
"ElmerModuleDriver:MakeProject: Processing files....";
270 while(fni != filenames.end()){
271 std::string filename(*fni++);
273 std::cout <<
"ElmerModuleDriver:MakeProject: File: " << filename << std::endl;
275 ComStr <<
"sed -i 's/" << OriginalName <<
"/" << NewName <<
"/g' " << filename;
277 std::cout <<
"ElmerModuleDriver:MakeProject: " << ComStr.str() << std::endl;
278 System.Execute(ComStr.str());
280 while(std::getline(System,comline))
283 ComStr <<
"sed -i 's/" << oupper <<
"/" << nupper <<
"/g' " << filename;
285 std::cout <<
" " << ComStr.str() << std::endl;
287 System.Execute(ComStr.str());
288 while(std::getline(System,comline))
291 ComStr <<
"sed -i 's/" << olower <<
"/" << nlower <<
"/g' " << filename;
293 std::cout <<
" " << ComStr.str() << std::endl;
295 System.Execute(ComStr.str());
296 while(std::getline(System,comline))
300 std::cout <<
"ElmerModuleDriver:MakeProject: Done processing file contents." << std::endl
301 <<
" Renaming files..." << std::endl;
304 ComStr <<
"find . -name \"*" << OriginalName <<
"*\"";
305 System.Execute(ComStr.str());
306 std::string::size_type olen = OriginalName.length();
307 std::string::size_type nlen = NewName.length();
308 while(std::getline(System,comline)){
310 std::cout <<
"ElmerModuleDriver:MakeProject: Renaming " << comline <<
" to ";
311 std::string newname(comline);
312 std::string::size_type x = newname.find(OriginalName);
313 while(x != std::string::npos){
314 newname.replace(x,olen,NewName);
315 x = newname.find(OriginalName);
319 std::cout << newname << std::endl;
320 ComStr <<
"mv " << comline <<
" " << newname;
322 IRAD::Sys::InProcess MV(ComStr.str());
325 std::cout <<
"done." << std::endl;
330 int main(
int argc,
char *argv[])
bool Excluded(const std::string &filename)
Exclude certain template files from conversion in project creation.
int MakeProject(int argc, char *argv[])
Creates a new project from an ElmerModuleDriver base.