local.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  25. import urllib
  26. import bb
  27. import bb.utils
  28. from bb import data
  29. from bb.fetch2 import FetchMethod, FetchError
  30. from bb.fetch2 import logger
  31. class Local(FetchMethod):
  32. def supports(self, url, urldata, d):
  33. """
  34. Check to see if a given url represents a local fetch.
  35. """
  36. return urldata.type in ['file']
  37. def urldata_init(self, ud, d):
  38. # We don't set localfile as for this fetcher the file is already local!
  39. ud.decodedurl = urllib.unquote(ud.url.split("://")[1].split(";")[0])
  40. ud.basename = os.path.basename(ud.decodedurl)
  41. return
  42. def localpath(self, url, urldata, d):
  43. """
  44. Return the local filename of a given url assuming a successful fetch.
  45. """
  46. path = urldata.decodedurl
  47. newpath = path
  48. if path[0] != "/":
  49. filespath = data.getVar('FILESPATH', d, True)
  50. if filespath:
  51. newpath = bb.utils.which(filespath, path)
  52. if not newpath:
  53. filesdir = data.getVar('FILESDIR', d, True)
  54. if filesdir:
  55. newpath = os.path.join(filesdir, path)
  56. if not os.path.exists(newpath) and path.find("*") == -1:
  57. dldirfile = os.path.join(d.getVar("DL_DIR", True), path)
  58. bb.utils.mkdirhier(os.path.dirname(dldirfile))
  59. return dldirfile
  60. return newpath
  61. def need_update(self, url, ud, d):
  62. if url.find("*") != -1:
  63. return False
  64. if os.path.exists(ud.localpath):
  65. return False
  66. return True
  67. def download(self, url, urldata, d):
  68. """Fetch urls (no-op for Local method)"""
  69. # no need to fetch local files, we'll deal with them in place.
  70. if self.supports_checksum(urldata) and not os.path.exists(urldata.localpath):
  71. locations = []
  72. filespath = data.getVar('FILESPATH', d, True)
  73. if filespath:
  74. locations = filespath.split(":")
  75. filesdir = data.getVar('FILESDIR', d, True)
  76. if filesdir:
  77. locations.append(filesdir)
  78. locations.append(d.getVar("DL_DIR", True))
  79. msg = "Unable to find file " + url + " anywhere. The paths that were searched were:\n " + "\n ".join(locations)
  80. raise FetchError(msg)
  81. return True
  82. def checkstatus(self, url, urldata, d):
  83. """
  84. Check the status of the url
  85. """
  86. if urldata.localpath.find("*") != -1:
  87. logger.info("URL %s looks like a glob and was therefore not checked.", url)
  88. return True
  89. if os.path.exists(urldata.localpath):
  90. return True
  91. return False
  92. def clean(self, urldata, d):
  93. return