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"""
38 def supports(self, url, ud, d):
40 Check to see if a given url can be fetched with svn.
42 return ud.type in ['svn']
44 def localpath(self, url, ud, d):
45 if not "module" in ud.parm:
46 raise MissingParameterError("svn method needs a 'module' parameter")
48 module = ud.parm["module"]
52 ud.revision = ud.parm['rev']
54 ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
56 return os.path.join(data.getVar("DL_DIR", d, 1), )
58 def go(self, loc, ud, d):
61 localdata = data.createCopy(d)
62 data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata)
63 data.update_data(localdata)
65 if not "module" in ud.parm:
66 raise MissingParameterError("svn method needs a 'module' parameter")
68 module = ud.parm["module"]
70 dlfile = self.localpath(loc, localdata)
71 dldir = data.getVar('DL_DIR', localdata, 1)
76 if "proto" in ud.parm:
77 proto = ud.parm["proto"]
82 if proto == "svn+ssh" and "rsh" in ud.parm:
83 svn_rsh = ud.parm["rsh"]
87 # try to use the tarball stash
88 if Fetch.check_for_tarball(d, tarfn, dldir, ud.date):
89 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % tarfn)
92 olddir = os.path.abspath(os.getcwd())
93 os.chdir(data.expand(dldir, localdata))
95 svnroot = ud.host + ud.path
97 # either use the revision, or SRCDATE in braces, or nothing for SRCDATE = "now"
99 options.append("-r %s" % ud.revision)
100 elif ud.date != "now":
101 options.append("-r {%s}" % ud.date)
103 data.setVar('SVNROOT', "%s://%s/%s" % (proto, svnroot, module), localdata)
104 data.setVar('SVNCOOPTS', " ".join(options), localdata)
105 data.setVar('SVNMODULE', module, localdata)
106 svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
107 svnupcmd = data.getVar('UPDATECOMMAND', localdata, 1)
110 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
111 svnupcmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svnupcmd)
113 pkg=data.expand('${PN}', d)
114 pkgdir=os.path.join(data.expand('${SVNDIR}', localdata), pkg)
115 moddir=os.path.join(pkgdir, module)
116 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + moddir + "'")
118 if os.access(os.path.join(moddir,'.svn'), os.R_OK):
119 bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
120 # update sources there
122 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnupcmd)
123 myret = os.system(svnupcmd)
125 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
126 # check out sources there
129 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svncmd)
130 myret = os.system(svncmd)
133 raise FetchError(module)
136 # tar them up to a defined filename
137 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module)))