Begining switch from sp.run -> sp.Popen

This commit is contained in:
Edgar P. Burkhart 2022-01-23 14:01:45 +01:00
parent 813eba5b1b
commit 39da28602d
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -43,28 +43,66 @@ if not work_dir.exists():
case_dir = work_dir.joinpath(config.get('main', 'case')) case_dir = work_dir.joinpath(config.get('main', 'case'))
if case_dir.exists(): if case_dir.exists():
log.info(f'Deleting case ({case_dir})') log.info(f'Deleting case ({case_dir})')
sp.run( cp = sp.Popen(
('rm', '-r', case_dir) ('cp', '-r', stl_in, stl_dir),
stderr=sp.PIPE,
text=True,
) )
code = cp.wait()
if cp.returncode != 0:
log.error(f'Error while copying stl ({stl_in} -> {stl_dir})')
log.error(cp.stderr.read()[:-1])
sys.exit(code)
rm = sp.Popen(
('rm', '-r', case_dir),
stdout=sp.PIPE,
stderr=sp.PIPE,
text=True,
)
code = rm.wait()
if code != 0:
log.error(f'Error while deleting case ({case_dir})')
log.error(rm.stderr)
sys.exit(code)
log.info(f'Copying case ({input_dir} -> {case_dir})') log.info(f'Copying case ({input_dir} -> {case_dir})')
sp.run( cp = sp.run(
('cp', '-r', input_dir, case_dir) ('cp', '-r', input_dir, case_dir),
capture_output=False,
) )
if cp.returncode != 0:
log.error(f'Error while copying case ({input_dir} -> {case_dir})')
log.error(cp.stderr)
sys.exit(cp.returncode)
if config.getboolean('stl', 'copy', fallback=False): if config.getboolean('stl', 'copy', fallback=False):
stl_dir = case_dir.joinpath('constant', 'triSurface') stl_dir = case_dir.joinpath('constant', 'triSurface')
if stl_dir.exists(): if stl_dir.exists():
log.info(f'Deleting stl directory ({stl_dir})') log.info(f'Deleting stl directory ({stl_dir})')
sp.run( rm = sp.Popen(
('rm', '-r', stl_dir) ('rm', '-r', stl_dir),
stdout=sp.PIPE,
stderr=sp.PIPE,
text=True,
) )
code = rm.wait()
if code != 0:
log.error(f'Error while deleting stl ({stl_dir})')
log.error(rm.stderr.read())
sys.exit(code)
stl_in = Path(config.get('stl', 'from')).expanduser() stl_in = Path(config.get('stl', 'from')).expanduser()
log.info(f'Copying stl directory ({stl_in} -> {stl_dir})') log.info(f'Copying stl directory ({stl_in} -> {stl_dir})')
sp.run( cp = sp.Popen(
('cp', '-r', stl_in, stl_dir) ('cp', '-r', stl_in, stl_dir),
stderr=sp.PIPE,
text=True,
) )
code = cp.wait()
if cp.returncode != 0:
log.error(f'Error while copying stl ({stl_in} -> {stl_dir})')
log.error(cp.stderr.read()[:-1])
sys.exit(code)
if config.getboolean('blockMesh', 'enable', fallback=False): if config.getboolean('blockMesh', 'enable', fallback=False):
log.info('Running blockMesh') log.info('Running blockMesh')
@ -107,12 +145,17 @@ if config.getboolean('snappyHexMesh', 'enable', fallback=False):
log.info(f'snappyHexMesh finished successfully') log.info(f'snappyHexMesh finished successfully')
log.info('Copying 0.org -> 0') log.info('Copying 0.org -> 0')
sp.run( cp = sp.run(
('cp', '-r', ('cp', '-r',
case_dir.joinpath('0.org'), case_dir.joinpath('0.org'),
case_dir.joinpath('0'), case_dir.joinpath('0'),
),
capture_output=False,
) )
) if cp.returncode != 0:
log.error(f'Error while copying 0.org -> 0')
log.error(cp.stderr)
sys.exit(cp.returncode)
if config.getboolean('setFields', 'enable', fallback=False): if config.getboolean('setFields', 'enable', fallback=False):
log.info('Running setFields') log.info('Running setFields')
@ -202,9 +245,14 @@ if config.getboolean('olaFlow', 'enable', fallback=False):
log.info(f'Deleting processor directories') log.info(f'Deleting processor directories')
for proc_dir in case_dir.glob(r'processor*'): for proc_dir in case_dir.glob(r'processor*'):
log.info(f'Deleting {proc_dir}') log.info(f'Deleting {proc_dir}')
sp.run( rm = sp.run(
('rm', '-r', proc_dir) ('rm', '-r', proc_dir),
capture_output=False,
) )
if rm.returncode != 0:
log.error(f'Error while deleting processor ({proc_dir})')
log.error(rm.stderr)
sys.exit(rm.returncode)
_t1 = time() _t1 = time()
log.info(f'Program ended successfully after {timedelta(seconds=_t1-_t0)}') log.info(f'Program ended successfully after {timedelta(seconds=_t1-_t0)}')