summaryrefslogtreecommitdiff
path: root/src/tools/docwriter/check.py
blob: 52ceaed1304ea64f09c8559c4548d4661366e57e (plain)
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
#
#  check.py
#
#    Check if all external modules are present.
#
#  Copyright 2018 by
#  Nikhil Ramakrishnan.
#
#  This file is part of the FreeType project, and may only be used,
#  modified, and distributed under the terms of the FreeType project
#  license, LICENSE.TXT.  By continuing to use, modify, or distribute
#  this file you indicate that you have read the license and
#  understand and accept it fully.

"""Utility to check if all required modules are available.

The list of required modules can be modified in this file.

Usage:
    import check
    status = check.check()
"""

import logging

log = logging.getLogger( __name__ )

#
# Required imports
# Note that this is not the package name, but the module name as would be
# used in an import statement.
#
import_list = ["mistune", "yaml"]

def check():
    """Check if all required modules are present.

    Returns 0 on success, non-zero on error.
    """
    flag = 0
    for package in import_list:
        try:
            exec( "import " + package )
        except Exception:
            log.error( "Missing module: %s", package )
            flag = True
    if flag:
        return 1
    return 0

# eof