fetchers: Cleanup more variables
[vuplus_bitbake] / lib / bb / fetch / svk.py
1 #!/usr/bin/env python
2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4 """
5 BitBake 'Fetch' implementations
6
7 This implementation is for svk. It is based on the svn implementation
8
9 Copyright (C) 2006 Holger Hans Peter Freyther
10
11 GPL and MIT licensed
12
13
14
15 Classes for obtaining upstream sources for the
16 BitBake build tools.
17
18 Copyright (C) 2003, 2004  Chris Larson
19
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
23 version.
24
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.
28
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. 
32
33 Based on functions from the base bb module, Copyright 2003 Holger Schurig
34 """
35
36 import os, re
37 import bb
38 from   bb import data
39 from   bb.fetch import Fetch
40 from   bb.fetch import FetchError
41 from   bb.fetch import MissingParameterError
42
43 class Svk(Fetch):
44     """Class to fetch a module or modules from svk repositories"""
45     def supports(self, url, ud, d):
46         """
47         Check to see if a given url can be fetched with cvs.
48         """
49         return ud.type in ['svk']
50
51     def localpath(self, url, ud, d):
52         if not "module" in ud.parm:
53             raise MissingParameterError("svk method needs a 'module' parameter")
54         else:
55             ud.module = ud.parm["module"]
56
57         ud.revision = ""
58         if 'rev' in ud.parm:
59             ud.revision = ud.parm['rev']
60
61         ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
62
63         return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
64
65     def go(self, loc, ud, d):
66         """Fetch urls"""
67
68         localdata = data.createCopy(d)
69         data.setVar('OVERRIDES', "svk:%s" % data.getVar('OVERRIDES', localdata), localdata)
70         data.update_data(localdata)
71
72         # setup svk options
73         options = []
74
75         if (date != "now") and Fetch.try_mirror(d, ud.localfile):
76             return
77
78         svkroot = ud.host + ud.path
79
80         data.setVar('SVKROOT', svkroot, localdata)
81         data.setVar('SVKCOOPTS', " ".join(options), localdata)
82         data.setVar('SVKMODULE', ud.module, localdata)
83         svkcmd = "svk co -r {%s} %s/%s" % (date, svkroot, ud.module)
84
85         if ud.revision:
86             svkcmd = "svk co -r %s/%s" % (ud.revision, svkroot, ud.module)
87
88         # create temp directory
89         bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: creating temporary directory")
90         bb.mkdirhier(data.expand('${WORKDIR}', localdata))
91         data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvk.XXXXXX', localdata), localdata)
92         tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
93         tmpfile = tmppipe.readline().strip()
94         if not tmpfile:
95             bb.msg.error(bb.msg.domain.Fetcher, "Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
96             raise FetchError(ud.module)
97
98         # check out sources there
99         os.chdir(tmpfile)
100         bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
101         bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svkcmd)
102         myret = os.system(svkcmd)
103         if myret != 0:
104             try:
105                 os.rmdir(tmpfile)
106             except OSError:
107                 pass
108             raise FetchError(ud.module)
109
110         os.chdir(os.path.join(tmpfile, os.path.dirname(ud.module)))
111         # tar them up to a defined filename
112         myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)))
113         if myret != 0:
114             try:
115                 os.unlink(ud.localpath)
116             except OSError:
117                 pass
118         # cleanup
119         os.system('rm -rf %s' % tmpfile)