summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/svn.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/fetch2/svn.py')
-rw-r--r--bitbake/lib/bb/fetch2/svn.py191
1 files changed, 191 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..8847461913
--- /dev/null
+++ b/bitbake/lib/bb/fetch2/svn.py
@@ -0,0 +1,191 @@
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
30import re
31from bb import data
32from bb.fetch2 import FetchMethod
33from bb.fetch2 import FetchError
34from bb.fetch2 import MissingParameterError
35from bb.fetch2 import runfetchcmd
36from bb.fetch2 import logger
37
38class Svn(FetchMethod):
39 """Class to fetch a module or modules from svn repositories"""
40 def supports(self, ud, d):
41 """
42 Check to see if a given url can be fetched with svn.
43 """
44 return ud.type in ['svn']
45
46 def urldata_init(self, ud, d):
47 """
48 init svn specific variable within url data
49 """
50 if not "module" in ud.parm:
51 raise MissingParameterError('module', ud.url)
52
53 ud.basecmd = d.getVar('FETCHCMD_svn', True)
54
55 ud.module = ud.parm["module"]
56
57 # Create paths to svn checkouts
58 relpath = self._strip_leading_slashes(ud.path)
59 ud.pkgdir = os.path.join(data.expand('${SVNDIR}', d), ud.host, relpath)
60 ud.moddir = os.path.join(ud.pkgdir, ud.module)
61
62 ud.setup_revisons(d)
63
64 if 'rev' in ud.parm:
65 ud.revision = ud.parm['rev']
66
67 ud.localfile = data.expand('%s_%s_%s_%s_.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision), d)
68
69 def _buildsvncommand(self, ud, d, command):
70 """
71 Build up an svn commandline based on ud
72 command is "fetch", "update", "info"
73 """
74
75 proto = ud.parm.get('protocol', 'svn')
76
77 svn_rsh = None
78 if proto == "svn+ssh" and "rsh" in ud.parm:
79 svn_rsh = ud.parm["rsh"]
80
81 svnroot = ud.host + ud.path
82
83 options = []
84
85 options.append("--no-auth-cache")
86
87 if ud.user:
88 options.append("--username %s" % ud.user)
89
90 if ud.pswd:
91 options.append("--password %s" % ud.pswd)
92
93 if command == "info":
94 svncmd = "%s info %s %s://%s/%s/" % (ud.basecmd, " ".join(options), proto, svnroot, ud.module)
95 elif command == "log1":
96 svncmd = "%s log --limit 1 %s %s://%s/%s/" % (ud.basecmd, " ".join(options), proto, svnroot, ud.module)
97 else:
98 suffix = ""
99 if ud.revision:
100 options.append("-r %s" % ud.revision)
101 suffix = "@%s" % (ud.revision)
102
103 if command == "fetch":
104 svncmd = "%s co %s %s://%s/%s%s %s" % (ud.basecmd, " ".join(options), proto, svnroot, ud.module, suffix, ud.module)
105 elif command == "update":
106 svncmd = "%s update %s" % (ud.basecmd, " ".join(options))
107 else:
108 raise FetchError("Invalid svn command %s" % command, ud.url)
109
110 if svn_rsh:
111 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
112
113 return svncmd
114
115 def download(self, ud, d):
116 """Fetch url"""
117
118 logger.debug(2, "Fetch: checking for module directory '" + ud.moddir + "'")
119
120 if os.access(os.path.join(ud.moddir, '.svn'), os.R_OK):
121 svnupdatecmd = self._buildsvncommand(ud, d, "update")
122 logger.info("Update " + ud.url)
123 # update sources there
124 os.chdir(ud.moddir)
125 # We need to attempt to run svn upgrade first in case its an older working format
126 try:
127 runfetchcmd(ud.basecmd + " upgrade", d)
128 except FetchError:
129 pass
130 logger.debug(1, "Running %s", svnupdatecmd)
131 bb.fetch2.check_network_access(d, svnupdatecmd, ud.url)
132 runfetchcmd(svnupdatecmd, d)
133 else:
134 svnfetchcmd = self._buildsvncommand(ud, d, "fetch")
135 logger.info("Fetch " + ud.url)
136 # check out sources there
137 bb.utils.mkdirhier(ud.pkgdir)
138 os.chdir(ud.pkgdir)
139 logger.debug(1, "Running %s", svnfetchcmd)
140 bb.fetch2.check_network_access(d, svnfetchcmd, ud.url)
141 runfetchcmd(svnfetchcmd, d)
142
143 scmdata = ud.parm.get("scmdata", "")
144 if scmdata == "keep":
145 tar_flags = ""
146 else:
147 tar_flags = "--exclude '.svn'"
148
149 os.chdir(ud.pkgdir)
150 # tar them up to a defined filename
151 runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d, cleanup = [ud.localpath])
152
153 def clean(self, ud, d):
154 """ Clean SVN specific files and dirs """
155
156 bb.utils.remove(ud.localpath)
157 bb.utils.remove(ud.moddir, True)
158
159
160 def supports_srcrev(self):
161 return True
162
163 def _revision_key(self, ud, d, name):
164 """
165 Return a unique key for the url
166 """
167 return "svn:" + ud.moddir
168
169 def _latest_revision(self, ud, d, name):
170 """
171 Return the latest upstream revision number
172 """
173 bb.fetch2.check_network_access(d, self._buildsvncommand(ud, d, "log1"))
174
175 output = runfetchcmd("LANG=C LC_ALL=C " + self._buildsvncommand(ud, d, "log1"), d, True)
176
177 # skip the first line, as per output of svn log
178 # then we expect the revision on the 2nd line
179 revision = re.search('^r([0-9]*)', output.splitlines()[1]).group(1)
180
181 return revision
182
183 def sortable_revision(self, ud, d, name):
184 """
185 Return a sortable revision number which in our case is the revision number
186 """
187
188 return False, self._build_revision(ud, d)
189
190 def _build_revision(self, ud, d):
191 return ud.revision