local.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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, 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. ud.basepath = ud.decodedurl
  42. return
  43. def localpath(self, urldata, d):
  44. """
  45. Return the local filename of a given url assuming a successful fetch.
  46. """
  47. return self.localpaths(urldata, d)[-1]
  48. def localpaths(self, urldata, d):
  49. """
  50. Return the local filename of a given url assuming a successful fetch.
  51. """
  52. searched = []
  53. path = urldata.decodedurl
  54. newpath = path
  55. if path[0] == "/":
  56. return [path]
  57. filespath = data.getVar('FILESPATH', d, True)
  58. if filespath:
  59. logger.debug(2, "Searching for %s in paths:\n %s" % (path, "\n ".join(filespath.split(":"))))
  60. newpath, hist = bb.utils.which(filespath, path, history=True)
  61. searched.extend(hist)
  62. if not newpath:
  63. filesdir = data.getVar('FILESDIR', d, True)
  64. if filesdir:
  65. logger.debug(2, "Searching for %s in path: %s" % (path, filesdir))
  66. newpath = os.path.join(filesdir, path)
  67. searched.append(newpath)
  68. if (not newpath or not os.path.exists(newpath)) and path.find("*") != -1:
  69. # For expressions using '*', best we can do is take the first directory in FILESPATH that exists
  70. newpath, hist = bb.utils.which(filespath, ".", history=True)
  71. searched.extend(hist)
  72. logger.debug(2, "Searching for %s in path: %s" % (path, newpath))
  73. return searched
  74. if not os.path.exists(newpath):
  75. dldirfile = os.path.join(d.getVar("DL_DIR", True), path)
  76. logger.debug(2, "Defaulting to %s for %s" % (dldirfile, path))
  77. bb.utils.mkdirhier(os.path.dirname(dldirfile))
  78. searched.append(dldirfile)
  79. return searched
  80. return searched
  81. def need_update(self, ud, d):
  82. if ud.url.find("*") != -1:
  83. return False
  84. if os.path.exists(ud.localpath):
  85. return False
  86. return True
  87. def download(self, urldata, d):
  88. """Fetch urls (no-op for Local method)"""
  89. # no need to fetch local files, we'll deal with them in place.
  90. if self.supports_checksum(urldata) and not os.path.exists(urldata.localpath):
  91. locations = []
  92. filespath = data.getVar('FILESPATH', d, True)
  93. if filespath:
  94. locations = filespath.split(":")
  95. filesdir = data.getVar('FILESDIR', d, True)
  96. if filesdir:
  97. locations.append(filesdir)
  98. locations.append(d.getVar("DL_DIR", True))
  99. msg = "Unable to find file " + urldata.url + " anywhere. The paths that were searched were:\n " + "\n ".join(locations)
  100. raise FetchError(msg)
  101. return True
  102. def checkstatus(self, fetch, urldata, d):
  103. """
  104. Check the status of the url
  105. """
  106. if urldata.localpath.find("*") != -1:
  107. logger.info("URL %s looks like a glob and was therefore not checked.", urldata.url)
  108. return True
  109. if os.path.exists(urldata.localpath):
  110. return True
  111. return False
  112. def clean(self, urldata, d):
  113. return
  114. def try_premirror(self, urldata, d):
  115. """
  116. Should premirrors be used?
  117. """
  118. return False