summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/local.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/fetch2/local.py')
-rw-r--r--bitbake/lib/bb/fetch2/local.py116
1 files changed, 116 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/local.py b/bitbake/lib/bb/fetch2/local.py
new file mode 100644
index 0000000..5c4e42a
--- /dev/null
+++ b/bitbake/lib/bb/fetch2/local.py
@@ -0,0 +1,116 @@
1# 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
48 return
49
50 def localpath(self, urldata, d):
51 """
52 Return the local filename of a given url assuming a successful fetch.
53 """
54 path = urldata.decodedurl
55 newpath = path
56 if path[0] != "/":
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 = bb.utils.which(filespath, path)
61 if not newpath:
62 filesdir = data.getVar('FILESDIR', d, True)
63 if filesdir:
64 logger.debug(2, "Searching for %s in path: %s" % (path, filesdir))
65 newpath = os.path.join(filesdir, path)
66 if (not newpath or not os.path.exists(newpath)) and path.find("*") != -1:
67 # For expressions using '*', best we can do is take the first directory in FILESPATH that exists
68 newpath = bb.utils.which(filespath, ".")
69 logger.debug(2, "Searching for %s in path: %s" % (path, newpath))
70 return newpath
71 if not os.path.exists(newpath):
72 dldirfile = os.path.join(d.getVar("DL_DIR", True), path)
73 logger.debug(2, "Defaulting to %s for %s" % (dldirfile, path))
74 bb.utils.mkdirhier(os.path.dirname(dldirfile))
75 return dldirfile
76 return newpath
77
78 def need_update(self, ud, d):
79 if ud.url.find("*") != -1:
80 return False
81 if os.path.exists(ud.localpath):
82 return False
83 return True
84
85 def download(self, urldata, d):
86 """Fetch urls (no-op for Local method)"""
87 # no need to fetch local files, we'll deal with them in place.
88 if self.supports_checksum(urldata) and not os.path.exists(urldata.localpath):
89 locations = []
90 filespath = data.getVar('FILESPATH', d, True)
91 if filespath:
92 locations = filespath.split(":")
93 filesdir = data.getVar('FILESDIR', d, True)
94 if filesdir:
95 locations.append(filesdir)
96 locations.append(d.getVar("DL_DIR", True))
97
98 msg = "Unable to find file " + urldata.url + " anywhere. The paths that were searched were:\n " + "\n ".join(locations)
99 raise FetchError(msg)
100
101 return True
102
103 def checkstatus(self, urldata, d):
104 """
105 Check the status of the url
106 """
107 if urldata.localpath.find("*") != -1:
108 logger.info("URL %s looks like a glob and was therefore not checked.", urldata.url)
109 return True
110 if os.path.exists(urldata.localpath):
111 return True
112 return False
113
114 def clean(self, urldata, d):
115 return
116