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
32 from bb.fetch import Fetch
33 from bb.fetch import FetchError
34 from bb.fetch import MissingParameterError
37 """Class to fetch a module or modules from svn repositories"""
39 """Check to see if a given url can be fetched with svn.
40 Expects supplied url in list form, as outputted by bb.decodeurl().
42 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
43 return type in ['svn']
44 supports = staticmethod(supports)
46 def localpath(url, d):
47 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
48 if "localpath" in parm:
49 # if user overrides local path, use it.
50 return parm["localpath"]
52 if not "module" in parm:
53 raise MissingParameterError("svn method needs a 'module' parameter")
55 module = parm["module"]
57 revision = parm['rev']
61 date = Fetch.getSRCDate(d)
63 return os.path.join(data.getVar("DL_DIR", d, 1),data.expand('%s_%s_%s_%s_%s.tar.gz' % ( module.replace('/', '.'), host, path.replace('/', '.'), revision, date), d))
64 localpath = staticmethod(localpath)
66 def go(self, d, urls = []):
71 localdata = data.createCopy(d)
72 data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata)
73 data.update_data(localdata)
76 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, localdata))
77 if not "module" in parm:
78 raise MissingParameterError("svn method needs a 'module' parameter")
80 module = parm["module"]
82 dlfile = self.localpath(loc, localdata)
83 dldir = data.getVar('DL_DIR', localdata, 1)
84 # if local path contains the svn
85 # module, consider the dir above it to be the
87 # pos = dlfile.find(module)
89 # dldir = dlfile[:pos]
91 # dldir = os.path.dirname(dlfile)
96 revision = parm['rev']
100 date = Fetch.getSRCDate(d)
103 proto = parm["proto"]
108 if proto == "svn+ssh" and "rsh" in parm:
109 svn_rsh = parm["rsh"]
111 tarfn = data.expand('%s_%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), host, path.replace('/', '.'), revision, date), localdata)
112 data.setVar('TARFILES', dlfile, localdata)
113 data.setVar('TARFN', tarfn, localdata)
115 # try to use the tarball stash
116 if Fetch.check_for_tarball(d, tarfn, dldir, date):
117 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % tarfn)
120 olddir = os.path.abspath(os.getcwd())
121 os.chdir(data.expand(dldir, localdata))
123 svnroot = host + path
125 # either use the revision, or SRCDATE in braces, or nothing for SRCDATE = "now"
127 options.append("-r %s" % revision)
129 options.append("-r {%s}" % date)
131 data.setVar('SVNROOT', "%s://%s/%s" % (proto, svnroot, module), localdata)
132 data.setVar('SVNCOOPTS', " ".join(options), localdata)
133 data.setVar('SVNMODULE', module, localdata)
134 svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
135 svnupcmd = data.getVar('UPDATECOMMAND', localdata, 1)
138 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
139 svnupcmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svnupcmd)
141 pkg=data.expand('${PN}', d)
142 pkgdir=os.path.join(data.expand('${SVNDIR}', localdata), pkg)
143 moddir=os.path.join(pkgdir, module)
144 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + moddir + "'")
146 if os.access(os.path.join(moddir,'.svn'), os.R_OK):
147 bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
148 # update sources there
150 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnupcmd)
151 myret = os.system(svnupcmd)
153 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
154 # check out sources there
157 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svncmd)
158 myret = os.system(svncmd)
161 raise FetchError(module)
164 # tar them up to a defined filename
165 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module)))