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
37 Class to fetch a module or modules from cvs repositories
39 def supports(self, url, ud, d):
41 Check to see if a given url can be fetched with cvs.
43 return ud.type in ['cvs', 'pserver']
45 def localpath(self, url, ud, d):
46 if not "module" in ud.parm:
47 raise MissingParameterError("cvs method needs a 'module' parameter")
48 ud.module = ud.parm["module"]
52 ud.tag = ud.parm['tag']
54 # Override the default date in certain cases
56 ud.date = ud.parm['date']
60 ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date), d)
62 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
64 def go(self, loc, ud, d):
66 localdata = data.createCopy(d)
67 data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata)
68 data.update_data(localdata)
73 if "method" in ud.parm:
74 method = ud.parm["method"]
78 if "localdir" in ud.parm:
79 localdir = ud.parm["localdir"]
86 cvs_rsh = ud.parm["rsh"]
88 # try to use the tarball stash
89 if (ud.date != "now") and Fetch.try_mirror(d, ud.localfile):
90 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping cvs checkout." % ud.localpath)
94 options.append("-D %s" % ud.date)
96 options.append("-r %s" % ud.tag)
102 cvsroot = ":" + method + ":" + ud.user
104 cvsroot += ":" + ud.pswd
105 cvsroot += "@" + ud.host + ":" + ud.path
107 data.setVar('CVSROOT', cvsroot, localdata)
108 data.setVar('CVSCOOPTS', " ".join(options), localdata)
109 data.setVar('CVSMODULE', ud.module, localdata)
110 cvscmd = data.getVar('FETCHCOMMAND', localdata, 1)
111 cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1)
114 cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
115 cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
117 # create module directory
118 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory")
119 pkg=data.expand('${PN}', d)
120 pkgdir=os.path.join(data.expand('${CVSDIR}', localdata), pkg)
121 moddir=os.path.join(pkgdir,localdir)
122 if os.access(os.path.join(moddir,'CVS'), os.R_OK):
123 bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
124 # update sources there
126 myret = os.system(cvsupdatecmd)
128 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
129 # check out sources there
132 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % cvscmd)
133 myret = os.system(cvscmd)
135 if myret != 0 or not os.access(moddir, os.R_OK):
140 raise FetchError(ud.module)
144 # tar them up to a defined filename
145 myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(moddir)))
148 os.unlink(ud.localpath)