From f89f07e5cf86dcd8efbfdd50aee15d5563881ccc Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 28 Apr 2021 19:04:54 +0200 Subject: [PATCH] avoid use of global variables in functions --- .../apply_DAMASK_modifications.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/installation/mods_MarcMentat/apply_DAMASK_modifications.py b/installation/mods_MarcMentat/apply_DAMASK_modifications.py index 4c6568466..38323b3f7 100755 --- a/installation/mods_MarcMentat/apply_DAMASK_modifications.py +++ b/installation/mods_MarcMentat/apply_DAMASK_modifications.py @@ -7,6 +7,11 @@ from pathlib import Path 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( description='Apply DAMASK modification to MSC.Marc/Mentat', prog = Path(__file__).name, @@ -24,27 +29,18 @@ parser.add_argument('--damask-root', dest='damask_root', metavar = 'string', 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 -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') src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Marc_tools' dst = msc_root/f'marc{msc_version}/tools' 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') @@ -52,12 +48,12 @@ print('adapting Mentat scripts and menus...\n') src = damask_root/f'installation/mods_MarcMentat/{msc_version}/Mentat_bin' dst = msc_root/f'mentat{msc_version}/bin' 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' dst = msc_root/f'mentat{msc_version}/menus' 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...')