From dcefeb2278f57ea1b8d5f425b829e180052a0055 Mon Sep 17 00:00:00 2001 From: David Bold Date: Mon, 2 Dec 2024 13:58:25 +0100 Subject: [PATCH] Add input parser for v6 --- src/boutupgrader/__init__.py | 2 ++ .../bout_v5_input_file_upgrader.py | 12 ++++++++-- .../bout_v6_input_file_upgrader.py | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/boutupgrader/bout_v6_input_file_upgrader.py diff --git a/src/boutupgrader/__init__.py b/src/boutupgrader/__init__.py index 0a82f7a..7479db6 100644 --- a/src/boutupgrader/__init__.py +++ b/src/boutupgrader/__init__.py @@ -10,6 +10,7 @@ from .bout_v5_physics_model_upgrader import add_parser as add_model_parser from .bout_v5_xzinterpolation_upgrader import add_parser as add_xzinterp_parser from .bout_v6_coordinates_upgrader import add_parser as add_v6_coordinates_parser +from .bout_v6_input_file_upgrader import add_parser as add_v6_input_parser try: # This gives the version if the boututils package was installed @@ -71,6 +72,7 @@ def main(): add_model_parser(v5_subcommand, common_args, files_args) add_xzinterp_parser(v5_subcommand, common_args, files_args) add_v6_coordinates_parser(v6_subcommand, common_args, files_args) + add_v6_input_parser(v6_subcommand, common_args, files_args) args = parser.parse_args() args.func(args) diff --git a/src/boutupgrader/bout_v5_input_file_upgrader.py b/src/boutupgrader/bout_v5_input_file_upgrader.py index fb4aeb7..1445878 100644 --- a/src/boutupgrader/bout_v5_input_file_upgrader.py +++ b/src/boutupgrader/bout_v5_input_file_upgrader.py @@ -236,7 +236,7 @@ def possibly_apply_patch(patch, options_file, quiet=False, force=False): return make_change -def add_parser(subcommand, default_args, files_args): +def add_parser_general(subcommand, default_args, files_args, run): parser = subcommand.add_parser( "input", formatter_class=argparse.RawDescriptionHelpFormatter, @@ -290,7 +290,7 @@ def add_parser(subcommand, default_args, files_args): parser.set_defaults(func=run) -def run(args): +def run_general(REPLACEMENTS, DELETED, args): from boutdata.data import BoutOptions, BoutOptionsFile # Monkey-patch BoutOptions to make sure it's case sensitive @@ -340,3 +340,11 @@ def run(args): continue possibly_apply_patch(patch, modified, args.quiet, args.force) + + +def run(args): + return run_general(REPLACEMENTS, DELETED, args) + + +def add_parser(subcommand, default_args, files_args): + return add_parser_general(subcommand, default_args, files_args, run) diff --git a/src/boutupgrader/bout_v6_input_file_upgrader.py b/src/boutupgrader/bout_v6_input_file_upgrader.py new file mode 100644 index 0000000..26ec176 --- /dev/null +++ b/src/boutupgrader/bout_v6_input_file_upgrader.py @@ -0,0 +1,22 @@ +from .bout_v6_input_file_upgrader import run_general, add_parser_general + +# This should be a list of dicts, each containing "old", "new" and optionally "new_values". +# The values of "old"/"new" keys should be the old/new names of input file values or +# sections. The value of "new_values" is a dict containing replacements for values of the +# option. "old_type" optionally specifies the type of the old value of the option; for +# example this is needed for special handling of boolean values. +REPLACEMENTS = [ + {"old": "timestep", "new": "solver:output_step"}, + {"old": "nout", "new": "solver:nout"}, + {"old": "grid", "new": "mesh:file"}, +] + +DELETED = [] + + +def run(args): + return run_general(REPLACEMENTS, DELETED, args) + + +def add_parser(subcommand, default_args, files_args): + return add_parser_general(subcommand, default_args, files_args, run)