2020-07-18 13:42:22 +05:30
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import argparse
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import damask
|
|
|
|
|
2020-11-01 00:02:49 +05:30
|
|
|
msc_version = float(damask.environment.options['MSC_VERSION'])
|
|
|
|
if int(msc_version) == msc_version:
|
|
|
|
msc_version = int(msc_version)
|
2020-07-18 13:42:22 +05:30
|
|
|
msc_root = Path(damask.environment.options['MSC_ROOT'])
|
2021-01-13 23:13:20 +05:30
|
|
|
damask_root = damask.environment.options['DAMASK_ROOT']
|
2020-07-18 13:42:22 +05:30
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Apply DAMASK modification to MSC.Marc/Mentat',
|
2020-11-01 00:02:49 +05:30
|
|
|
epilog = f'MSC_ROOT={msc_root} and MSC_VERSION={msc_version} (from {damask_root}/env/CONFIG)')
|
2020-07-18 13:42:22 +05:30
|
|
|
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()
|
2020-10-22 15:18:06 +05:30
|
|
|
content = content.replace('%INSTALLDIR%',str(msc_root))
|
2020-11-01 00:02:49 +05:30
|
|
|
content = content.replace('%VERSION%',str(msc_version))
|
2020-07-18 13:42:22 +05:30
|
|
|
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')
|
|
|
|
|
2020-11-01 00:02:49 +05:30
|
|
|
src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Marc_tools'
|
|
|
|
dst = msc_root/f'marc{msc_version}/tools'
|
2020-07-18 13:42:22 +05:30
|
|
|
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')
|
|
|
|
|
2020-11-01 00:02:49 +05:30
|
|
|
src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Mentat_bin'
|
|
|
|
dst = msc_root/f'mentat{msc_version}/bin'
|
2020-07-18 13:42:22 +05:30
|
|
|
for in_file in glob.glob(str(src/'*[!.original]')):
|
|
|
|
copy_and_replace(in_file,dst)
|
|
|
|
|
2020-11-01 00:02:49 +05:30
|
|
|
src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Mentat_menus'
|
|
|
|
dst = msc_root/f'mentat{msc_version}/menus'
|
2020-07-18 13:42:22 +05:30
|
|
|
for in_file in glob.glob(str(src/'job_run.ms')):
|
|
|
|
copy_and_replace(in_file,dst)
|
|
|
|
|
|
|
|
|
|
|
|
print('compiling Mentat menu binaries...')
|
|
|
|
|
2020-11-01 00:02:49 +05:30
|
|
|
executable = str(msc_root/f'mentat{msc_version}/bin/mentat')
|
|
|
|
menu_file = str(msc_root/f'mentat{msc_version}/menus/linux64/main.msb')
|
2020-07-18 13:42:22 +05:30
|
|
|
os.system(f'xvfb-run {executable} -compile {menu_file}')
|
|
|
|
|
|
|
|
|
|
|
|
print('setting file access rights...\n')
|
|
|
|
|
2020-11-01 00:02:49 +05:30
|
|
|
for pattern in [msc_root/f'marc{msc_version}/tools/*damask*',
|
|
|
|
msc_root/f'mentat{msc_version}/bin/submit?',
|
|
|
|
msc_root/f'mentat{msc_version}/bin/kill?']:
|
2020-07-18 13:42:22 +05:30
|
|
|
for f in glob.glob(str(pattern)):
|
|
|
|
os.chmod(f,0o755)
|