-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* run and move the input files in regression/input_files * call new run_tracking_inputs.py file from the ci (to test if it works as expected), removing print statements from the .py file too * try to get run-tracking-inputs to run on my fork * rename tracked mfiles in tracking dir to be _MFILE.DAT * remove print statement * delete commented out lines * work before updating main * parse args in run_tracking_inputs and call script in ci * changes from review comments
- Loading branch information
Showing
2 changed files
with
75 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"""Run the tracked files and move into tracking directory.""" | ||
|
||
import argparse | ||
from pathlib import Path | ||
import shutil | ||
import subprocess | ||
|
||
from tracking_data import ProcessTracker | ||
|
||
|
||
def run_and_move_tracked_files(arguments): | ||
""" | ||
Run PROCESS on the tracked files and move the MFiles to the tracking directory. | ||
""" | ||
path_to_tracking_files = Path(arguments.input_locs) | ||
|
||
input_files = path_to_tracking_files.glob("*.IN.DAT") | ||
tracking_dir = Path(__file__).parent | ||
for file_path in input_files: | ||
try: | ||
subprocess.run(f"process -i {file_path}", shell=True, check=True) | ||
except subprocess.CalledProcessError: | ||
continue | ||
created_mfile = file_path.with_name( | ||
file_path.name.replace(".IN.DAT", ".MFILE.DAT") | ||
) | ||
moved_mfile = created_mfile.with_name( | ||
created_mfile.name.replace(".MFILE.DAT", "_MFILE.DAT") | ||
) | ||
created_mfile.rename(tracking_dir / moved_mfile.name) | ||
|
||
|
||
def tracking(arguments): | ||
""" | ||
Call the ProcessTracker, move the MFiles to the database and rename. | ||
""" | ||
path_to_tracking_mfiles = Path(__file__).parent | ||
mfiles = path_to_tracking_mfiles.glob("*_MFILE.DAT") | ||
for mfile_path in mfiles: | ||
ProcessTracker( | ||
mfile=mfile_path, | ||
database=arguments.db, | ||
message=arguments.commit, | ||
hashid=arguments.hash, | ||
) | ||
|
||
copied_mfile = shutil.copy(mfile_path, Path(arguments.db) / mfile_path.name) | ||
moved_mfile_name = copied_mfile.with_name( | ||
copied_mfile.name.replace("_MFILE.DAT", f"_MFILE_{arguments.hash}.DAT") | ||
) | ||
copied_mfile.rename(moved_mfile_name) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
subparsers = parser.add_subparsers(help="Choose the usage mode", dest="command") | ||
|
||
# Run command | ||
subparser_run = subparsers.add_parser("run") | ||
subparser_run.add_argument("input_locs", type=str) | ||
|
||
# Tracking command | ||
subparser_trk = subparsers.add_parser("track") | ||
subparser_trk.add_argument("db", type=str) | ||
subparser_trk.add_argument("commit", type=str) | ||
subparser_trk.add_argument("hash", type=str) | ||
|
||
arguments = parser.parse_args() | ||
|
||
if arguments.command == "run": | ||
run_and_move_tracked_files(arguments) | ||
else: | ||
tracking(arguments) |