summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/perforce.py
diff options
context:
space:
mode:
authorYu Ke <ke.yu@intel.com>2011-01-10 14:23:36 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-01-10 14:23:36 +0000
commit4dccd92439f3b21056c53f2317249228067defe6 (patch)
treeb5507598213381b870f53b3f816102b0b2899b86 /bitbake/lib/bb/fetch2/perforce.py
parentf46cdcbbae0ac3cbce423d262358e670add6065e (diff)
downloadpoky-4dccd92439f3b21056c53f2317249228067defe6.tar.gz
bitbake: copy bb.fetch to bb.fetch2 as initial code base for fetcher overhaul
Signed-off-by: Yu Ke <ke.yu@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/perforce.py')
-rw-r--r--bitbake/lib/bb/fetch2/perforce.py206
1 files changed, 206 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py
new file mode 100644
index 0000000000..222ed7eaaa
--- /dev/null
+++ b/bitbake/lib/bb/fetch2/perforce.py
@@ -0,0 +1,206 @@
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
28from future_builtins import zip
29import os
30import logging
31import bb
32from bb import data
33from bb.fetch import Fetch
34from bb.fetch import FetchError
35from bb.fetch import logger
36
37class Perforce(Fetch):
38 def supports(self, url, ud, d):
39 return ud.type in ['p4']
40
41 def doparse(url, d):
42 parm = {}
43 path = url.split("://")[1]
44 delim = path.find("@");
45 if delim != -1:
46 (user, pswd, host, port) = path.split('@')[0].split(":")
47 path = path.split('@')[1]
48 else:
49 (host, port) = data.getVar('P4PORT', d).split(':')
50 user = ""
51 pswd = ""
52
53 if path.find(";") != -1:
54 keys=[]
55 values=[]
56 plist = path.split(';')
57 for item in plist:
58 if item.count('='):
59 (key, value) = item.split('=')
60 keys.append(key)
61 values.append(value)
62
63 parm = dict(zip(keys, values))
64 path = "//" + path.split(';')[0]
65 host += ":%s" % (port)
66 parm["cset"] = Perforce.getcset(d, path, host, user, pswd, parm)
67
68 return host, path, user, pswd, parm
69 doparse = staticmethod(doparse)
70
71 def getcset(d, depot, host, user, pswd, parm):
72 p4opt = ""
73 if "cset" in parm:
74 return parm["cset"];
75 if user:
76 p4opt += " -u %s" % (user)
77 if pswd:
78 p4opt += " -P %s" % (pswd)
79 if host:
80 p4opt += " -p %s" % (host)
81
82 p4date = data.getVar("P4DATE", d, 1)
83 if "revision" in parm:
84 depot += "#%s" % (parm["revision"])
85 elif "label" in parm:
86 depot += "@%s" % (parm["label"])
87 elif p4date:
88 depot += "@%s" % (p4date)
89
90 p4cmd = data.getVar('FETCHCOMMAND_p4', d, 1)
91 logger.debug(1, "Running %s%s changes -m 1 %s", p4cmd, p4opt, depot)
92 p4file = os.popen("%s%s changes -m 1 %s" % (p4cmd, p4opt, depot))
93 cset = p4file.readline().strip()
94 logger.debug(1, "READ %s", cset)
95 if not cset:
96 return -1
97
98 return cset.split(' ')[1]
99 getcset = staticmethod(getcset)
100
101 def localpath(self, url, ud, d):
102
103 (host, path, user, pswd, parm) = Perforce.doparse(url, d)
104
105 # If a label is specified, we use that as our filename
106
107 if "label" in parm:
108 ud.localfile = "%s.tar.gz" % (parm["label"])
109 return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
110
111 base = path
112 which = path.find('/...')
113 if which != -1:
114 base = path[:which]
115
116 base = self._strip_leading_slashes(base)
117
118 cset = Perforce.getcset(d, path, host, user, pswd, parm)
119
120 ud.localfile = data.expand('%s+%s+%s.tar.gz' % (host, base.replace('/', '.'), cset), d)
121
122 return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
123
124 def go(self, loc, ud, d):
125 """
126 Fetch urls
127 """
128
129 (host, depot, user, pswd, parm) = Perforce.doparse(loc, d)
130
131 if depot.find('/...') != -1:
132 path = depot[:depot.find('/...')]
133 else:
134 path = depot
135
136 module = parm.get('module', os.path.basename(path))
137
138 localdata = data.createCopy(d)
139 data.setVar('OVERRIDES', "p4:%s" % data.getVar('OVERRIDES', localdata), localdata)
140 data.update_data(localdata)
141
142 # Get the p4 command
143 p4opt = ""
144 if user:
145 p4opt += " -u %s" % (user)
146
147 if pswd:
148 p4opt += " -P %s" % (pswd)
149
150 if host:
151 p4opt += " -p %s" % (host)
152
153 p4cmd = data.getVar('FETCHCOMMAND', localdata, 1)
154
155 # create temp directory
156 logger.debug(2, "Fetch: creating temporary directory")
157 bb.mkdirhier(data.expand('${WORKDIR}', localdata))
158 data.setVar('TMPBASE', data.expand('${WORKDIR}/oep4.XXXXXX', localdata), localdata)
159 tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
160 tmpfile = tmppipe.readline().strip()
161 if not tmpfile:
162 logger.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
163 raise FetchError(module)
164
165 if "label" in parm:
166 depot = "%s@%s" % (depot, parm["label"])
167 else:
168 cset = Perforce.getcset(d, depot, host, user, pswd, parm)
169 depot = "%s@%s" % (depot, cset)
170
171 os.chdir(tmpfile)
172 logger.info("Fetch " + loc)
173 logger.info("%s%s files %s", p4cmd, p4opt, depot)
174 p4file = os.popen("%s%s files %s" % (p4cmd, p4opt, depot))
175
176 if not p4file:
177 logger.error("Fetch: unable to get the P4 files from %s", depot)
178 raise FetchError(module)
179
180 count = 0
181
182 for file in p4file:
183 list = file.split()
184
185 if list[2] == "delete":
186 continue
187
188 dest = list[0][len(path)+1:]
189 where = dest.find("#")
190
191 os.system("%s%s print -o %s/%s %s" % (p4cmd, p4opt, module, dest[:where], list[0]))
192 count = count + 1
193
194 if count == 0:
195 logger.error("Fetch: No files gathered from the P4 fetch")
196 raise FetchError(module)
197
198 myret = os.system("tar -czf %s %s" % (ud.localpath, module))
199 if myret != 0:
200 try:
201 os.unlink(ud.localpath)
202 except OSError:
203 pass
204 raise FetchError(module)
205 # cleanup
206 bb.utils.prunedir(tmpfile)