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 This implementation is for svk. It is based on the svn implementation
9 Copyright (C) 2006 Holger Hans Peter Freyther
15 Classes for obtaining upstream sources for the
18 Copyright (C) 2003, 2004 Chris Larson
20 This program is free software; you can redistribute it and/or modify it under
21 the terms of the GNU General Public License as published by the Free Software
22 Foundation; either version 2 of the License, or (at your option) any later
25 This program is distributed in the hope that it will be useful, but WITHOUT
26 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
27 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
29 You should have received a copy of the GNU General Public License along with
30 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
31 Place, Suite 330, Boston, MA 02111-1307 USA.
33 Based on functions from the base bb module, Copyright 2003 Holger Schurig
39 from bb.fetch import Fetch
40 from bb.fetch import FetchError
41 from bb.fetch import MissingParameterError
44 """Class to fetch a module or modules from svk repositories"""
45 def supports(self, url, ud, d):
47 Check to see if a given url can be fetched with cvs.
49 return ud.type in ['svk']
51 def localpath(self, url, ud, d):
52 if not "module" in ud.parm:
53 raise MissingParameterError("svk method needs a 'module' parameter")
55 module = ud.parm["module"]
57 revision = ud.parm['rev']
61 ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), revision, ud.date), d)
63 return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
65 def go(self, loc, ud, d):
68 localdata = data.createCopy(d)
69 data.setVar('OVERRIDES', "svk:%s" % data.getVar('OVERRIDES', localdata), localdata)
70 data.update_data(localdata)
72 if not "module" in ud.parm:
73 raise MissingParameterError("svk method needs a 'module' parameter")
75 module = ud.parm["module"]
78 dldir = data.getVar('DL_DIR', localdata, 1)
83 revision = ud.parm['rev']
88 data.setVar('TARFILES', dlfile, localdata)
89 data.setVar('TARFN', tarfn, localdata)
91 if (date != "now") and Fetch.try_mirror(d, ud.localfile):
94 olddir = os.path.abspath(os.getcwd())
95 os.chdir(data.expand(dldir, localdata))
97 svkroot = ud.host + ud.path
99 data.setVar('SVKROOT', svkroot, localdata)
100 data.setVar('SVKCOOPTS', " ".join(options), localdata)
101 data.setVar('SVKMODULE', module, localdata)
102 svkcmd = "svk co -r {%s} %s/%s" % (date, svkroot, module)
105 svkcmd = "svk co -r %s/%s" % (revision, svkroot, module)
107 # create temp directory
108 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: creating temporary directory")
109 bb.mkdirhier(data.expand('${WORKDIR}', localdata))
110 data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvk.XXXXXX', localdata), localdata)
111 tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
112 tmpfile = tmppipe.readline().strip()
114 bb.msg.error(bb.msg.domain.Fetcher, "Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
115 raise FetchError(module)
117 # check out sources there
119 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
120 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svkcmd)
121 myret = os.system(svkcmd)
127 raise FetchError(module)
129 os.chdir(os.path.join(tmpfile, os.path.dirname(module)))
130 # tar them up to a defined filename
131 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module)))
138 os.system('rm -rf %s' % tmpfile)