diff options
Diffstat (limited to 'bitbake-dev/lib/bb/fetch/wget.py')
-rw-r--r-- | bitbake-dev/lib/bb/fetch/wget.py | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/fetch/wget.py b/bitbake-dev/lib/bb/fetch/wget.py new file mode 100644 index 0000000000..739d5a1bc6 --- /dev/null +++ b/bitbake-dev/lib/bb/fetch/wget.py | |||
@@ -0,0 +1,105 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | """ | ||
4 | BitBake 'Fetch' implementations | ||
5 | |||
6 | Classes for obtaining upstream sources for the | ||
7 | BitBake build tools. | ||
8 | |||
9 | """ | ||
10 | |||
11 | # Copyright (C) 2003, 2004 Chris Larson | ||
12 | # | ||
13 | # This program is free software; you can redistribute it and/or modify | ||
14 | # it under the terms of the GNU General Public License version 2 as | ||
15 | # published by the Free Software Foundation. | ||
16 | # | ||
17 | # This program is distributed in the hope that it will be useful, | ||
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | # GNU General Public License for more details. | ||
21 | # | ||
22 | # You should have received a copy of the GNU General Public License along | ||
23 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
24 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
25 | # | ||
26 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | ||
27 | |||
28 | import os, re | ||
29 | import bb | ||
30 | from bb import data | ||
31 | from bb.fetch import Fetch | ||
32 | from bb.fetch import FetchError | ||
33 | from bb.fetch import uri_replace | ||
34 | |||
35 | class Wget(Fetch): | ||
36 | """Class to fetch urls via 'wget'""" | ||
37 | def supports(self, url, ud, d): | ||
38 | """ | ||
39 | Check to see if a given url can be fetched with cvs. | ||
40 | """ | ||
41 | return ud.type in ['http','https','ftp'] | ||
42 | |||
43 | def localpath(self, url, ud, d): | ||
44 | |||
45 | url = bb.encodeurl([ud.type, ud.host, ud.path, ud.user, ud.pswd, {}]) | ||
46 | ud.basename = os.path.basename(ud.path) | ||
47 | ud.localfile = data.expand(os.path.basename(url), d) | ||
48 | |||
49 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) | ||
50 | |||
51 | def go(self, uri, ud, d, checkonly = False): | ||
52 | """Fetch urls""" | ||
53 | |||
54 | def fetch_uri(uri, ud, d): | ||
55 | if checkonly: | ||
56 | fetchcmd = data.getVar("CHECKCOMMAND", d, 1) | ||
57 | elif os.path.exists(ud.localpath): | ||
58 | # file exists, but we didnt complete it.. trying again.. | ||
59 | fetchcmd = data.getVar("RESUMECOMMAND", d, 1) | ||
60 | else: | ||
61 | fetchcmd = data.getVar("FETCHCOMMAND", d, 1) | ||
62 | |||
63 | bb.msg.note(1, bb.msg.domain.Fetcher, "fetch " + uri) | ||
64 | fetchcmd = fetchcmd.replace("${URI}", uri) | ||
65 | fetchcmd = fetchcmd.replace("${FILE}", ud.basename) | ||
66 | bb.msg.debug(2, bb.msg.domain.Fetcher, "executing " + fetchcmd) | ||
67 | ret = os.system(fetchcmd) | ||
68 | if ret != 0: | ||
69 | return False | ||
70 | |||
71 | # Sanity check since wget can pretend it succeed when it didn't | ||
72 | # Also, this used to happen if sourceforge sent us to the mirror page | ||
73 | if not os.path.exists(ud.localpath): | ||
74 | bb.msg.debug(2, bb.msg.domain.Fetcher, "The fetch command for %s returned success but %s doesn't exist?..." % (uri, ud.localpath)) | ||
75 | return False | ||
76 | |||
77 | return True | ||
78 | |||
79 | localdata = data.createCopy(d) | ||
80 | data.setVar('OVERRIDES', "wget:" + data.getVar('OVERRIDES', localdata), localdata) | ||
81 | data.update_data(localdata) | ||
82 | |||
83 | premirrors = [ i.split() for i in (data.getVar('PREMIRRORS', localdata, 1) or "").split('\n') if i ] | ||
84 | for (find, replace) in premirrors: | ||
85 | newuri = uri_replace(uri, find, replace, d) | ||
86 | if newuri != uri: | ||
87 | if fetch_uri(newuri, ud, localdata): | ||
88 | return True | ||
89 | |||
90 | if fetch_uri(uri, ud, localdata): | ||
91 | return True | ||
92 | |||
93 | # try mirrors | ||
94 | mirrors = [ i.split() for i in (data.getVar('MIRRORS', localdata, 1) or "").split('\n') if i ] | ||
95 | for (find, replace) in mirrors: | ||
96 | newuri = uri_replace(uri, find, replace, d) | ||
97 | if newuri != uri: | ||
98 | if fetch_uri(newuri, ud, localdata): | ||
99 | return True | ||
100 | |||
101 | raise FetchError(uri) | ||
102 | |||
103 | |||
104 | def checkstatus(self, uri, ud, d): | ||
105 | return self.go(uri, ud, d, True) | ||