diff options
author | pacien | 2020-02-27 21:05:51 +0100 |
---|---|---|
committer | Notkea | 2020-02-27 21:36:39 +0100 |
commit | c7fa5bd40d0e5c9ea50190a90a0ccfee8ad96c25 (patch) | |
tree | 6c524899070301a13c7ce03bc6640d9c266bed71 /scripts | |
parent | 8f041b9f13b4c043acc7720aa4c082583b52ffe1 (diff) | |
download | ldgallery-c7fa5bd40d0e5c9ea50190a90a0ccfee8ad96c25.tar.gz |
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
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() | ||