Skip to content

Commit 08ca2fd

Browse files
committed
Added input checks.
1 parent dcb7e89 commit 08ca2fd

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/CreateNewModule.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def EditFile(source, line, typeOption):
3737
raise IOError("File not found: %s" % source)
3838
# type 1: main csn file
3939
if( typeOption == 1) :
40-
# read file
40+
# read file
4141
f = open(source, 'r')
4242
content = f.read()
4343
f.close()
@@ -46,23 +46,31 @@ def EditFile(source, line, typeOption):
4646
f = open(source, 'a')
4747
f.write("\n%s\n" % line);
4848
f.close()
49+
else:
50+
logger.warn("The line to insert ('%s') is already present in %s" % (line, source))
4951
# type 2: gimias csn file
5052
if( typeOption == 2 ):
5153
f = open(source, 'r')
5254
template = f.read()
5355
f.close()
56+
# check if the 'AddProjects' string is present
57+
if template.find( "AddProjects([" ) == -1:
58+
raise IOError("Could not find the project group (starting with 'AddProjects(['), \
59+
are you sure you provided the proper input file?")
5460
# check if line is not already there
5561
if template.find( line ) == -1:
56-
template = template.replace( "AddProjects([", "AddProjects([\n %s," % line)
62+
template = template.replace( "AddProjects([", "AddProjects([\n %s," % line, 1)
5763
f = open(source, 'w')
5864
f.write(template)
5965
f.close()
66+
else:
67+
logger.warn("The line to insert ('%s') is already present in %s" % (line, source))
6068
# type 4: widget collective
6169
if( typeOption == 4 ):
6270
f = open(source, 'r')
6371
template = f.read()
6472
f.close()
65-
template = template.replace(".CommandPanel();", ".CommandPanel();\n Core::Runtime::Kernel::GetGraphicalInterface()->RegisterFactory(\n %s::Factory::NewBase(), \n config.Caption(\"%s\").\n Id(wxID_%s) );\n" % (line,line,line))
73+
template = template.replace(".CommandPanel();", ".CommandPanel();\n Core::Runtime::Kernel::GetGraphicalInterface()->RegisterFactory(\n %s::Factory::NewBase(), \n config.Caption(\"%s\").\n Id(wxID_%s) );\n" % (line,line,line), 1)
6674
f = open(source, 'w')
6775
f.write(template)
6876
f.close()
@@ -71,7 +79,7 @@ def EditFile(source, line, typeOption):
7179
f = open(source, 'r')
7280
template = f.read()
7381
f.close()
74-
template = template.replace("Core::Runtime::Kernel::GetProcessorFactories();", "Core::Runtime::Kernel::GetProcessorFactories();\n factories->RegisterFactory( %s::Factory::NewBase( ) );\n" % line)
82+
template = template.replace("Core::Runtime::Kernel::GetProcessorFactories();", "Core::Runtime::Kernel::GetProcessorFactories();\n factories->RegisterFactory( %s::Factory::NewBase( ) );\n" % line, 1)
7583
f = open(source, 'w')
7684
f.write(template)
7785
f.close()
@@ -151,6 +159,8 @@ def CreateLibrary(rootPath, libraryName, rootForTemplateFiles, tkFilename):
151159
raise ValueError("No library name provided.")
152160
if not os.path.exists(tkFilename):
153161
raise IOError("The toolkit csnake file does not exist.")
162+
if not os.path.isfile(tkFilename):
163+
raise IOError("The toolkit csnake file is not a file.")
154164

155165
# create dictionary
156166
dictionary = dict()
@@ -205,8 +215,12 @@ def CreatePlugin(rootPath, pluginName, rootForTemplateFiles, tkFilename, gimiasF
205215
raise ValueError("No plugin name provided.")
206216
if not os.path.exists(tkFilename):
207217
raise IOError("The toolkit csnake file does not exist.")
218+
if not os.path.isfile(tkFilename):
219+
raise IOError("The toolkit csnake file is not a file.")
208220
if not os.path.exists(gimiasFilename):
209221
raise IOError("The gimias csnake file does not exist.")
222+
if not os.path.isfile(gimiasFilename):
223+
raise IOError("The gimias csnake file is not a file.")
210224

211225
# template plugin folder
212226
templatePluginFolder = "%s/TemplatePlugin%s" % (rootForTemplateFiles, gimiasVersion.replace('.', ''))
@@ -317,6 +331,8 @@ def CreateThirdParty(rootPath, thirdPartyName, rootForTemplateFiles, tkFilename)
317331
raise ValueError("No thirdparty name provided.")
318332
if not os.path.exists(tkFilename):
319333
raise IOError("The toolkit csnake file does not exist.")
334+
if not os.path.isfile(tkFilename):
335+
raise IOError("The toolkit csnake file is not a file.")
320336
cmakeFileName = os.path.join(rootPath ,"CMakeLists.txt")
321337
if not os.path.exists(cmakeFileName):
322338
raise IOError("The CMakeLists file does not exist.")

0 commit comments

Comments
 (0)