~vcs-imports/kupfer/master-new

« back to all changes in this revision

Viewing changes to waflib/extras/package.py

  • Committer: Ulrik Sverdrup
  • Date: 2012-02-26 17:50:05 UTC
  • mfrom: (2916.1.5)
  • Revision ID: git-v1:a1d52c4a74cd48e1b673e68977eba58b48928b7f
Merge branch 'full-waf'

* full-waf:
  Update NEWS
  wscript: Use .xz for distribution tarball
  wscript: Clean all .pyc files on distclean
  Update README for Waf being included in the repository and tarball
  Add waf-light and waflib from waf-1.6.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# encoding: utf-8
 
3
# Thomas Nagy, 2011
 
4
 
 
5
"""
 
6
Obtain packages, unpack them in a location, and add associated uselib variables
 
7
(CFLAGS_pkgname, LIBPATH_pkgname, etc).
 
8
 
 
9
The default is use a Dependencies.txt file in the source directory.
 
10
 
 
11
This is a work in progress.
 
12
 
 
13
Usage:
 
14
 
 
15
def options(opt):
 
16
        opt.load('package')
 
17
 
 
18
def configure(conf):
 
19
    conf.load_packages()
 
20
"""
 
21
 
 
22
from waflib import Logs
 
23
from waflib.Configure import conf
 
24
 
 
25
try:
 
26
        from urllib import request
 
27
except:
 
28
        from urllib import urlopen
 
29
else:
 
30
        urlopen = request.urlopen
 
31
 
 
32
 
 
33
CACHEVAR = 'WAFCACHE_PACKAGE'
 
34
 
 
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
 
48
 
 
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)
 
71
 
 
72
@conf
 
73
def load_packages(self):
 
74
        cache = self.get_package_cache_dir()
 
75
        # read the dependencies, get the archives, ..
 
76