Skip to content

Commit

Permalink
CleanOutput.py: support glob patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsvu committed Apr 9, 2024
1 parent fab01a9 commit a1e4bbe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 3 additions & 0 deletions support/Pipelines/Bbh/InitialData.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# See LICENSE.txt for details.

Executable: SolveXcts
ExpectedOutput:
- BbhReductions.h5
- BbhVolume*.h5
{% if evolve %}
Next:
Run: spectre.Pipelines.Bbh.Inspiral:start_inspiral
Expand Down
7 changes: 1 addition & 6 deletions tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ Testing:
ExpectedOutput:
- PoissonProductOfSinusoids1DReductions.h5
- PoissonProductOfSinusoids1DVolume0.h5
- SubdomainMatrix_[B0,(L1I0)].txt
- SubdomainMatrix_[B0,(L1I1)].txt
- SubdomainMatrix_[B0,(L2I0)].txt
- SubdomainMatrix_[B0,(L2I1)].txt
- SubdomainMatrix_[B0,(L2I2)].txt
- SubdomainMatrix_[B0,(L2I3)].txt
- SubdomainMatrix*.txt
OutputFileChecks:
- Label: Discretization error
Subfile: ErrorNorms.dat
Expand Down
23 changes: 14 additions & 9 deletions tools/CleanOutput.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Distributed under the MIT License.
# See LICENSE.txt for details.

import glob
import logging
import os
import shutil
Expand All @@ -24,13 +25,14 @@ def clean_output(input_file, output_dir, force):
Deletes output files specified in the `input_file` from the `output_dir`,
raising an error if the expected output files were not found.
The `input_file` must list its expected output files in the metadata:
The `input_file` must list its expected output files in the metadata.
They may contain glob patterns:
\b
```yaml
ExpectedOutput:
- Reduction.h5
- Volume0.h5
- Volume*.h5
```
"""
with open(input_file, "r") as open_input_file:
Expand All @@ -52,14 +54,17 @@ def clean_output(input_file, output_dir, force):

missing_files = []
for expected_output_file in expected_output:
expected_output_file = os.path.join(output_dir, expected_output_file)
found_output_files = glob.glob(
os.path.join(output_dir, expected_output_file)
)
logging.debug(f"Attempting to remove file {expected_output_file}...")
if os.path.exists(expected_output_file):
if os.path.isfile(expected_output_file):
os.remove(expected_output_file)
else:
shutil.rmtree(expected_output_file)
logging.info(f"Removed file {expected_output_file}.")
if len(found_output_files) > 0:
for expected_output_file in found_output_files:
if os.path.isfile(expected_output_file):
os.remove(expected_output_file)
else:
shutil.rmtree(expected_output_file)
logging.info(f"Removed file {expected_output_file}.")
elif not force:
missing_files.append(expected_output_file)
logging.error(
Expand Down

0 comments on commit a1e4bbe

Please sign in to comment.