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 # try to use the tarball stash
132 if Fetch.try_mirror(d, tarfn):
133 bb.debug(1, "%s already exists or was mirrored, skipping cvs checkout." % tarfn)
137 options.append("-D %s" % date)
139 options.append("-r %s" % tag)
141 olddir = os.path.abspath(os.getcwd())
142 os.chdir(data.expand(dldir, localdata))
148 cvsroot = ":" + method + ":" + user
150 cvsroot += ":" + pswd
151 cvsroot += "@" + host + ":" + path
153 data.setVar('CVSROOT', cvsroot, localdata)
154 data.setVar('CVSCOOPTS', " ".join(options), localdata)
155 data.setVar('CVSMODULE', module, localdata)
156 cvscmd = data.getVar('FETCHCOMMAND', localdata, 1)
157 cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1)
160 cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
161 cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
163 # create module directory
164 bb.debug(2, "Fetch: checking for module directory")
165 pkg=data.expand('${PN}', d)
166 pkgdir=os.path.join(data.expand('${CVSDIR}', localdata), pkg)
167 moddir=os.path.join(pkgdir,localdir)
168 if os.access(os.path.join(moddir,'CVS'), os.R_OK):
169 bb.note("Update " + loc)
170 # update sources there
172 myret = os.system(cvsupdatecmd)
174 bb.note("Fetch " + loc)
175 # check out sources there
178 bb.debug(1, "Running %s" % cvscmd)
179 myret = os.system(cvscmd)
181 if myret != 0 or not os.access(moddir, os.R_OK):
186 raise FetchError(module)
190 # tar them up to a defined filename
191 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(moddir)))