2006-02-10 10:13:42 +00:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
"""
|
|
|
|
BitBake 'Fetch' implementations
|
|
|
|
|
|
|
|
Classes for obtaining upstream sources for the
|
|
|
|
BitBake build tools.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2007-01-08 23:53:01 +00:00
|
|
|
# Copyright (C) 2003, 2004 Chris Larson
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Based on functions from the base bb module, Copyright 2003 Holger Schurig
|
|
|
|
|
2009-11-03 23:14:53 +00:00
|
|
|
import os
|
2006-02-10 10:13:42 +00:00
|
|
|
import bb
|
|
|
|
from bb import data
|
|
|
|
from bb.fetch import Fetch
|
|
|
|
from bb.fetch import FetchError
|
|
|
|
|
|
|
|
class Wget(Fetch):
|
|
|
|
"""Class to fetch urls via 'wget'"""
|
2006-11-16 15:02:15 +00:00
|
|
|
def supports(self, url, ud, d):
|
2006-02-10 10:13:42 +00:00
|
|
|
"""
|
2010-01-20 18:46:02 +00:00
|
|
|
Check to see if a given url can be fetched with wget.
|
2006-11-16 15:02:15 +00:00
|
|
|
"""
|
|
|
|
return ud.type in ['http','https','ftp']
|
|
|
|
|
|
|
|
def localpath(self, url, ud, d):
|
|
|
|
|
|
|
|
url = bb.encodeurl([ud.type, ud.host, ud.path, ud.user, ud.pswd, {}])
|
|
|
|
ud.basename = os.path.basename(ud.path)
|
|
|
|
ud.localfile = data.expand(os.path.basename(url), d)
|
|
|
|
|
|
|
|
return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
|
|
|
|
|
2008-04-27 11:22:54 +00:00
|
|
|
def go(self, uri, ud, d, checkonly = False):
|
2006-02-10 10:13:42 +00:00
|
|
|
"""Fetch urls"""
|
|
|
|
|
2006-11-16 15:02:15 +00:00
|
|
|
def fetch_uri(uri, ud, d):
|
2008-04-27 11:22:54 +00:00
|
|
|
if checkonly:
|
2008-04-27 12:53:36 +00:00
|
|
|
fetchcmd = data.getVar("CHECKCOMMAND", d, 1)
|
2008-04-27 11:22:54 +00:00
|
|
|
elif os.path.exists(ud.localpath):
|
2006-11-16 15:02:15 +00:00
|
|
|
# file exists, but we didnt complete it.. trying again..
|
2006-02-10 10:13:42 +00:00
|
|
|
fetchcmd = data.getVar("RESUMECOMMAND", d, 1)
|
|
|
|
else:
|
|
|
|
fetchcmd = data.getVar("FETCHCOMMAND", d, 1)
|
|
|
|
|
2008-11-04 19:13:03 +00:00
|
|
|
uri = uri.split(";")[0]
|
|
|
|
uri_decoded = list(bb.decodeurl(uri))
|
|
|
|
uri_type = uri_decoded[0]
|
|
|
|
uri_host = uri_decoded[1]
|
|
|
|
|
2006-11-16 15:02:15 +00:00
|
|
|
bb.msg.note(1, bb.msg.domain.Fetcher, "fetch " + uri)
|
2009-01-06 19:56:02 +00:00
|
|
|
fetchcmd = fetchcmd.replace("${URI}", uri.split(";")[0])
|
2006-11-16 15:02:15 +00:00
|
|
|
fetchcmd = fetchcmd.replace("${FILE}", ud.basename)
|
2008-11-04 19:13:03 +00:00
|
|
|
httpproxy = None
|
|
|
|
ftpproxy = None
|
|
|
|
if uri_type == 'http':
|
|
|
|
httpproxy = data.getVar("HTTP_PROXY", d, True)
|
2008-11-04 21:11:58 +00:00
|
|
|
httpproxy_ignore = (data.getVar("HTTP_PROXY_IGNORE", d, True) or "").split()
|
2008-11-04 19:13:03 +00:00
|
|
|
for p in httpproxy_ignore:
|
|
|
|
if uri_host.endswith(p):
|
|
|
|
httpproxy = None
|
|
|
|
break
|
|
|
|
if uri_type == 'ftp':
|
|
|
|
ftpproxy = data.getVar("FTP_PROXY", d, True)
|
2008-11-04 21:11:58 +00:00
|
|
|
ftpproxy_ignore = (data.getVar("HTTP_PROXY_IGNORE", d, True) or "").split()
|
2008-11-04 19:13:03 +00:00
|
|
|
for p in ftpproxy_ignore:
|
|
|
|
if uri_host.endswith(p):
|
|
|
|
ftpproxy = None
|
|
|
|
break
|
2008-10-22 21:24:03 +00:00
|
|
|
if httpproxy:
|
|
|
|
fetchcmd = "http_proxy=" + httpproxy + " " + fetchcmd
|
|
|
|
if ftpproxy:
|
|
|
|
fetchcmd = "ftp_proxy=" + ftpproxy + " " + fetchcmd
|
2006-11-16 15:02:15 +00:00
|
|
|
bb.msg.debug(2, bb.msg.domain.Fetcher, "executing " + fetchcmd)
|
2006-02-10 10:13:42 +00:00
|
|
|
ret = os.system(fetchcmd)
|
|
|
|
if ret != 0:
|
|
|
|
return False
|
|
|
|
|
2008-01-20 12:09:31 +00:00
|
|
|
# Sanity check since wget can pretend it succeed when it didn't
|
|
|
|
# Also, this used to happen if sourceforge sent us to the mirror page
|
2009-07-07 21:44:53 +00:00
|
|
|
if not os.path.exists(ud.localpath) and not checkonly:
|
2008-01-20 12:09:31 +00:00
|
|
|
bb.msg.debug(2, bb.msg.domain.Fetcher, "The fetch command for %s returned success but %s doesn't exist?..." % (uri, ud.localpath))
|
2006-02-10 10:13:42 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
localdata = data.createCopy(d)
|
|
|
|
data.setVar('OVERRIDES', "wget:" + data.getVar('OVERRIDES', localdata), localdata)
|
|
|
|
data.update_data(localdata)
|
|
|
|
|
2006-11-16 15:02:15 +00:00
|
|
|
if fetch_uri(uri, ud, localdata):
|
2008-04-27 11:22:54 +00:00
|
|
|
return True
|
2006-11-16 15:02:15 +00:00
|
|
|
|
|
|
|
raise FetchError(uri)
|
2008-04-27 11:22:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def checkstatus(self, uri, ud, d):
|
|
|
|
return self.go(uri, ud, d, True)
|