blob: 303a52b6384d25542e4c30eea3192f182f5078da [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake 'Fetch' implementations
5
6Classes for obtaining upstream sources for the
7BitBake build tools.
8
9"""
10
11# Copyright (C) 2003, 2004 Chris Larson
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License version 2 as
15# published by the Free Software Foundation.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License along
23# with this program; if not, write to the Free Software Foundation, Inc.,
24# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25#
26# Based on functions from the base bb module, Copyright 2003 Holger Schurig
27
28import os
29import urllib
30import bb
31import bb.utils
32from bb import data
33from bb.fetch2 import FetchMethod, FetchError
34from bb.fetch2 import logger
35
36class Local(FetchMethod):
37 def supports(self, urldata, d):
38 """
39 Check to see if a given url represents a local fetch.
40 """
41 return urldata.type in ['file']
42
43 def urldata_init(self, ud, d):
44 # We don't set localfile as for this fetcher the file is already local!
45 ud.decodedurl = urllib.unquote(ud.url.split("://")[1].split(";")[0])
46 ud.basename = os.path.basename(ud.decodedurl)
47 ud.basepath = ud.decodedurl
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050048 ud.needdonestamp = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049 return
50
51 def localpath(self, urldata, d):
52 """
53 Return the local filename of a given url assuming a successful fetch.
54 """
55 return self.localpaths(urldata, d)[-1]
56
57 def localpaths(self, urldata, d):
58 """
59 Return the local filename of a given url assuming a successful fetch.
60 """
61 searched = []
62 path = urldata.decodedurl
63 newpath = path
64 if path[0] == "/":
65 return [path]
66 filespath = data.getVar('FILESPATH', d, True)
67 if filespath:
68 logger.debug(2, "Searching for %s in paths:\n %s" % (path, "\n ".join(filespath.split(":"))))
69 newpath, hist = bb.utils.which(filespath, path, history=True)
70 searched.extend(hist)
71 if not newpath:
72 filesdir = data.getVar('FILESDIR', d, True)
73 if filesdir:
74 logger.debug(2, "Searching for %s in path: %s" % (path, filesdir))
75 newpath = os.path.join(filesdir, path)
76 searched.append(newpath)
77 if (not newpath or not os.path.exists(newpath)) and path.find("*") != -1:
78 # For expressions using '*', best we can do is take the first directory in FILESPATH that exists
79 newpath, hist = bb.utils.which(filespath, ".", history=True)
80 searched.extend(hist)
81 logger.debug(2, "Searching for %s in path: %s" % (path, newpath))
82 return searched
83 if not os.path.exists(newpath):
84 dldirfile = os.path.join(d.getVar("DL_DIR", True), path)
85 logger.debug(2, "Defaulting to %s for %s" % (dldirfile, path))
86 bb.utils.mkdirhier(os.path.dirname(dldirfile))
87 searched.append(dldirfile)
88 return searched
89 return searched
90
91 def need_update(self, ud, d):
92 if ud.url.find("*") != -1:
93 return False
94 if os.path.exists(ud.localpath):
95 return False
96 return True
97
98 def download(self, urldata, d):
99 """Fetch urls (no-op for Local method)"""
100 # no need to fetch local files, we'll deal with them in place.
101 if self.supports_checksum(urldata) and not os.path.exists(urldata.localpath):
102 locations = []
103 filespath = data.getVar('FILESPATH', d, True)
104 if filespath:
105 locations = filespath.split(":")
106 filesdir = data.getVar('FILESDIR', d, True)
107 if filesdir:
108 locations.append(filesdir)
109 locations.append(d.getVar("DL_DIR", True))
110
111 msg = "Unable to find file " + urldata.url + " anywhere. The paths that were searched were:\n " + "\n ".join(locations)
112 raise FetchError(msg)
113
114 return True
115
116 def checkstatus(self, fetch, urldata, d):
117 """
118 Check the status of the url
119 """
120 if urldata.localpath.find("*") != -1:
121 logger.info("URL %s looks like a glob and was therefore not checked.", urldata.url)
122 return True
123 if os.path.exists(urldata.localpath):
124 return True
125 return False
126
127 def clean(self, urldata, d):
128 return
129