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
36 """Class to fetch a module or modules from cvs repositories"""
38 """Check to see if a given url can be fetched with cvs.
39 Expects supplied url in list form, as outputted by bb.decodeurl().
41 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
42 return type in ['cvs', 'pserver']
43 supports = staticmethod(supports)
45 def localpath(url, d):
46 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
47 if "localpath" in parm:
48 # if user overrides local path, use it.
49 return parm["localpath"]
51 if not "module" in parm:
52 raise MissingParameterError("cvs method needs a 'module' parameter")
54 module = parm["module"]
63 date = Fetch.getSRCDate(d)
67 return os.path.join(data.getVar("DL_DIR", d, 1),data.expand('%s_%s_%s_%s.tar.gz' % ( module.replace('/', '.'), host, tag, date), d))
68 localpath = staticmethod(localpath)
70 def go(self, d, urls = []):
75 localdata = data.createCopy(d)
76 data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata)
77 data.update_data(localdata)
80 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, localdata))
81 if not "module" in parm:
82 raise MissingParameterError("cvs method needs a 'module' parameter")
84 module = parm["module"]
86 dlfile = self.localpath(loc, localdata)
87 dldir = data.getVar('DL_DIR', localdata, 1)
88 # if local path contains the cvs
89 # module, consider the dir above it to be the
91 # pos = dlfile.find(module)
93 # dldir = dlfile[:pos]
95 # dldir = os.path.dirname(dlfile)
108 date = Fetch.getSRCDate(d)
113 method = parm["method"]
117 if "localdir" in parm:
118 localdir = parm["localdir"]
125 cvs_rsh = parm["rsh"]
127 tarfn = data.expand('%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), host, tag, date), localdata)
128 data.setVar('TARFILES', dlfile, localdata)
129 data.setVar('TARFN', tarfn, localdata)
131 dl = os.path.join(dldir, tarfn)
132 if os.access(dl, os.R_OK):
133 bb.debug(1, "%s already exists, skipping cvs checkout." % tarfn)
136 pn = data.getVar('PN', d, 1)
137 cvs_tarball_stash = None
139 cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH_%s' % pn, d, 1)
140 if cvs_tarball_stash == None:
141 cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH', d, 1)
142 if cvs_tarball_stash:
143 fetchcmd = data.getVar("FETCHCOMMAND_wget", d, 1)
144 uri = cvs_tarball_stash + tarfn
145 bb.note("fetch " + uri)
146 fetchcmd = fetchcmd.replace("${URI}", uri)
147 ret = os.system(fetchcmd)
149 bb.note("Fetched %s from tarball stash, skipping checkout" % tarfn)
153 options.append("-D %s" % date)
155 options.append("-r %s" % tag)
157 olddir = os.path.abspath(os.getcwd())
158 os.chdir(data.expand(dldir, localdata))
164 cvsroot = ":" + method + ":" + user
166 cvsroot += ":" + pswd
167 cvsroot += "@" + host + ":" + path
169 data.setVar('CVSROOT', cvsroot, localdata)
170 data.setVar('CVSCOOPTS', " ".join(options), localdata)
171 data.setVar('CVSMODULE', module, localdata)
172 cvscmd = data.getVar('FETCHCOMMAND', localdata, 1)
173 cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1)
176 cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
177 cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
179 # create module directory
180 bb.debug(2, "Fetch: checking for module directory")
181 pkg=data.expand('${PN}', d)
182 pkgdir=os.path.join(data.expand('${CVSDIR}', localdata), pkg)
183 moddir=os.path.join(pkgdir,localdir)
184 if os.access(os.path.join(moddir,'CVS'), os.R_OK):
185 bb.note("Update " + loc)
186 # update sources there
188 myret = os.system(cvsupdatecmd)
190 bb.note("Fetch " + loc)
191 # check out sources there
194 bb.debug(1, "Running %s" % cvscmd)
195 myret = os.system(cvscmd)
197 if myret != 0 or not os.access(moddir, os.R_OK):
202 raise FetchError(module)
206 # tar them up to a defined filename
207 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(moddir)))