DAMASK_EICMD/installation/symlink_Processing.py

43 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*-
# Makes postprocessing routines acessible from everywhere.
import os,sys
from damask import Environment
2014-04-11 00:55:23 +05:30
BOLD = '\033[1m'
ENDC = '\033[0m'
damaskEnv = Environment()
2014-01-24 19:17:46 +05:30
baseDir = damaskEnv.relPath('processing/')
codeDir = damaskEnv.relPath('code/')
try:
binDir = damaskEnv.options['DAMASK_BIN']
except:
2014-04-11 00:55:23 +05:30
binDir = '/usr/local/bin' if os.access('/usr/local/bin', os.W_OK) else os.path.join(os.getenv('HOME'),'bin')
if not os.path.isdir(binDir):
os.mkdir(binDir)
#define ToDo list
2014-04-11 00:55:23 +05:30
processing_subDirs = ['pre','post','misc',]
processing_extensions = ['.py','.sh',]
2014-04-11 00:55:23 +05:30
for subDir in processing_subDirs:
theDir = os.path.abspath(os.path.join(baseDir,subDir))
2014-04-11 00:55:23 +05:30
for theFile in os.listdir(theDir):
if os.path.splitext(theFile)[1] in processing_extensions: # omit anything not fitting our script extensions (skip .py.bak, .py~, and the like)
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,os.path.splitext(theFile)[0]))
if os.path.lexists(sym_link):
os.remove(sym_link)
sys.stdout.write(sym_link)
2014-04-11 00:55:23 +05:30
else:
sys.stdout.write(BOLD + sym_link + ENDC)
2014-04-11 00:55:23 +05:30
os.symlink(src,sym_link)
sys.stdout.write(' -> '+src+'\n')