diff --git a/docs/migration_2_to_3.rst b/docs/migration_2_to_3.rst index e57444c157..94640b913a 100644 --- a/docs/migration_2_to_3.rst +++ b/docs/migration_2_to_3.rst @@ -28,7 +28,7 @@ Alternatively, you can convert any old configuration file using the conversion t .. code-block:: none - $ python3 tools/convert_config.py unittests/resources/settings_old_syntax.py + $ ./tools/convert-config unittests/resources/settings_old_syntax.py Conversion successful! The converted file can be found at '/var/folders/h7/k7cgrdl13r996m4dmsvjq7v80000gp/T/tmpz4f6yer4.py'. diff --git a/reframe/core/config.py b/reframe/core/config.py index 8cad64f281..eaf8c56784 100644 --- a/reframe/core/config.py +++ b/reframe/core/config.py @@ -374,7 +374,7 @@ def select_subconfig(self, system_fullname=None): self._local_system = system_fullname -def convert_old_config(filename): +def convert_old_config(filename, newfilename=None): old_config = util.import_module_from_file(filename).settings converted = { 'systems': [], @@ -524,11 +524,17 @@ def handler_list(handler_config): if converted['general'] == [{}]: del converted['general'] - with tempfile.NamedTemporaryFile(mode='w', suffix='.py', - delete=False) as fp: - fp.write(f"#\n# This file was automatically generated " - f"by ReFrame based on '{filename}'.\n#\n\n") - fp.write(f'site_configuration = {util.ppretty(converted)}\n') + contents = (f"#\n# This file was automatically generated " + f"by ReFrame based on '{filename}'.\n#\n\n" + f"site_configuration = {util.ppretty(converted)}\n") + + if newfilename: + with open(newfilename, 'w') as fp: + fp.write(contents) + else: + with tempfile.NamedTemporaryFile(mode='w', suffix='.py', + delete=False) as fp: + fp.write(contents) return fp.name diff --git a/tools/convert-config b/tools/convert-config new file mode 120000 index 0000000000..2ad48ad1cf --- /dev/null +++ b/tools/convert-config @@ -0,0 +1 @@ +convert_config.py \ No newline at end of file diff --git a/tools/convert_config.py b/tools/convert_config.py old mode 100644 new mode 100755 index 04674cc866..87f7e6762e --- a/tools/convert_config.py +++ b/tools/convert_config.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 +# # Copyright 2016-2020 Swiss National Supercomputing Centre (CSCS/ETH Zurich) # ReFrame Project Developers. See the top-level LICENSE file for details. # @@ -16,11 +18,17 @@ old_config = sys.argv[1] except IndexError: print(f'{sys.argv[0]}: too few arguments', file=sys.stderr) - print(f'Usage: {sys.argv[0]} OLD_CONFIG_FILE', file=sys.stderr) + print(f'Usage: {sys.argv[0]} OLD_CONFIG_FILE [NEW_CONFIG_FILE]', + file=sys.stderr) sys.exit(1) try: - new_config = config.convert_old_config(old_config) + new_config = sys.argv[2] + except IndexError: + new_config = None + + try: + new_config = config.convert_old_config(old_config, new_config) except Exception as e: print(f'{sys.argv[0]}: could not convert file: {e}', file=sys.stderr)