2011-01-10 14:23:36 +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 .
"""
# 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
import os
import logging
import bb
import urllib
from bb import data
2011-02-07 23:42:45 +00:00
from bb . fetch2 import FetchMethod
from bb . fetch2 import FetchError
from bb . fetch2 import logger
from bb . fetch2 import runfetchcmd
2011-01-10 14:23:36 +00:00
2011-02-04 10:49:27 +00:00
class Wget ( FetchMethod ) :
2011-01-10 14:23:36 +00:00
""" Class to fetch urls via ' wget ' """
2013-11-19 14:32:08 +00:00
def supports ( self , ud , d ) :
2011-01-10 14:23:36 +00:00
"""
Check to see if a given url can be fetched with wget .
"""
return ud . type in [ ' http ' , ' https ' , ' ftp ' ]
2012-05-15 19:49:36 +00:00
def recommends_checksum ( self , urldata ) :
return True
2011-02-03 21:17:26 +00:00
def urldata_init ( self , ud , d ) :
2012-10-03 12:27:57 +00:00
if ' protocol ' in ud . parm :
if ud . parm [ ' protocol ' ] == ' git ' :
raise bb . fetch2 . ParameterError ( " Invalid protocol - if you wish to fetch from a git repository using http, you need to instead use the git:// prefix with protocol=http " , ud . url )
2011-01-10 14:23:36 +00:00
2012-07-19 00:39:18 +00:00
if ' downloadfilename ' in ud . parm :
ud . basename = ud . parm [ ' downloadfilename ' ]
else :
ud . basename = os . path . basename ( ud . path )
2011-01-10 14:23:36 +00:00
ud . localfile = data . expand ( urllib . unquote ( ud . basename ) , d )
2013-11-19 14:32:08 +00:00
def download ( self , ud , d , checkonly = False ) :
2011-01-10 14:23:36 +00:00
""" Fetch urls """
2012-07-09 16:44:08 +00:00
basecmd = d . getVar ( " FETCHCMD_wget " , True ) or " /usr/bin/env wget -t 2 -T 30 -nv --passive-ftp --no-check-certificate "
2013-02-14 21:33:04 +00:00
if not checkonly and ' downloadfilename ' in ud . parm :
2013-02-19 21:52:38 +00:00
dldir = d . getVar ( " DL_DIR " , True )
bb . utils . mkdirhier ( os . path . dirname ( dldir + os . sep + ud . localfile ) )
basecmd + = " -O " + dldir + os . sep + ud . localfile
2012-07-19 00:39:18 +00:00
2012-05-04 17:26:40 +00:00
if checkonly :
2014-02-28 17:56:04 +00:00
fetchcmd = d . expand ( basecmd + " --spider ' $ {URI} ' " )
2012-05-04 17:26:40 +00:00
elif os . path . exists ( ud . localpath ) :
# file exists, but we didnt complete it.. trying again..
2014-02-28 17:56:04 +00:00
fetchcmd = d . expand ( basecmd + " -c -P $ {DL_DIR} ' $ {URI} ' " )
2012-05-04 17:26:40 +00:00
else :
2014-02-28 17:56:04 +00:00
fetchcmd = d . expand ( basecmd + " -P $ {DL_DIR} ' $ {URI} ' " )
2011-01-10 14:23:36 +00:00
2013-11-19 14:32:08 +00:00
uri = ud . url . split ( " ; " ) [ 0 ]
2011-01-10 14:23:36 +00:00
2012-05-04 17:26:40 +00:00
fetchcmd = fetchcmd . replace ( " $ {URI} " , uri . split ( " ; " ) [ 0 ] )
fetchcmd = fetchcmd . replace ( " $ {FILE} " , ud . basename )
if not checkonly :
logger . info ( " fetch " + uri )
logger . debug ( 2 , " executing " + fetchcmd )
bb . fetch2 . check_network_access ( d , fetchcmd )
runfetchcmd ( fetchcmd , d , quiet = checkonly )
2011-01-10 14:23:36 +00:00
2012-05-04 17:26:40 +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
if not os . path . exists ( ud . localpath ) and not checkonly :
raise FetchError ( " The fetch command returned success for url %s but %s doesn ' t exist?! " % ( uri , ud . localpath ) , uri )
2012-05-04 17:27:31 +00:00
2014-01-21 09:58:21 +00:00
if not checkonly and os . path . getsize ( ud . localpath ) == 0 :
os . remove ( ud . localpath )
raise FetchError ( " The fetch of %s resulted in a zero size file?! Deleting and failing since this isn ' t right. " % ( uri ) , uri )
2011-02-04 10:26:21 +00:00
return True
2011-01-10 14:23:36 +00:00
2013-11-19 14:32:08 +00:00
def checkstatus ( self , ud , d ) :
return self . download ( ud , d , True )