aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/migrate_tags_dot_to_colon.py25
1 files changed, 25 insertions, 0 deletions
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 @@
1#!/usr/bin/env nix-shell
2#!nix-shell -i python -p "python3.withPackages (ps: with ps; [ruamel_yaml])"
3
4from argparse import ArgumentParser
5from ruamel.yaml import YAML
6from collections.abc import Iterable
7
8parser = ArgumentParser(description='Converts tag separator from dot to colon in sidecar files, easing migration after GH-164.')
9parser.add_argument('file', type=str, nargs='+', help='YAML sidecar file(s) to migrate.')
10args = parser.parse_args()
11
12yaml = YAML(typ='rt') # preserve order, style and comments
13yaml.indent(mapping=2, sequence=2, offset=2)
14
15for file_path in args.file:
16 with open(file_path, 'r+') as file:
17 sidecar = yaml.load(file)
18 if not sidecar: continue
19
20 if 'tags' in sidecar and isinstance(sidecar['tags'], Iterable):
21 sidecar['tags'] = [tag.replace('.', ':') for tag in sidecar['tags']]
22
23 file.seek(0)
24 yaml.dump(sidecar, file)
25 file.truncate()