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 svn repositories"""
38 """Check to see if a given url can be fetched with svn.
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 ['svn']
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("svn method needs a 'module' parameter")
54 module = parm["module"]
56 revision = parm['rev']
60 date = Fetch.getSRCDate(d)
62 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))
63 localpath = staticmethod(localpath)
65 def go(self, d, urls = []):
70 localdata = data.createCopy(d)
71 data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata)
72 data.update_data(localdata)
75 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, localdata))
76 if not "module" in parm:
77 raise MissingParameterError("svn method needs a 'module' parameter")
79 module = parm["module"]
81 dlfile = self.localpath(loc, localdata)
82 dldir = data.getVar('DL_DIR', localdata, 1)
83 # if local path contains the svn
84 # module, consider the dir above it to be the
86 # pos = dlfile.find(module)
88 # dldir = dlfile[:pos]
90 # dldir = os.path.dirname(dlfile)
95 revision = parm['rev']
99 date = Fetch.getSRCDate(d)
102 proto = parm["proto"]
107 if proto == "svn+ssh" and "rsh" in parm:
108 svn_rsh = parm["rsh"]
110 tarfn = data.expand('%s_%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), host, path.replace('/', '.'), revision, date), localdata)
111 data.setVar('TARFILES', dlfile, localdata)
112 data.setVar('TARFN', tarfn, localdata)
114 dl = os.path.join(dldir, tarfn)
115 if os.access(dl, os.R_OK):
116 bb.debug(1, "%s already exists, skipping svn checkout." % tarfn)
119 # try to use the tarball stash
120 if Fetch.try_mirror(d, tarfn):
123 olddir = os.path.abspath(os.getcwd())
124 os.chdir(data.expand(dldir, localdata))
126 svnroot = host + path
128 data.setVar('SVNROOT', svnroot, localdata)
129 data.setVar('SVNCOOPTS', " ".join(options), localdata)
130 data.setVar('SVNMODULE', module, localdata)
131 svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
132 svncmd = "svn co -r {%s} %s://%s/%s" % (date, proto, svnroot, module)
135 svncmd = "svn co -r %s %s://%s/%s" % (revision, proto, svnroot, module)
137 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
139 # create temp directory
140 bb.debug(2, "Fetch: creating temporary directory")
141 bb.mkdirhier(data.expand('${WORKDIR}', localdata))
142 data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvn.XXXXXX', localdata), localdata)
143 tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
144 tmpfile = tmppipe.readline().strip()
146 bb.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
147 raise FetchError(module)
149 # check out sources there
151 bb.note("Fetch " + loc)
152 bb.debug(1, "Running %s" % svncmd)
153 myret = os.system(svncmd)
159 raise FetchError(module)
161 os.chdir(os.path.join(tmpfile, os.path.dirname(module)))
162 # tar them up to a defined filename
163 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module)))
170 os.system('rm -rf %s' % tmpfile)