avoid use of global variables in functions
This commit is contained in:
parent
f860b26664
commit
f89f07e5cf
|
@ -7,6 +7,11 @@ from pathlib import Path
|
||||||
|
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Apply DAMASK modification to MSC.Marc/Mentat',
|
description='Apply DAMASK modification to MSC.Marc/Mentat',
|
||||||
prog = Path(__file__).name,
|
prog = Path(__file__).name,
|
||||||
|
@ -24,27 +29,18 @@ parser.add_argument('--damask-root', dest='damask_root', metavar = 'string',
|
||||||
default=damask.solver._marc._damask_root,
|
default=damask.solver._marc._damask_root,
|
||||||
help='DAMASK root directory')
|
help='DAMASK root directory')
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
msc_root = Path(args.msc_root)
|
msc_root = Path(args.msc_root)
|
||||||
damask_root = Path(args.damask_root)
|
damask_root = Path(args.damask_root)
|
||||||
msc_version = args.msc_version
|
msc_version = args.msc_version
|
||||||
|
|
||||||
def copy_and_replace(in_file,dst):
|
|
||||||
with open(in_file) as f:
|
|
||||||
content = f.read()
|
|
||||||
content = content.replace('%INSTALLDIR%',str(msc_root))
|
|
||||||
content = content.replace('%EDITOR%', args.editor)
|
|
||||||
with open(dst/Path(in_file).name,'w') as f:
|
|
||||||
f.write(content)
|
|
||||||
|
|
||||||
|
|
||||||
print('adapting Marc tools...\n')
|
print('adapting Marc tools...\n')
|
||||||
|
|
||||||
src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Marc_tools'
|
src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Marc_tools'
|
||||||
dst = msc_root/f'marc{msc_version}/tools'
|
dst = msc_root/f'marc{msc_version}/tools'
|
||||||
for in_file in glob.glob(str(src/'*damask*')) + [str(src/'include_linux64')]:
|
for in_file in glob.glob(str(src/'*damask*')) + [str(src/'include_linux64')]:
|
||||||
copy_and_replace(in_file,dst)
|
copy_and_replace(in_file,dst,args.msc_root,args.editor)
|
||||||
|
|
||||||
|
|
||||||
print('adapting Mentat scripts and menus...\n')
|
print('adapting Mentat scripts and menus...\n')
|
||||||
|
@ -52,12 +48,12 @@ print('adapting Mentat scripts and menus...\n')
|
||||||
src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Mentat_bin'
|
src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Mentat_bin'
|
||||||
dst = msc_root/f'mentat{msc_version}/bin'
|
dst = msc_root/f'mentat{msc_version}/bin'
|
||||||
for in_file in glob.glob(str(src/'*[!.original]')):
|
for in_file in glob.glob(str(src/'*[!.original]')):
|
||||||
copy_and_replace(in_file,dst)
|
copy_and_replace(in_file,dst,args.msc_root,args.editor)
|
||||||
|
|
||||||
src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Mentat_menus'
|
src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Mentat_menus'
|
||||||
dst = msc_root/f'mentat{msc_version}/menus'
|
dst = msc_root/f'mentat{msc_version}/menus'
|
||||||
for in_file in glob.glob(str(src/'job_run.ms')):
|
for in_file in glob.glob(str(src/'job_run.ms')):
|
||||||
copy_and_replace(in_file,dst)
|
copy_and_replace(in_file,dst,args.msc_root,args.editor)
|
||||||
|
|
||||||
|
|
||||||
print('compiling Mentat menu binaries...')
|
print('compiling Mentat menu binaries...')
|
||||||
|
|
Loading…
Reference in New Issue