2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
5 BitBake 'Fetch' implementations
7 Classes for obtaining upstream sources for the
10 Copyright (C) 2003, 2004 Chris Larson
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free Software
14 Foundation; either version 2 of the License, or (at your option) any later
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 USA.
25 Based on functions from the base bb module, Copyright 2003 Holger Schurig
31 from bb.fetch import Fetch
32 from bb.fetch import FetchError
33 from bb.fetch import MissingParameterError
35 class Perforce(Fetch):
36 def supports(self, url, ud, d):
37 return ud.type in ['p4']
41 path = url.split("://")[1]
42 delim = path.find("@");
44 (user,pswd,host,port) = path.split('@')[0].split(":")
45 path = path.split('@')[1]
47 (host,port) = data.getVar('P4PORT', d).split(':')
51 if path.find(";") != -1:
54 plist = path.split(';')
57 (key,value) = item.split('=')
61 parm = dict(zip(keys,values))
62 path = "//" + path.split(';')[0]
63 host += ":%s" % (port)
64 parm["cset"] = Perforce.getcset(d, path, host, user, pswd, parm)
66 return host,path,user,pswd,parm
67 doparse = staticmethod(doparse)
69 def getcset(d, depot,host,user,pswd,parm):
73 data.setVar('P4USER', user, d)
75 data.setVar('P4PASSWD', pswd, d)
77 data.setVar('P4PORT', host, d)
79 p4date = data.getVar("P4DATE", d, 1)
80 if "revision" in parm:
81 depot += "#%s" % (parm["revision"])
83 depot += "@%s" % (parm["label"])
85 depot += "@%s" % (p4date)
87 p4cmd = data.getVar('FETCHCOMMAND_p4', d, 1)
88 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s changes -m 1 %s" % (p4cmd, depot))
89 p4file = os.popen("%s changes -m 1 %s" % (p4cmd,depot))
90 cset = p4file.readline().strip()
91 bb.msg.debug(1, bb.msg.domain.Fetcher, "READ %s" % (cset))
95 return cset.split(' ')[1]
96 getcset = staticmethod(getcset)
98 def localpath(self, url, ud, d):
100 (host,path,user,pswd,parm) = Perforce.doparse(url,d)
102 # If a label is specified, we use that as our filename
105 ud.localfile = "%s.tar.gz" % (parm["label"])
106 return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
109 which = path.find('/...')
116 cset = Perforce.getcset(d, path, host, user, pswd, parm)
118 ud.localfile = data.expand('%s+%s+%s.tar.gz' % (host,base.replace('/', '.'), cset), d)
120 return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
122 def go(self, loc, ud, d):
127 # try to use the tarball stash
128 if not self.forcefetch(loc, ud, d) and Fetch.try_mirror(d, ud.localfile):
129 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping perforce checkout." % ud.localpath)
132 (host,depot,user,pswd,parm) = Perforce.doparse(loc, d)
134 if depot.find('/...') != -1:
135 path = depot[:depot.find('/...')]
140 module = parm["module"]
142 module = os.path.basename(path)
144 localdata = data.createCopy(d)
145 data.setVar('OVERRIDES', "p4:%s" % data.getVar('OVERRIDES', localdata), localdata)
146 data.update_data(localdata)
150 data.setVar('P4USER', user, localdata)
153 data.setVar('P4PASSWD', pswd, localdata)
156 data.setVar('P4PORT', host, localdata)
158 p4cmd = data.getVar('FETCHCOMMAND', localdata, 1)
160 # create temp directory
161 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: creating temporary directory")
162 bb.mkdirhier(data.expand('${WORKDIR}', localdata))
163 data.setVar('TMPBASE', data.expand('${WORKDIR}/oep4.XXXXXX', localdata), localdata)
164 tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
165 tmpfile = tmppipe.readline().strip()
167 bb.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
168 raise FetchError(module)
171 depot = "%s@%s" % (depot,parm["label"])
173 cset = Perforce.getcset(d, depot, host, user, pswd, parm)
174 depot = "%s@%s" % (depot,cset)
177 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
178 bb.msg.note(1, bb.msg.domain.Fetcher, "%s files %s" % (p4cmd, depot))
179 p4file = os.popen("%s files %s" % (p4cmd, depot))
182 bb.error("Fetch: unable to get the P4 files from %s" % (depot))
183 raise FetchError(module)
190 if list[2] == "delete":
193 dest = list[0][len(path)+1:]
194 where = dest.find("#")
196 os.system("%s print -o %s/%s %s" % (p4cmd, module,dest[:where],list[0]))
200 bb.error("Fetch: No files gathered from the P4 fetch")
201 raise FetchError(module)
203 myret = os.system("tar -czf %s %s" % (ud.localpath, module))
206 os.unlink(ud.localpath)
209 raise FetchError(module)
211 os.system('rm -rf %s' % tmpfile)