DAMASK_EICMD/installation/symlink_Processing.py

60 lines
1.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: UTF-8 no BOM -*-
# Makes postprocessing routines acessible from everywhere.
import os,sys
import damask
damaskEnv = damask.Environment()
2014-01-24 19:17:46 +05:30
baseDir = damaskEnv.relPath('processing/')
binDir = damaskEnv.relPath('bin/')
if not os.path.isdir(binDir):
os.mkdir(binDir)
#define ToDo list
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))
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):
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-04-11 00:55:23 +05:30
src = os.path.abspath(os.path.join(theDir,theFile))
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)
output = theName+damask.util.deemph(theExt)
2014-04-11 00:55:23 +05:30
else:
output = damask.util.emph(theName)+damask.util.deemph(theExt)
sys.stdout.write(damask.util.deemph('... ')+output+'\n')
2014-04-11 00:55:23 +05:30
os.symlink(src,sym_link)
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')