#!/usr/bin/python3
# SPDX-License-Identifier: LGPL-2.1+

""" Check dependencies needed for rasterization """

import sys
import os

err = []

try:
    import gi
except ImportError:
    err.append("missing dependency python gobject introspection (python3-gi)")
try:
    gi.require_version("Pango", "1.0")
    from gi.repository import Pango
except NameError:
    pass
except ValueError:
    err.append("missing pango gobject introspection library")
try:
    gi.require_version("PangoCairo", "1.0")
    from gi.repository import PangoCairo
except NameError:
    pass
except ValueError:
    err.append("missing pangocairo gobject introspection library")

try:
    gi.require_version("cairo", "1.0")
    from gi.repository import cairo
except NameError:
    pass
except ValueError:
    err.append("missing cairo gobject introspection library")

try:
    import cairo
except NameError:
    pass
except ImportError:
    err.append("missing dependency python cairo (python3-cairo)")

# check that LINUGAS lists every language with a .po file
try:
    linguas_fn = sys.argv[1]
except IndexError:
    linguas_fn = open("po/LINGUAS")
with open(linguas_fn) as f:
    langs = f.read().splitlines()
for root, dirs, files in os.walk("po"):
    for file in files:
        if not file.endswith(".po"):
            continue
        l = file.split(".po")
        if len(l) > 1 and not l[0] in langs:
            err = 1
            err.append("missing translations for %s" % l[0])
for msg in err:
    print(f"Error: {msg}", file=sys.stderr)
sys.exit(len(err))
