wget.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. Classes for obtaining upstream sources for the
  6. BitBake build tools.
  7. """
  8. # Copyright (C) 2003, 2004 Chris Larson
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License version 2 as
  12. # published by the Free Software Foundation.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. # Based on functions from the base bb module, Copyright 2003 Holger Schurig
  24. import os, re
  25. import bb
  26. from bb import data
  27. from bb.fetch import Fetch
  28. from bb.fetch import FetchError
  29. from bb.fetch import uri_replace
  30. class Wget(Fetch):
  31. """Class to fetch urls via 'wget'"""
  32. def supports(self, url, ud, d):
  33. """
  34. Check to see if a given url can be fetched with cvs.
  35. """
  36. return ud.type in ['http','https','ftp']
  37. def localpath(self, url, ud, d):
  38. url = bb.encodeurl([ud.type, ud.host, ud.path, ud.user, ud.pswd, {}])
  39. ud.basename = os.path.basename(ud.path)
  40. ud.localfile = data.expand(os.path.basename(url), d)
  41. return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
  42. def go(self, uri, ud, d):
  43. """Fetch urls"""
  44. def fetch_uri(uri, ud, d):
  45. if os.path.exists(ud.localpath):
  46. # file exists, but we didnt complete it.. trying again..
  47. fetchcmd = data.getVar("RESUMECOMMAND", d, 1)
  48. else:
  49. fetchcmd = data.getVar("FETCHCOMMAND", d, 1)
  50. bb.msg.note(1, bb.msg.domain.Fetcher, "fetch " + uri)
  51. fetchcmd = fetchcmd.replace("${URI}", uri)
  52. fetchcmd = fetchcmd.replace("${FILE}", ud.basename)
  53. bb.msg.debug(2, bb.msg.domain.Fetcher, "executing " + fetchcmd)
  54. ret = os.system(fetchcmd)
  55. if ret != 0:
  56. return False
  57. # check if sourceforge did send us to the mirror page
  58. if not os.path.exists(ud.localpath):
  59. os.system("rm %s*" % ud.localpath) # FIXME shell quote it
  60. bb.msg.debug(2, bb.msg.domain.Fetcher, "sourceforge.net send us to the mirror on %s" % ud.basename)
  61. return False
  62. return True
  63. localdata = data.createCopy(d)
  64. data.setVar('OVERRIDES', "wget:" + data.getVar('OVERRIDES', localdata), localdata)
  65. data.update_data(localdata)
  66. premirrors = [ i.split() for i in (data.getVar('PREMIRRORS', localdata, 1) or "").split('\n') if i ]
  67. for (find, replace) in premirrors:
  68. newuri = uri_replace(uri, find, replace, d)
  69. if newuri != uri:
  70. if fetch_uri(newuri, ud, localdata):
  71. return
  72. if fetch_uri(uri, ud, localdata):
  73. return
  74. # try mirrors
  75. mirrors = [ i.split() for i in (data.getVar('MIRRORS', localdata, 1) or "").split('\n') if i ]
  76. for (find, replace) in mirrors:
  77. newuri = uri_replace(uri, find, replace, d)
  78. if newuri != uri:
  79. if fetch_uri(newuri, ud, localdata):
  80. return
  81. raise FetchError(uri)