diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/local.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/local.py | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/local.py b/bitbake/lib/bb/fetch2/local.py new file mode 100644 index 0000000000..0785236a6b --- /dev/null +++ b/bitbake/lib/bb/fetch2/local.py | |||
@@ -0,0 +1,128 @@ | |||
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 | |||
6 | Classes for obtaining upstream sources for the | ||
7 | BitBake 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 | |||
28 | import os | ||
29 | import urllib | ||
30 | import bb | ||
31 | import bb.utils | ||
32 | from bb import data | ||
33 | from bb.fetch2 import FetchMethod, FetchError | ||
34 | from bb.fetch2 import logger | ||
35 | |||
36 | class 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 | return self.localpaths(urldata, d)[-1] | ||
55 | |||
56 | def localpaths(self, urldata, d): | ||
57 | """ | ||
58 | Return the local filename of a given url assuming a successful fetch. | ||
59 | """ | ||
60 | searched = [] | ||
61 | path = urldata.decodedurl | ||
62 | newpath = path | ||
63 | if path[0] == "/": | ||
64 | return [path] | ||
65 | filespath = data.getVar('FILESPATH', d, True) | ||
66 | if filespath: | ||
67 | logger.debug(2, "Searching for %s in paths:\n %s" % (path, "\n ".join(filespath.split(":")))) | ||
68 | newpath, hist = bb.utils.which(filespath, path, history=True) | ||
69 | searched.extend(hist) | ||
70 | if not newpath: | ||
71 | filesdir = data.getVar('FILESDIR', d, True) | ||
72 | if filesdir: | ||
73 | logger.debug(2, "Searching for %s in path: %s" % (path, filesdir)) | ||
74 | newpath = os.path.join(filesdir, path) | ||
75 | searched.append(newpath) | ||
76 | if (not newpath or not os.path.exists(newpath)) and path.find("*") != -1: | ||
77 | # For expressions using '*', best we can do is take the first directory in FILESPATH that exists | ||
78 | newpath, hist = bb.utils.which(filespath, ".", history=True) | ||
79 | searched.extend(hist) | ||
80 | logger.debug(2, "Searching for %s in path: %s" % (path, newpath)) | ||
81 | return searched | ||
82 | if not os.path.exists(newpath): | ||
83 | dldirfile = os.path.join(d.getVar("DL_DIR", True), path) | ||
84 | logger.debug(2, "Defaulting to %s for %s" % (dldirfile, path)) | ||
85 | bb.utils.mkdirhier(os.path.dirname(dldirfile)) | ||
86 | searched.append(dldirfile) | ||
87 | return searched | ||
88 | return searched | ||
89 | |||
90 | def need_update(self, ud, d): | ||
91 | if ud.url.find("*") != -1: | ||
92 | return False | ||
93 | if os.path.exists(ud.localpath): | ||
94 | return False | ||
95 | return True | ||
96 | |||
97 | def download(self, urldata, d): | ||
98 | """Fetch urls (no-op for Local method)""" | ||
99 | # no need to fetch local files, we'll deal with them in place. | ||
100 | if self.supports_checksum(urldata) and not os.path.exists(urldata.localpath): | ||
101 | locations = [] | ||
102 | filespath = data.getVar('FILESPATH', d, True) | ||
103 | if filespath: | ||
104 | locations = filespath.split(":") | ||
105 | filesdir = data.getVar('FILESDIR', d, True) | ||
106 | if filesdir: | ||
107 | locations.append(filesdir) | ||
108 | locations.append(d.getVar("DL_DIR", True)) | ||
109 | |||
110 | msg = "Unable to find file " + urldata.url + " anywhere. The paths that were searched were:\n " + "\n ".join(locations) | ||
111 | raise FetchError(msg) | ||
112 | |||
113 | return True | ||
114 | |||
115 | def checkstatus(self, urldata, d): | ||
116 | """ | ||
117 | Check the status of the url | ||
118 | """ | ||
119 | if urldata.localpath.find("*") != -1: | ||
120 | logger.info("URL %s looks like a glob and was therefore not checked.", urldata.url) | ||
121 | return True | ||
122 | if os.path.exists(urldata.localpath): | ||
123 | return True | ||
124 | return False | ||
125 | |||
126 | def clean(self, urldata, d): | ||
127 | return | ||
128 | |||