check for existence of files before sym-linking to them.

This commit is contained in:
Philip Eisenlohr 2012-11-14 09:40:45 +00:00
parent 0513bf3256
commit ad9639f2f7
1 changed files with 26 additions and 26 deletions

View File

@ -45,30 +45,30 @@ architectures = {
}
bin_link = { \
'' : [
'DAMASK_spectral.exe',
],
}
'.' : [
'DAMASK_spectral.exe',
],
}
damaskEnv = damask.Environment('../../') # script location relative to root
baseDir = damaskEnv.relPath('code/')
for arch in architectures:
me = architectures[arch]
try:
parentFile = open(baseDir+os.sep+me['parent'])
parentContent = parentFile.readlines()
parentFile.close()
except IOError:
print 'unable to open',me['parent']
continue
me = architectures[arch]
try:
parentFile = open(baseDir+os.sep+me['parent'])
parentContent = parentFile.readlines()
parentFile.close()
except IOError:
print 'unable to open',me['parent']
continue
for version in me['versions'][1:]:
childFile = open(baseDir+os.sep+version.join(os.path.splitext(me['parent'])),'w')
for line in parentContent:
childFile.write(line.replace(me['versions'][0],version))
childFile.close()
for version in me['versions'][1:]:
childFile = open(baseDir+os.sep+version.join(os.path.splitext(me['parent'])),'w')
for line in parentContent:
childFile.write(line.replace(me['versions'][0],version))
childFile.close()
# changing dirs in makefile
makefile = open(os.path.join(baseDir,'Makefile'))
@ -91,14 +91,14 @@ if (options.spectralCompile):
os.system('make --directory %s clean'%(baseDir))
os.system('make --directory %s %s'%(baseDir,' '.join(options.makeOptions)))
# processing symbolic linking list
for dir in bin_link:
for file in bin_link[dir]:
src = os.path.abspath(os.path.join(baseDir,dir,file))
if (file == ''):
sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),dir))
else:
sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),os.path.splitext(file)[0]))
print sym_link,'-->',src
if os.path.lexists(sym_link):
os.remove(sym_link)
os.symlink(src,sym_link)
if os.path.exists(src):
sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),\
{True: dir,
False:os.path.splitext(file)[0]}[file == '']))
if os.path.lexists(sym_link): os.remove(sym_link)
os.symlink(src,sym_link)
print sym_link,'-->',src