Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/migration_2_to_3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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'.


Expand Down
18 changes: 12 additions & 6 deletions reframe/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [],
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tools/convert-config
12 changes: 10 additions & 2 deletions tools/convert_config.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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.
#
Expand All @@ -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)
Expand Down