2020-07-18 13:42:22 +05:30
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import argparse
|
|
|
|
from pathlib import Path
|
|
|
|
|
2021-04-22 12:19:52 +05:30
|
|
|
import damask
|
2020-07-18 13:42:22 +05:30
|
|
|
|
2021-04-28 22:34:54 +05:30
|
|
|
def copy_and_replace(in_file,dst,msc_root,editor):
|
|
|
|
with open(in_file) as f_in, open(dst/Path(in_file).name,'w') as f_out:
|
|
|
|
f_out.write(f_in.read().replace('%INSTALLDIR%',msc_root).replace('%EDITOR%',editor))
|
|
|
|
|
|
|
|
|
2020-07-18 13:42:22 +05:30
|
|
|
parser = argparse.ArgumentParser(
|
2021-04-22 12:19:52 +05:30
|
|
|
description='Apply DAMASK modification to MSC.Marc/Mentat',
|
|
|
|
prog = Path(__file__).name,
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
|
|
|
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)')
|
2021-04-22 12:19:52 +05:30
|
|
|
parser.add_argument('--msc-root', dest='msc_root', metavar='string',
|
|
|
|
default=damask.solver._marc._msc_root,
|
|
|
|
help='MSC.Marc/Mentat root directory')
|
2021-04-28 12:23:40 +05:30
|
|
|
parser.add_argument('--msc-version', dest='msc_version', type=float, metavar='float',
|
2021-04-22 12:19:52 +05:30
|
|
|
default=damask.solver._marc._msc_version,
|
|
|
|
help='MSC.Marc/Mentat version')
|
2021-04-28 12:23:40 +05:30
|
|
|
parser.add_argument('--damask-root', dest='damask_root', metavar = 'string',
|
2021-04-22 12:19:52 +05:30
|
|
|
default=damask.solver._marc._damask_root,
|
|
|
|
help='DAMASK root directory')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
msc_root = Path(args.msc_root)
|
|
|
|
damask_root = Path(args.damask_root)
|
|
|
|
msc_version = args.msc_version
|
2020-07-18 13:42:22 +05:30
|
|
|
|
|
|
|
|
|
|
|
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')]:
|
2021-04-28 22:34:54 +05:30
|
|
|
copy_and_replace(in_file,dst,args.msc_root,args.editor)
|
2020-07-18 13:42:22 +05:30
|
|
|
|
|
|
|
|
|
|
|
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]')):
|
2021-04-28 22:34:54 +05:30
|
|
|
copy_and_replace(in_file,dst,args.msc_root,args.editor)
|
2020-07-18 13:42:22 +05:30
|
|
|
|
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')):
|
2021-04-28 22:34:54 +05:30
|
|
|
copy_and_replace(in_file,dst,args.msc_root,args.editor)
|
2020-07-18 13:42:22 +05:30
|
|
|
|
|
|
|
|
|
|
|
print('compiling Mentat menu binaries...')
|
|
|
|
|
2021-01-15 01:42:29 +05:30
|
|
|
executable = msc_root/f'mentat{msc_version}/bin/mentat'
|
|
|
|
menu_file = 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)
|