File: check_syntax.py

package info (click to toggle)
game-data-packager 85.1
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 33,332 kB
  • sloc: python: 15,320; sh: 713; ansic: 95; makefile: 60
file content (45 lines) | stat: -rwxr-xr-x 1,425 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python3
# encoding=utf-8
#
# Copyright © 2014-2023 Simon McVittie <smcv@debian.org>
# SPDX-License-Identifier: GPL-2.0-or-later

import os
import sys
import yaml
from pathlib import Path

if 'GDP_UNINSTALLED' not in os.environ:
    sys.path.insert(0, '/usr/share/game-data-packager')
    sys.path.insert(0, '/usr/share/games/game-data-packager')

from game_data_packager.game import load_games
from game_data_packager.util import ascii_safe

if __name__ == '__main__':
    games = load_games()

    for name, game in games.items():
        try:
            game.load_file_data()
        except Exception:
            sys.stderr.write('While loading %s:\n' % game)
            raise

        ascii_safe(game.longname, force=True).encode('ascii')
        ascii_safe(game.help_text, force=True).encode('ascii')
        if 'DEBUG' in os.environ or 'GDP_DEBUG' in os.environ:
            print('# %s -----------------------------------------' % name)
            print(yaml.safe_dump(game.to_data()))

    if 'GDP_UNINSTALLED' in os.environ:
        srcdir = Path(__file__).resolve().parent.parent

        for path in (srcdir / 'data').glob('*.yaml'):
            if path.stem not in games:
                build = srcdir / 'data' / 'meson.build'

                raise AssertionError(
                    f'{path.stem} not found in games list '
                    f'({path.name} not in {build}?)'
                )