1212import os
1313import time
1414import ElementsKernel .ProjectCommonRoutines as epcr
15- import ElementsKernel .parseCmakeLists as pcl
15+ import ElementsKernel .ParseCmakeLists as pcl
1616import ElementsKernel .Logging as log
1717
1818logger = log .getLogger ('AddCppClass' )
@@ -35,7 +35,7 @@ def getClassName(str_subdir_class):
3535 """
3636 name_list = str_subdir_class .split (os .path .sep )
3737 className = name_list [- 1 ]
38- subdir = str_subdir_class .replace (className ,'' )
38+ subdir = str_subdir_class .replace (className , '' )
3939 # Remove end slash
4040 subdir = subdir [:- 1 ]
4141 logger .info ('# Class name: %s' % className )
@@ -79,9 +79,9 @@ def substituteStringsInDotH(file_path, class_name, module_name, subdir):
7979 # Make some substitutions
8080 file_name_str = os .path .join (module_name , subdir , class_name + '.h' )
8181 define_words_str = '_' + file_name_str
82- define_words_str = define_words_str .replace (H_TEMPLATE_FILE , class_name + '.h' )
83- define_words_str = define_words_str .replace ('.' ,'_' )
84- define_words_str = (define_words_str .replace (os .path .sep ,'_' )).upper ()
82+ define_words_str = define_words_str .replace (H_TEMPLATE_FILE , class_name + '.h' )
83+ define_words_str = define_words_str .replace ('.' , '_' )
84+ define_words_str = (define_words_str .replace (os .path .sep , '_' )).upper ()
8585 new_data = data % {"FILE" : file_name_str ,
8686 "DATE" : date_str ,
8787 "AUTHOR" : author_str ,
@@ -110,7 +110,7 @@ def substituteStringsInDotCpp(file_path, class_name, module_name, subdir):
110110 f = open (template_file , 'r' )
111111 data = f .read ()
112112 author_str = epcr .getAuthor ()
113- date_str = time .strftime ("%x" )
113+ date_str = time .strftime ("%x" )
114114 # This avoid double slashes
115115 ossep2 = os .sep
116116 if not subdir :
@@ -146,8 +146,8 @@ def substituteStringsInUnitTestFile(file_path, class_name, module_name, subdir):
146146 f = open (template_file , 'r' )
147147 data = f .read ()
148148 author_str = epcr .getAuthor ()
149- date_str = time .strftime ("%x" )
150- file_name_str = os .path .join ('tests' ,'src' ,class_name + '_test.cpp' )
149+ date_str = time .strftime ("%x" )
150+ file_name_str = os .path .join ('tests' , 'src' , class_name + '_test.cpp' )
151151 new_data = data % {"FILE" : file_name_str ,
152152 "DATE" : date_str ,
153153 "AUTHOR" : author_str ,
@@ -208,7 +208,7 @@ def updateCmakeListsFile(module_dir, module_name, subdir, class_name,
208208 # Update elements_add_library macro
209209 if module_name :
210210 source = 'src' + os .sep + 'lib' + os .sep + subdir + '*.cpp'
211- existing = [x for x in cmake_object .elements_add_library_list if x .name == module_name ]
211+ existing = [x for x in cmake_object .elements_add_library_list if x .name == module_name ]
212212 link_libs = []
213213 if elements_dep_list :
214214 link_libs = link_libs + elements_dep_list
@@ -221,18 +221,18 @@ def updateCmakeListsFile(module_dir, module_name, subdir, class_name,
221221 if not lib in existing [0 ].link_libraries_list :
222222 existing [0 ].link_libraries_list .append (lib )
223223 else :
224- source_list = [source ]
225- include_dirs_list = []
224+ source_list = [source ]
225+ include_dirs_list = []
226226 public_headers_list = [module_name ]
227- lib_object = pcl .ElementsAddLibrary (module_name , source_list ,
227+ lib_object = pcl .ElementsAddLibrary (module_name , source_list ,
228228 link_libs , include_dirs_list ,
229229 public_headers_list )
230230 cmake_object .elements_add_library_list .append (lib_object )
231231
232232 # Add unit test
233233 source_name = 'tests' + os .sep + 'src' + os .sep + subdir + \
234234 class_name + '_test.cpp'
235- unittest_object = pcl .ElementsAddUnitTest (class_name + '_test' ,
235+ unittest_object = pcl .ElementsAddUnitTest (class_name + '_test' ,
236236 [source_name ], [module_name ], [], 'Boost' )
237237 cmake_object .elements_add_unit_test_list .append (unittest_object )
238238
@@ -248,8 +248,8 @@ def isClassFileAlreadyExist(class_name, module_dir, module_name, subdir):
248248 Check if the class file does not already exist
249249 """
250250 script_goes_on = True
251- module_path = os .path .join (module_dir , module_name , subdir )
252- file_name = class_name + '.h'
251+ module_path = os .path .join (module_dir , module_name , subdir )
252+ file_name = class_name + '.h'
253253 file_name_path = os .path .join (module_path , file_name )
254254 if os .path .exists (file_name_path ):
255255 script_goes_on = False
@@ -265,20 +265,19 @@ def createCppClass(module_dir, module_name, subdir, class_name, elements_dep_lis
265265 """
266266 Create all necessary files for a cpp class
267267 """
268- script_goes_on = True
269268
270269 # Check the class does not exist already
271- script_goes_on = isClassFileAlreadyExist (class_name , module_dir , module_name ,
270+ script_goes_on = isClassFileAlreadyExist (class_name , module_dir , module_name ,
272271 subdir )
273272 if script_goes_on :
274273
275274 createDirectories (module_dir , module_name , subdir )
276275 class_h_path = os .path .join (module_dir , module_name , subdir )
277276 script_goes_on = epcr .copyAuxFile (class_h_path , H_TEMPLATE_FILE_IN )
278- class_cpp_path = os .path .join (module_dir ,'src' ,'lib' , subdir )
277+ class_cpp_path = os .path .join (module_dir , 'src' , 'lib' , subdir )
279278 if script_goes_on :
280279 script_goes_on = epcr .copyAuxFile (class_cpp_path , CPP_TEMPLATE_FILE_IN )
281- unittest_path = os .path .join (module_dir ,'tests' ,'src' , subdir )
280+ unittest_path = os .path .join (module_dir , 'tests' , 'src' , subdir )
282281 if script_goes_on :
283282 script_goes_on = epcr .copyAuxFile (unittest_path , UNITTEST_TEMPLATE_FILE_IN )
284283 if script_goes_on :
@@ -302,14 +301,14 @@ def defineSpecificProgramOptions():
302301the [-extd] option for external dependency.
303302 """
304303 parser = argparse .ArgumentParser (description = description )
305- parser .add_argument ('class_name' , metavar = 'class-name' ,
306- type = str ,
304+ parser .add_argument ('class_name' , metavar = 'class-name' ,
305+ type = str ,
307306 help = 'Class name' )
308- parser .add_argument ('-ed' , '--elements-dependency' , metavar = 'module_name' ,
307+ parser .add_argument ('-ed' , '--elements-dependency' , metavar = 'module_name' ,
309308 action = 'append' , type = str ,
310309 help = 'Dependency module name e.g. "-ed ElementsKernel"' )
311310 parser .add_argument ('-extd' , '--external-dependency' , metavar = 'library_name' ,
312- action = 'append' ,type = str ,
311+ action = 'append' , type = str ,
313312 help = 'External dependency library name e.g. "-extd ElementsKernel"' )
314313
315314 return parser
@@ -325,11 +324,11 @@ def mainMethod(args):
325324
326325 try :
327326 # True: no error occured
328- script_goes_on = True
327+ script_goes_on = True
329328
330- elements_dep_list = args .elements_dependency
331- library_dep_list = args .external_dependency
332- (subdir ,class_name ) = getClassName (args .class_name )
329+ elements_dep_list = args .elements_dependency
330+ library_dep_list = args .external_dependency
331+ (subdir , class_name ) = getClassName (args .class_name )
333332
334333 # Default is the current directory
335334 module_dir = os .getcwd ()
@@ -351,7 +350,7 @@ def mainMethod(args):
351350 logger .info ('# <%s> class successfully created in <%s>.' %
352351 (class_name , module_dir + os .sep + subdir ))
353352 # Remove backup file
354- epcr .deleteFile (os .path .join (module_dir , CMAKE_LISTS_FILE )+ '~' )
353+ epcr .deleteFile (os .path .join (module_dir , CMAKE_LISTS_FILE ) + '~' )
355354 logger .info ('# Script over.' )
356355 else :
357356 logger .error ('# Script aborted!' )
0 commit comments