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 ud.module = ud.parm["module"]
52 ud.revision = ud.parm['rev']
54 ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
56 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
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)
69 if "proto" in ud.parm:
70 proto = ud.parm["proto"]
73 if proto == "svn+ssh" and "rsh" in ud.parm:
74 svn_rsh = ud.parm["rsh"]
76 # try to use the tarball stash
77 if (date != "now") and Fetch.try_mirror(d, ud.localfile):
78 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % ud.localpath)
81 svnroot = ud.host + ud.path
83 # either use the revision, or SRCDATE in braces, or nothing for SRCDATE = "now"
85 options.append("-r %s" % ud.revision)
86 elif ud.date != "now":
87 options.append("-r {%s}" % ud.date)
89 data.setVar('SVNROOT', "%s://%s/%s" % (proto, svnroot, ud.module), localdata)
90 data.setVar('SVNCOOPTS', " ".join(options), localdata)
91 data.setVar('SVNMODULE', ud.module, localdata)
92 svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
93 svnupcmd = data.getVar('UPDATECOMMAND', localdata, 1)
96 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
97 svnupcmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svnupcmd)
99 pkg=data.expand('${PN}', d)
100 pkgdir=os.path.join(data.expand('${SVNDIR}', localdata), pkg)
101 moddir=os.path.join(pkgdir, ud.module)
102 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + moddir + "'")
104 if os.access(os.path.join(moddir,'.svn'), os.R_OK):
105 bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
106 # update sources there
108 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnupcmd)
109 myret = os.system(svnupcmd)
111 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
112 # check out sources there
115 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svncmd)
116 myret = os.system(svncmd)
119 raise FetchError(ud.module)
122 # tar them up to a defined filename
123 myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)))
126 os.unlink(ud.localpath)