diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/migrate_tags_dot_to_colon.py | 25 |
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 | |||
4 | from argparse import ArgumentParser | ||
5 | from ruamel.yaml import YAML | ||
6 | from collections.abc import Iterable | ||
7 | |||
8 | parser = ArgumentParser(description='Converts tag separator from dot to colon in sidecar files, easing migration after GH-164.') | ||
9 | parser.add_argument('file', type=str, nargs='+', help='YAML sidecar file(s) to migrate.') | ||
10 | args = parser.parse_args() | ||
11 | |||
12 | yaml = YAML(typ='rt') # preserve order, style and comments | ||
13 | yaml.indent(mapping=2, sequence=2, offset=2) | ||
14 | |||
15 | for 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() | ||