diff --git a/.travis.yml b/.travis.yml index e5fc5ded713..5850e557ac2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ jobs: - find . -name "*.json" -not -path "*/node_modules/*" -print0 | xargs -0 python3 ./tools/json_verifier.py - tools/travis/build_tgui.sh - tools/travis/check_grep.sh + - python3 -m pip install -r tools/mapmerge2/requirements.txt && python3 tools/mapmerge2/dmi.py --test - ~/dreamchecker - name: "Compile All Maps" diff --git a/tools/mapmerge2/dmi.py b/tools/mapmerge2/dmi.py index 7e1c75cf8d5..e87cf507b99 100644 --- a/tools/mapmerge2/dmi.py +++ b/tools/mapmerge2/dmi.py @@ -217,7 +217,8 @@ class State: return self.frames[self._frame_index(*args, **kwargs)] def escape(text): - assert '\\' not in text and '"' not in text + text = text.replace('\\', '\\\\') + text = text.replace('"', '\\"') return f'"{text}"' def unescape(text, quote='"'): @@ -226,7 +227,8 @@ def unescape(text, quote='"'): if not (text.startswith(quote) and text.endswith(quote)): raise ValueError(text) text = text[1:-1] - assert '\\' not in text and quote not in text + text = text.replace('\\"', '"') + text = text.replace('\\\\', '\\') return text def parse_num(value): @@ -239,7 +241,7 @@ def parse_bool(value): raise ValueError(value) return value == '1' -if __name__ == '__main__': +def _self_test(): # test: can we load every DMI in the tree import os @@ -249,7 +251,31 @@ if __name__ == '__main__': dirnames.remove('.git') for filename in filenames: if filename.endswith('.dmi'): - Dmi.from_file(os.path.join(dirpath, filename)) + fullpath = os.path.join(dirpath, filename) + try: + Dmi.from_file(fullpath) + except: + print('Failed on:', fullpath) + raise count += 1 print(f"Successfully parsed {count} dmi files") + +def _usage(): + import sys + print(f"Usage:") + print(f" {sys.argv[0]} --test") + exit(1) + +def _main(): + import sys + if len(sys.argv) < 2: + return _usage() + + if sys.argv[1] == '--test': + return _self_test() + + return _usage() + +if __name__ == '__main__': + _main()