ctdb-daemon: Use ctdb_parse_node_address() in ctdbd
[samba4-gss.git] / third_party / waf / waflib / extras / package.py
blobc06498eba8f567830e4af512da1664fd93922b82
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # Thomas Nagy, 2011
5 """
6 Obtain packages, unpack them in a location, and add associated uselib variables
7 (CFLAGS_pkgname, LIBPATH_pkgname, etc).
9 The default is use a Dependencies.txt file in the source directory.
11 This is a work in progress.
13 Usage:
15 def options(opt):
16 opt.load('package')
18 def configure(conf):
19 conf.load_packages()
20 """
22 from waflib import Logs
23 from waflib.Configure import conf
25 try:
26 from urllib import request
27 except ImportError:
28 from urllib import urlopen
29 else:
30 urlopen = request.urlopen
33 CACHEVAR = 'WAFCACHE_PACKAGE'
35 @conf
36 def get_package_cache_dir(self):
37 cache = None
38 if CACHEVAR in conf.environ:
39 cache = conf.environ[CACHEVAR]
40 cache = self.root.make_node(cache)
41 elif self.env[CACHEVAR]:
42 cache = self.env[CACHEVAR]
43 cache = self.root.make_node(cache)
44 else:
45 cache = self.srcnode.make_node('.wafcache_package')
46 cache.mkdir()
47 return cache
49 @conf
50 def download_archive(self, src, dst):
51 for x in self.env.PACKAGE_REPO:
52 url = '/'.join((x, src))
53 try:
54 web = urlopen(url)
55 try:
56 if web.getcode() != 200:
57 continue
58 except AttributeError:
59 pass
60 except Exception:
61 # on python3 urlopen throws an exception
62 # python 2.3 does not have getcode and throws an exception to fail
63 continue
64 else:
65 tmp = self.root.make_node(dst)
66 tmp.write(web.read())
67 Logs.warn('Downloaded %s from %s', tmp.abspath(), url)
68 break
69 else:
70 self.fatal('Could not get the package %s' % src)
72 @conf
73 def load_packages(self):
74 self.get_package_cache_dir()
75 # read the dependencies, get the archives, ..