Skip to content

Commit

Permalink
bugy#261 made migrations not to fail startup on broken json files
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy authored and antonellocaroli committed Aug 1, 2020
1 parent e3edab6 commit a080c94
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/migrations/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,8 @@ def move_to_access(field, parent_object):


@_migration('migrate_output_files_parameters_substitution')
def __introduce_access_config(context):
conf_folder = os.path.join(context.conf_folder, 'runners')

if not os.path.exists(conf_folder):
return

conf_files = [os.path.join(conf_folder, file)
for file in os.listdir(conf_folder)
if file.lower().endswith('.json')]

for conf_file in conf_files:
content = file_utils.read_file(conf_file)
json_object = json.loads(content, object_pairs_hook=OrderedDict)

def __migrate_output_files_parameters_substitution(context):
for (conf_file, json_object, content) in _load_runner_files(context.conf_folder):
if ('output_files' not in json_object) or ('parameters' not in json_object):
continue

Expand Down Expand Up @@ -284,6 +272,30 @@ def _write_json(file_path, json_object, old_content):
json.dump(json_object, fp, indent=indent)


def _load_runner_files(conf_folder):
runners_folder = os.path.join(conf_folder, 'runners')

if not os.path.exists(runners_folder):
return

conf_files = [os.path.join(runners_folder, file)
for file in os.listdir(runners_folder)
if file.lower().endswith('.json')]

result = []

for conf_file in conf_files:
content = file_utils.read_file(conf_file)
try:
json_object = json.loads(content, object_pairs_hook=OrderedDict)
result.append((conf_file, json_object, content))
except Exception:
LOGGER.exception('Failed to load file for migration: ' + conf_file)
continue

return result


def migrate(temp_folder, conf_folder, conf_file, log_folder):
_validate_requirements()

Expand Down

0 comments on commit a080c94

Please sign in to comment.