2020-07-18 13:42:22 +05:30
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import argparse
|
2021-07-14 15:45:39 +05:30
|
|
|
import shutil
|
2020-07-18 13:42:22 +05:30
|
|
|
from pathlib import Path
|
|
|
|
|
2021-04-22 12:19:52 +05:30
|
|
|
import damask
|
2020-07-18 13:42:22 +05:30
|
|
|
|
2021-07-14 21:50:43 +05:30
|
|
|
def copy_and_patch(patch,orig,msc_root,editor):
|
2021-07-14 15:45:39 +05:30
|
|
|
try:
|
2021-07-14 13:43:08 +05:30
|
|
|
shutil.copyfile(orig,orig.parent/patch.stem)
|
2021-07-14 15:45:39 +05:30
|
|
|
except shutil.SameFileError:
|
|
|
|
pass
|
2021-07-14 22:05:38 +05:30
|
|
|
damask.execute(f'patch {orig.parent/patch.stem} {patch} -b')
|
|
|
|
with open(orig.parent/patch.stem) as f_in:
|
|
|
|
content = f_in.read()
|
|
|
|
with open(orig.parent/patch.stem,'w') as f_out:
|
|
|
|
f_out.write(content.replace('%INSTALLDIR%',msc_root).replace('%EDITOR%',editor))
|
2021-04-28 22:34:54 +05:30
|
|
|
|
|
|
|
|
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()
|
2021-07-14 15:45:39 +05:30
|
|
|
msc_root = Path(args.msc_root).expanduser()
|
|
|
|
damask_root = Path(args.damask_root).expanduser()
|
2021-07-14 22:05:38 +05:30
|
|
|
msc_version = int(args.msc_version) if str(args.msc_version).split('.')[1] == '0' else \
|
|
|
|
args.msc_version
|
2021-07-14 15:45:39 +05:30
|
|
|
|
|
|
|
matches = {'Marc_tools': [['comp_user','comp_damask_*mp'],
|
|
|
|
['run_marc','run_damask_*mp'],
|
|
|
|
['include_linux64','include_linux64']],
|
|
|
|
'Mentat_bin': [['edit_window','edit_window'],
|
|
|
|
['submit1','submit?'],
|
|
|
|
['kill1','kill?']],
|
|
|
|
'Mentat_menus':[['job_run.ms','job_run.ms']]}
|
|
|
|
|
|
|
|
|
|
|
|
print('patching files...\n')
|
|
|
|
|
|
|
|
for directory in glob.glob(str(damask_root/f'install/MarcMentat/{msc_version}/*')):
|
|
|
|
for orig, mods in matches[Path(directory).name]:
|
2021-07-14 22:05:38 +05:30
|
|
|
product,subfolder = (msc_root/Path(directory)).name.split('_')
|
|
|
|
orig = msc_root/f'{product.lower()}{msc_version}/{subfolder}/{orig}'
|
2021-07-14 15:45:39 +05:30
|
|
|
for patch in glob.glob(f'{directory}/{mods}.patch'):
|
2021-07-14 22:05:38 +05:30
|
|
|
copy_and_patch(Path(patch),orig,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'
|
2021-07-10 01:55:56 +05:30
|
|
|
os.system(f'xvfb-run -a {executable} -compile {menu_file}')
|