From c7fa5bd40d0e5c9ea50190a90a0ccfee8ad96c25 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 27 Feb 2020 21:05:51 +0100 Subject: viewer: use colon as tag separator instead of dot For consistency with the query language and allowing the use of the very common dot in tags. This also introduces a migration script. GitHub: closes #164 --- scripts/migrate_tags_dot_to_colon.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 scripts/migrate_tags_dot_to_colon.py (limited to 'scripts') diff --git a/scripts/migrate_tags_dot_to_colon.py b/scripts/migrate_tags_dot_to_colon.py new file mode 100755 index 0000000..bf56c4c --- /dev/null +++ b/scripts/migrate_tags_dot_to_colon.py @@ -0,0 +1,25 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i python -p "python3.withPackages (ps: with ps; [ruamel_yaml])" + +from argparse import ArgumentParser +from ruamel.yaml import YAML +from collections.abc import Iterable + +parser = ArgumentParser(description='Converts tag separator from dot to colon in sidecar files, easing migration after GH-164.') +parser.add_argument('file', type=str, nargs='+', help='YAML sidecar file(s) to migrate.') +args = parser.parse_args() + +yaml = YAML(typ='rt') # preserve order, style and comments +yaml.indent(mapping=2, sequence=2, offset=2) + +for file_path in args.file: + with open(file_path, 'r+') as file: + sidecar = yaml.load(file) + if not sidecar: continue + + if 'tags' in sidecar and isinstance(sidecar['tags'], Iterable): + sidecar['tags'] = [tag.replace('.', ':') for tag in sidecar['tags']] + + file.seek(0) + yaml.dump(sidecar, file) + file.truncate() -- cgit v1.2.3