File: validate.py

package info (click to toggle)
hicolor-icon-theme 0.18-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 280 kB
  • sloc: xml: 3,470; python: 41; sh: 19; makefile: 6
file content (64 lines) | stat: -rwxr-xr-x 1,591 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
#
# Copyright (C) 2022-2024 Matthias Klumpp <matthias@tenstral.net>
#
# SPDX-License-Identifier: GPL-2.0-or-later

import os
import sys
import shutil
import subprocess
from contextlib import contextmanager


SPEC_FILES = ['icon-naming-spec.xml', 'icon-theme-spec.xml']
VALIDATE_TABLES = False


@contextmanager
def temp_dir(basename=None):
    import tempfile

    current_dir = os.getcwd()
    temp_dir = tempfile.mkdtemp(prefix='tmp_', dir=current_dir)
    try:
        yield temp_dir
    finally:
        shutil.rmtree(temp_dir)


def main():
    daps_exe = shutil.which('daps')
    if not daps_exe:
        print("daps is not installed - please install it to continue!", file=sys.stderr)
        return 4

    with temp_dir() as tdir:
        xml_target = os.path.join(tdir, 'xml')
        os.makedirs(xml_target, exist_ok=True)

        # copy files into a structure that DAPS likes
        for fname in SPEC_FILES:
            shutil.copy(os.path.join('spec', fname), xml_target)

        # validate
        for fname in SPEC_FILES:
            print('➤', 'Validating:', fname)

            cmd = [daps_exe,
                   '-m', os.path.join(xml_target, fname),
                   'validate']
            if not VALIDATE_TABLES:
                cmd.append('--not-validate-tables')

            res = subprocess.run(cmd, check=False)
            if res.returncode != 0:
                return res.returncode

    return 0


if __name__ == '__main__':
    script_dir = os.path.dirname(os.path.abspath(__file__))
    os.chdir(script_dir)
    sys.exit(main())