2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2014-01-11 18:16:30 +05:30
|
|
|
|
|
|
|
# Makes postprocessing routines acessible from everywhere.
|
2014-04-29 20:13:04 +05:30
|
|
|
import os,sys
|
2016-07-14 18:39:25 +05:30
|
|
|
import damask
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2016-07-14 18:39:25 +05:30
|
|
|
damaskEnv = damask.Environment()
|
2014-01-24 19:17:46 +05:30
|
|
|
baseDir = damaskEnv.relPath('processing/')
|
2016-07-14 18:39:25 +05:30
|
|
|
binDir = damaskEnv.options['DAMASK_BIN']
|
2014-02-28 13:17:11 +05:30
|
|
|
|
|
|
|
if not os.path.isdir(binDir):
|
|
|
|
os.mkdir(binDir)
|
2014-01-11 18:16:30 +05:30
|
|
|
|
|
|
|
#define ToDo list
|
2016-08-25 21:38:19 +05:30
|
|
|
processing_subDirs = ['pre',
|
|
|
|
'post',
|
|
|
|
'misc',
|
|
|
|
]
|
|
|
|
processing_extensions = ['.py',
|
|
|
|
'.sh',
|
|
|
|
]
|
|
|
|
|
|
|
|
sys.stdout.write('\nsymbolic linking...\n')
|
|
|
|
|
2014-04-11 00:55:23 +05:30
|
|
|
for subDir in processing_subDirs:
|
|
|
|
theDir = os.path.abspath(os.path.join(baseDir,subDir))
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2016-08-25 21:38:19 +05:30
|
|
|
sys.stdout.write('\n'+binDir+' ->\n'+theDir+damask.util.deemph(' ...')+'\n')
|
|
|
|
|
2014-04-11 00:55:23 +05:30
|
|
|
for theFile in os.listdir(theDir):
|
2016-08-25 21:38:19 +05:30
|
|
|
theName,theExt = os.path.splitext(theFile)
|
2017-06-02 13:24:54 +05:30
|
|
|
if theExt in processing_extensions: # only consider files with proper extensions
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2014-04-11 00:55:23 +05:30
|
|
|
src = os.path.abspath(os.path.join(theDir,theFile))
|
2016-08-25 21:38:19 +05:30
|
|
|
sym_link = os.path.abspath(os.path.join(binDir,theName))
|
2014-04-11 00:55:23 +05:30
|
|
|
|
|
|
|
if os.path.lexists(sym_link):
|
|
|
|
os.remove(sym_link)
|
2016-08-25 21:38:19 +05:30
|
|
|
output = theName+damask.util.deemph(theExt)
|
2014-04-11 00:55:23 +05:30
|
|
|
else:
|
2016-08-25 21:38:19 +05:30
|
|
|
output = damask.util.emph(theName)+damask.util.deemph(theExt)
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2016-08-25 21:38:19 +05:30
|
|
|
sys.stdout.write(damask.util.deemph('... ')+output+'\n')
|
2014-04-11 00:55:23 +05:30
|
|
|
os.symlink(src,sym_link)
|
2016-08-25 21:38:19 +05:30
|
|
|
|
|
|
|
|
|
|
|
sys.stdout.write('\npruning broken links...\n')
|
|
|
|
|
|
|
|
brokenLinks = 0
|
|
|
|
|
|
|
|
for filename in os.listdir(binDir):
|
|
|
|
path = os.path.join(binDir,filename)
|
|
|
|
if os.path.islink(path) and not os.path.exists(path):
|
|
|
|
sys.stdout.write(' '+damask.util.delete(path)+'\n')
|
|
|
|
os.remove(path)
|
|
|
|
brokenLinks += 1
|
|
|
|
|
|
|
|
sys.stdout.write(('none.' if brokenLinks == 0 else '')+'\n')
|