svn.py: Fix a reference to parm
[vuplus_bitbake] / lib / bb / fetch / svn.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 Classes for obtaining upstream sources for the
8 BitBake build tools.
9
10 Copyright (C) 2003, 2004  Chris Larson
11
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
15 version.
16
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.
20
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. 
24
25 Based on functions from the base bb module, Copyright 2003 Holger Schurig
26 """
27
28 import os, re
29 import sys
30 import bb
31 from   bb import data
32 from   bb.fetch import Fetch
33 from   bb.fetch import FetchError
34 from   bb.fetch import MissingParameterError
35
36 class Svn(Fetch):
37     """Class to fetch a module or modules from svn repositories"""
38     def supports(self, url, ud, d):
39         """
40         Check to see if a given url can be fetched with svn.
41         """
42         return ud.type in ['svn']
43
44     def localpath(self, url, ud, d):
45         if not "module" in ud.parm:
46             raise MissingParameterError("svn method needs a 'module' parameter")
47         else:
48             ud.module = ud.parm["module"]
49
50         ud.revision = ""
51         if 'rev' in ud.parm:
52             ud.revision = ud.parm['rev']
53
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)
55
56         return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
57
58     def go(self, loc, ud, d):
59         """Fetch url"""
60
61         localdata = data.createCopy(d)
62         data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata)
63         data.update_data(localdata)
64
65         # setup svn options
66         options = []
67
68         proto = "svn"
69         if "proto" in ud.parm:
70             proto = ud.parm["proto"]
71
72         svn_rsh = None
73         if proto == "svn+ssh" and "rsh" in ud.parm:
74             svn_rsh = ud.parm["rsh"]
75
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)
79             return
80
81         svnroot = ud.host + ud.path
82
83         # either use the revision, or SRCDATE in braces, or nothing for SRCDATE = "now"
84         if ud.revision:
85             options.append("-r %s" % ud.revision)
86         elif ud.date != "now":
87             options.append("-r {%s}" % ud.date)
88
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)
94
95         if svn_rsh:
96             svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
97             svnupcmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svnupcmd)
98
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 + "'")
103
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
107             os.chdir(moddir)
108             bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnupcmd)
109             myret = os.system(svnupcmd)
110         else:
111             bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
112             # check out sources there
113             bb.mkdirhier(pkgdir)
114             os.chdir(pkgdir)
115             bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svncmd)
116             myret = os.system(svncmd)
117
118         if myret != 0:
119             raise FetchError(ud.module)
120
121         os.chdir(pkgdir)
122         # tar them up to a defined filename
123         myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)))
124         if myret != 0:
125             try:
126                 os.unlink(ud.localpath)
127             except OSError:
128                 pass