summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/svn.py
diff options
context:
space:
mode:
authorYu Ke <ke.yu@intel.com>2011-01-10 14:23:36 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-01-10 14:23:36 +0000
commit4dccd92439f3b21056c53f2317249228067defe6 (patch)
treeb5507598213381b870f53b3f816102b0b2899b86 /bitbake/lib/bb/fetch2/svn.py
parentf46cdcbbae0ac3cbce423d262358e670add6065e (diff)
downloadpoky-4dccd92439f3b21056c53f2317249228067defe6.tar.gz
bitbake: copy bb.fetch to bb.fetch2 as initial code base for fetcher overhaul
Signed-off-by: Yu Ke <ke.yu@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/svn.py')
-rw-r--r--bitbake/lib/bb/fetch2/svn.py204
1 files changed, 204 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/svn.py b/bitbake/lib/bb/fetch2/svn.py
new file mode 100644
index 0000000000..8f053abf74
--- /dev/null
+++ b/bitbake/lib/bb/fetch2/svn.py
@@ -0,0 +1,204 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake 'Fetch' implementation for svn.
5
6"""
7
8# Copyright (C) 2003, 2004 Chris Larson
9# Copyright (C) 2004 Marcin Juszkiewicz
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License version 2 as
13# published by the Free Software Foundation.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License along
21# with this program; if not, write to the Free Software Foundation, Inc.,
22# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23#
24# Based on functions from the base bb module, Copyright 2003 Holger Schurig
25
26import os
27import sys
28import logging
29import bb
30from bb import data
31from bb.fetch import Fetch
32from bb.fetch import FetchError
33from bb.fetch import MissingParameterError
34from bb.fetch import runfetchcmd
35from bb.fetch import logger
36
37class Svn(Fetch):
38 """Class to fetch a module or modules from svn repositories"""
39 def supports(self, url, ud, d):
40 """
41 Check to see if a given url can be fetched with svn.
42 """
43 return ud.type in ['svn']
44
45 def localpath(self, url, ud, d):
46 if not "module" in ud.parm:
47 raise MissingParameterError("svn method needs a 'module' parameter")
48
49 ud.module = ud.parm["module"]
50
51 # Create paths to svn checkouts
52 relpath = self._strip_leading_slashes(ud.path)
53 ud.pkgdir = os.path.join(data.expand('${SVNDIR}', d), ud.host, relpath)
54 ud.moddir = os.path.join(ud.pkgdir, ud.module)
55
56 if 'rev' in ud.parm:
57 ud.date = ""
58 ud.revision = ud.parm['rev']
59 elif 'date' in ud.date:
60 ud.date = ud.parm['date']
61 ud.revision = ""
62 else:
63 #
64 # ***Nasty hack***
65 # If DATE in unexpanded PV, use ud.date (which is set from SRCDATE)
66 # Should warn people to switch to SRCREV here
67 #
68 pv = data.getVar("PV", d, 0)
69 if "DATE" in pv:
70 ud.revision = ""
71 else:
72 rev = Fetch.srcrev_internal_helper(ud, d)
73 if rev is True:
74 ud.revision = self.latest_revision(url, ud, d)
75 ud.date = ""
76 elif rev:
77 ud.revision = rev
78 ud.date = ""
79 else:
80 ud.revision = ""
81
82 ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
83
84 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
85
86 def _buildsvncommand(self, ud, d, command):
87 """
88 Build up an svn commandline based on ud
89 command is "fetch", "update", "info"
90 """
91
92 basecmd = data.expand('${FETCHCMD_svn}', d)
93
94 proto = ud.parm.get('proto', 'svn')
95
96 svn_rsh = None
97 if proto == "svn+ssh" and "rsh" in ud.parm:
98 svn_rsh = ud.parm["rsh"]
99
100 svnroot = ud.host + ud.path
101
102 # either use the revision, or SRCDATE in braces,
103 options = []
104
105 if ud.user:
106 options.append("--username %s" % ud.user)
107
108 if ud.pswd:
109 options.append("--password %s" % ud.pswd)
110
111 if command is "info":
112 svncmd = "%s info %s %s://%s/%s/" % (basecmd, " ".join(options), proto, svnroot, ud.module)
113 else:
114 suffix = ""
115 if ud.revision:
116 options.append("-r %s" % ud.revision)
117 suffix = "@%s" % (ud.revision)
118 elif ud.date:
119 options.append("-r {%s}" % ud.date)
120
121 if command is "fetch":
122 svncmd = "%s co %s %s://%s/%s%s %s" % (basecmd, " ".join(options), proto, svnroot, ud.module, suffix, ud.module)
123 elif command is "update":
124 svncmd = "%s update %s" % (basecmd, " ".join(options))
125 else:
126 raise FetchError("Invalid svn command %s" % command)
127
128 if svn_rsh:
129 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
130
131 return svncmd
132
133 def go(self, loc, ud, d):
134 """Fetch url"""
135
136 logger.debug(2, "Fetch: checking for module directory '" + ud.moddir + "'")
137
138 if os.access(os.path.join(ud.moddir, '.svn'), os.R_OK):
139 svnupdatecmd = self._buildsvncommand(ud, d, "update")
140 logger.info("Update " + loc)
141 # update sources there
142 os.chdir(ud.moddir)
143 logger.debug(1, "Running %s", svnupdatecmd)
144 runfetchcmd(svnupdatecmd, d)
145 else:
146 svnfetchcmd = self._buildsvncommand(ud, d, "fetch")
147 logger.info("Fetch " + loc)
148 # check out sources there
149 bb.mkdirhier(ud.pkgdir)
150 os.chdir(ud.pkgdir)
151 logger.debug(1, "Running %s", svnfetchcmd)
152 runfetchcmd(svnfetchcmd, d)
153
154 scmdata = ud.parm.get("scmdata", "")
155 if scmdata == "keep":
156 tar_flags = ""
157 else:
158 tar_flags = "--exclude '.svn'"
159
160 os.chdir(ud.pkgdir)
161 # tar them up to a defined filename
162 try:
163 runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d)
164 except:
165 t, v, tb = sys.exc_info()
166 try:
167 os.unlink(ud.localpath)
168 except OSError:
169 pass
170 raise t, v, tb
171
172 def supports_srcrev(self):
173 return True
174
175 def _revision_key(self, url, ud, d):
176 """
177 Return a unique key for the url
178 """
179 return "svn:" + ud.moddir
180
181 def _latest_revision(self, url, ud, d):
182 """
183 Return the latest upstream revision number
184 """
185 logger.debug(2, "SVN fetcher hitting network for %s", url)
186
187 output = runfetchcmd("LANG=C LC_ALL=C " + self._buildsvncommand(ud, d, "info"), d, True)
188
189 revision = None
190 for line in output.splitlines():
191 if "Last Changed Rev" in line:
192 revision = line.split(":")[1].strip()
193
194 return revision
195
196 def _sortable_revision(self, url, ud, d):
197 """
198 Return a sortable revision number which in our case is the revision number
199 """
200
201 return self._build_revision(url, ud, d)
202
203 def _build_revision(self, url, ud, d):
204 return ud.revision