d41b90698ed72699f843410157a750a8d1ff0605
[samba.git] / third_party / wscript
1 #!/usr/bin/env python
2
3 import Utils
4 import os
5 import sys
6
7 # work out what python external libraries we need to install
8 external_pkgs = {
9     "dns.resolver": "dnspython/dns",
10     "iso8601": "pyiso8601/iso8601",
11     }
12
13
14 def find_third_party_module(conf, module, package):
15     conf.COMPOUND_START("Checking for third party Python module %s" % module)
16     try:
17         __import__(module)
18     except ImportError:
19         pass
20     else:
21         # Installed on the system
22         conf.COMPOUND_END("system")
23
24     old_path = sys.path
25     try:
26         sys.path.append(os.path.join(conf.curdir, os.path.dirname(package)))
27         try:
28             __import__(module)
29         except ImportError:
30             if (os.path.isdir(os.path.join(conf.srcdir, ".git")) and
31                 os.path.isfile(os.path.join(conf.srcdir, ".gitmodule"))):
32                 raise Utils.WafError("""\
33 Unable to find Python module '%s'. Please install the system package or check \
34 out the relevant submodule by running 'git submodule update --init'.
35 """ % module)
36             else:
37                 raise Utils.WafError("""\
38 Unable to find Python module '%s'. Please install the system package or place a copy in
39 %s.
40 """ % (module, package))
41         else:
42             conf.COMPOUND_END("bundled")
43     finally:
44         sys.path = old_path
45
46
47 def configure(conf):
48     for module, package in external_pkgs.items():
49         find_third_party_module(conf, module, package)
50     conf.RECURSE('popt')
51     conf.RECURSE('zlib')
52
53
54 def build(bld):
55     list = []
56
57     for module, package in external_pkgs.items():
58         try:
59             __import__(module)
60         except ImportError:
61             list.append(package)
62
63     for e in list:
64         bld.INSTALL_WILDCARD('${PYTHONARCHDIR}/samba/third_party', e + '/**/*', flat=False,
65                              exclude='*.pyc', trim_path=os.path.dirname(e))
66
67     bld.SAMBA_GENERATOR('third_party_init_py',
68                         rule='touch ${TGT}',
69                         target='empty_file')
70
71     bld.INSTALL_FILES('${PYTHONARCHDIR}/samba/third_party', 'empty_file', destname='__init__.py')
72     bld.RECURSE('zlib')
73     bld.RECURSE('popt')