aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorpacien2020-02-27 21:05:51 +0100
committerNotkea2020-02-27 21:36:39 +0100
commitc7fa5bd40d0e5c9ea50190a90a0ccfee8ad96c25 (patch)
tree6c524899070301a13c7ce03bc6640d9c266bed71 /scripts
parent8f041b9f13b4c043acc7720aa4c082583b52ffe1 (diff)
downloadldgallery-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-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()