8f106e73c29374bd5a23d37095b21f3e04cc94fc
[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             module = ud.parm["module"]
56         if 'rev' in ud.parm:
57             revision = ud.parm['rev']
58         else:
59             revision = ""
60
61         ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), revision, ud.date), d)
62
63         return os.path.join(data.getVar("DL_DIR", d, 1), 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         if not "module" in ud.parm:
73             raise MissingParameterError("svk method needs a 'module' parameter")
74         else:
75             module = ud.parm["module"]
76
77         dlfile = ud.localpath
78         dldir = data.getVar('DL_DIR', localdata, 1)
79
80         # setup svk options
81         options = []
82         if 'rev' in ud.parm:
83             revision = ud.parm['rev']
84         else:
85             revision = ""
86
87         tarfn = ud.localfile
88         data.setVar('TARFILES', dlfile, localdata)
89         data.setVar('TARFN', tarfn, localdata)
90
91         if (date != "now") and Fetch.try_mirror(d, ud.localfile):
92             return
93
94         olddir = os.path.abspath(os.getcwd())
95         os.chdir(data.expand(dldir, localdata))
96
97         svkroot = ud.host + ud.path
98
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)
103
104         if revision:
105             svkcmd = "svk co -r %s/%s" % (revision, svkroot, module)
106
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()
113         if not tmpfile:
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)
116
117         # check out sources there
118         os.chdir(tmpfile)
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)
122         if myret != 0:
123             try:
124                 os.rmdir(tmpfile)
125             except OSError:
126                 pass
127             raise FetchError(module)
128
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)))
132         if myret != 0:
133             try:
134                 os.unlink(tarfn)
135             except OSError:
136                 pass
137         # cleanup
138         os.system('rm -rf %s' % tmpfile)
139         os.chdir(olddir)
140