python is more convenient

This commit is contained in:
Martin Diehl 2020-07-18 10:12:22 +02:00
parent 4860f9c9ce
commit 888e7028f9
3 changed files with 66 additions and 145 deletions

View File

@ -0,0 +1,65 @@
#!/usr/bin/env python3
import os
import glob
import argparse
from pathlib import Path
import damask
marc_version = float(damask.environment.options['MARC_VERSION'])
msc_root = Path(damask.environment.options['MSC_ROOT'])
damask_root = damask.environment.root_dir
parser = argparse.ArgumentParser(
description='Apply DAMASK modification to MSC.Marc/Mentat',
epilog = f'MSC_ROOT={msc_root} and MARC_VERSION={marc_version} (from {damask_root}/env/CONFIG)')
parser.add_argument('--editor', dest='editor', metavar='string', default='vi',
help='Name of the editor for MSC.Mentat (executable)')
def copy_and_replace(in_file,dst):
with open(in_file) as f:
content = f.read()
content = content.replace('%INSTALLDIR%',str(damask_root/'bin'))
content = content.replace('%VERSION%',str(marc_version).replace('.0',''))
content = content.replace('%EDITOR%', parser.parse_args().editor)
with open(dst/Path(in_file).name,'w') as f:
f.write(content)
print('adapting Marc tools...\n')
src = damask_root/f'installation/mods_MarcMentat/{marc_version}/Marc_tools'
dst = msc_root/f'marc{marc_version}/tools'
for in_file in glob.glob(str(src/'*damask*')) + [str(src/'include_linux64')]:
copy_and_replace(in_file,dst)
print('adapting Mentat scripts and menus...\n')
src = damask_root/f'installation/mods_MarcMentat/{marc_version}/Mentat_bin'
dst = msc_root/f'mentat{marc_version}/bin'
for in_file in glob.glob(str(src/'*[!.original]')):
copy_and_replace(in_file,dst)
src = damask_root/f'installation/mods_MarcMentat/{marc_version}/Mentat_menus'
dst = msc_root/f'mentat{marc_version}/menus'
for in_file in glob.glob(str(src/'job_run.ms')):
copy_and_replace(in_file,dst)
print('compiling Mentat menu binaries...')
executable = str(msc_root/f'mentat{marc_version}/bin/mentat')
menu_file = str(msc_root/f'mentat{marc_version}/menus/linux64/main.msb')
os.system(f'xvfb-run {executable} -compile {menu_file}')
print('setting file access rights...\n')
for pattern in [msc_root/f'marc{marc_version}/tools/*damask*',
msc_root/f'mentat{marc_version}/bin/submit?',
msc_root/f'mentat{marc_version}/bin/kill?']:
for f in glob.glob(str(pattern)):
os.chmod(f,0o755)

View File

@ -1,144 +0,0 @@
#!/usr/bin/env bash
SCRIPTLOCATION="$( cd "$( dirname "$0" )" && pwd )"
DAMASK_ROOT=$SCRIPTLOCATION/../../
if [ "x$MSC_ROOT" != "x" ]; then
DEFAULT_DIR=$MSC_ROOT
fi
if [ "x$MARC_VERSION" != "x" ]; then
DEFAULT_VERSION=$MARC_VERSION
fi
if [ "x$DAMASK_BIN" != "x" ]; then
BIN_DIR=$DAMASK_ROOT/bin
fi
while [ ! -d "$SCRIPTLOCATION/$VERSION" ] || [ -z "$VERSION" ]
do
echo "Input version of MARC/MENTAT installation: [${DEFAULT_VERSION}]"
read VERSION
if [ -z "$VERSION" ]; then
VERSION=${DEFAULT_VERSION}
fi
[[ -d "$SCRIPTLOCATION/$VERSION" ]] || echo -e "$VERSION not supported..!\n"
done
echo "MSC version: $VERSION"
while [ ! -d "$INSTALLDIR" ] || [ -z "$INSTALLDIR" ]
do
echo "Input path of MARC/MENTAT installation: [${DEFAULT_DIR}]"
read INSTALLDIR
if [ -z "$INSTALLDIR" ]; then
INSTALLDIR=${DEFAULT_DIR}
fi
[[ -d "$INSTALLDIR" ]] || echo -e "$INSTALLDIR not found..!\n"
done
INSTALLDIR=${INSTALLDIR%/} # remove trailing slash
echo "MSC installation path: $INSTALLDIR"
DEFAULT_EDITOR='vi'
EDITOR=''
while [ -z "$EDITOR" ]
do
echo "Input command to invoke your preferred editor: [${DEFAULT_EDITOR}]"
read EDITOR
if [ -z "$EDITOR" ]; then
EDITOR=${DEFAULT_EDITOR}
fi
done
echo "Editor: $EDITOR"
# tools
echo ''
echo 'adapting Marc tools...'
theDIR=$INSTALLDIR/marc$VERSION/tools
for filename in 'comp_damask_mp' \
'comp_damask_lmp' \
'comp_damask_hmp' \
'run_damask_mp' \
'run_damask_lmp' \
'run_damask_hmp' \
'include_linux64'; do
cp $SCRIPTLOCATION/$VERSION/Marc_tools/$filename $theDIR
echo $theDIR/$filename | xargs perl -pi -e "s:%INSTALLDIR%:${INSTALLDIR}:g"
echo $theDIR/$filename | xargs perl -pi -e "s:%VERSION%:${VERSION}:g"
echo $filename
done
# Mentat scripts
echo ''
echo 'adapting Mentat scripts...'
theDIR=$INSTALLDIR/mentat$VERSION/bin
for filename in 'edit_window' \
'submit4' \
'submit5' \
'submit6' \
'kill4' \
'kill5' \
'kill6'; do
cp $SCRIPTLOCATION/$VERSION/Mentat_bin/$filename $theDIR
echo $theDIR/$filename | xargs perl -pi -e "s:%INSTALLDIR%:${INSTALLDIR}:g"
echo $theDIR/$filename | xargs perl -pi -e "s:%VERSION%:${VERSION}:g"
echo $theDIR/$filename | xargs perl -pi -e "s:%EDITOR%:${EDITOR}:g"
echo $filename
done
# Mentat scripts
echo -e '\nadapting Mentat menus...'
theDIR=$INSTALLDIR/mentat$VERSION/menus
for filename in 'job_run.ms'; do
cp $SCRIPTLOCATION/$VERSION/Mentat_menus/$filename $theDIR
echo $theDIR/$filename | xargs perl -pi -e "s:%INSTALLDIR%:${INSTALLDIR}:g"
echo $theDIR/$filename | xargs perl -pi -e "s:%VERSION%:${VERSION}:g"
echo $filename
done
# compile menus
echo ''
echo 'compiling Mentat menu binaries...'
$(which xvfb-run 2>/dev/null) $INSTALLDIR/mentat$VERSION/bin/mentat -compile $INSTALLDIR/mentat$VERSION/menus/linux64/main.msb
[[ $? != 0 ]] && echo '...failed. Try installing xvfb-run on your system.'
# setting access rights
echo ''
echo 'setting file access rights...'
for filename in marc$VERSION/tools/run_damask* \
marc$VERSION/tools/comp_damask* \
mentat$VERSION/bin/submit{4..6} \
mentat$VERSION/bin/kill{4..6} ; do
chmod 755 $INSTALLDIR/${filename}
done
#creating symlinks for run_damask_scripts
if [ -d "$BIN_DIR" ]; then
echo ''
echo "Do you want to create symlinks for run_damask scripts in ${BIN_DIR} [YES/no] ?"
read YESNO
if [ -z "$YESNO" ]; then
YESNO=yes
fi
case $YESNO in
y* | Y* )
echo''
echo 'creating symlinks ...'
echo''
theDIR=$INSTALLDIR/marc$VERSION/tools
for filename in 'run_damask_mp' \
'run_damask_lmp' \
'run_damask_hmp'; do
echo ${filename:4}$VERSION
[ -f $BIN_DIR/${filename:4}$VERSION ] && rm $BIN_DIR/${filename:4}$VERSION
ln -s $theDIR/$filename $BIN_DIR/${filename:4}$VERSION
done
;;
esac
fi
# precompiling user subroutine
echo ''
echo 'precompiling $VERSION HYPELA2 user subroutine...'
echo 'not yet implemented..!'
echo -e '\ndone.'

View File

@ -11,7 +11,7 @@ The Intel Fortran compiler needs to be installed.
1) Install Marc, Mentat and Documentation as usual 1) Install Marc, Mentat and Documentation as usual
Run the test example including subroutines to confirm that the installation of both Marc/Mentat and the Intel Fortran Compiler is ok! Run the test example including subroutines to confirm that the installation of both Marc/Mentat and the Intel Fortran Compiler is ok!
2) Run the apply_DAMASK_modifications.sh script from this directory. 2) Run the apply_DAMASK_modifications.py script from this directory.
APPENDIX: APPENDIX: