From 27298f0f5fba2bd86eba7c23c2ad95b9ff3fcd8c Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 23 Jan 2022 14:13:36 +0100 Subject: [PATCH] Switched to shutil --- openfoam/run/__main__.py | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/openfoam/run/__main__.py b/openfoam/run/__main__.py index 4bf9cca..07341d5 100644 --- a/openfoam/run/__main__.py +++ b/openfoam/run/__main__.py @@ -1,4 +1,5 @@ import sys +import shutil import argparse import logging import configparser @@ -43,28 +44,24 @@ if not work_dir.exists(): case_dir = work_dir.joinpath(config.get('main', 'case')) if case_dir.exists(): log.info(f'Deleting case ({case_dir})') - sp.run( - ('rm', '-r', case_dir) - ) + shutil.rmtree(case_dir) log.info(f'Copying case ({input_dir} -> {case_dir})') -sp.run( - ('cp', '-r', input_dir, case_dir) -) +shutil.copytree(input_dir, case_dir) if config.getboolean('stl', 'copy', fallback=False): + stl_in = Path(config.get('stl', 'from')).expanduser() + if not stl_in.exists(): + log.error(f'STL from directory does not exist ({stl_in})') + sys.exit(1) + stl_dir = case_dir.joinpath('constant', 'triSurface') if stl_dir.exists(): log.info(f'Deleting stl directory ({stl_dir})') - sp.run( - ('rm', '-r', stl_dir) - ) + shutil.rmtree(stl_dir) - stl_in = Path(config.get('stl', 'from')).expanduser() log.info(f'Copying stl directory ({stl_in} -> {stl_dir})') - sp.run( - ('cp', '-r', stl_in, stl_dir) - ) + shutil.copytree(stl_in, stl_dir) if config.getboolean('blockMesh', 'enable', fallback=False): log.info('Running blockMesh') @@ -107,11 +104,9 @@ if config.getboolean('snappyHexMesh', 'enable', fallback=False): log.info(f'snappyHexMesh finished successfully') log.info('Copying 0.org -> 0') -sp.run( - ('cp', '-r', - case_dir.joinpath('0.org'), - case_dir.joinpath('0'), - ) +shutil.copytree( + case_dir.joinpath('0.org'), + case_dir.joinpath('0'), ) if config.getboolean('setFields', 'enable', fallback=False): @@ -202,9 +197,7 @@ if config.getboolean('olaFlow', 'enable', fallback=False): log.info(f'Deleting processor directories') for proc_dir in case_dir.glob(r'processor*'): log.info(f'Deleting {proc_dir}') - sp.run( - ('rm', '-r', proc_dir) - ) + shutil.rmtree(proc_dir) _t1 = time() log.info(f'Program ended successfully after {timedelta(seconds=_t1-_t0)}')