diff options
Diffstat (limited to 'bitbake-dev/lib/bb/fetch/svn.py')
-rw-r--r-- | bitbake-dev/lib/bb/fetch/svn.py | 206 |
1 files changed, 0 insertions, 206 deletions
diff --git a/bitbake-dev/lib/bb/fetch/svn.py b/bitbake-dev/lib/bb/fetch/svn.py deleted file mode 100644 index eef9862a84..0000000000 --- a/bitbake-dev/lib/bb/fetch/svn.py +++ /dev/null | |||
@@ -1,206 +0,0 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | """ | ||
4 | BitBake '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 | |||
26 | import os | ||
27 | import sys | ||
28 | import bb | ||
29 | from bb import data | ||
30 | from bb.fetch import Fetch | ||
31 | from bb.fetch import FetchError | ||
32 | from bb.fetch import MissingParameterError | ||
33 | from bb.fetch import runfetchcmd | ||
34 | |||
35 | class Svn(Fetch): | ||
36 | """Class to fetch a module or modules from svn repositories""" | ||
37 | def supports(self, url, ud, d): | ||
38 | """ | ||
39 | Check to see if a given url can be fetched with svn. | ||
40 | """ | ||
41 | return ud.type in ['svn'] | ||
42 | |||
43 | def localpath(self, url, ud, d): | ||
44 | if not "module" in ud.parm: | ||
45 | raise MissingParameterError("svn method needs a 'module' parameter") | ||
46 | |||
47 | ud.module = ud.parm["module"] | ||
48 | |||
49 | # Create paths to svn checkouts | ||
50 | relpath = ud.path | ||
51 | if relpath.startswith('/'): | ||
52 | # Remove leading slash as os.path.join can't cope | ||
53 | relpath = relpath[1:] | ||
54 | ud.pkgdir = os.path.join(data.expand('${SVNDIR}', d), ud.host, relpath) | ||
55 | ud.moddir = os.path.join(ud.pkgdir, ud.module) | ||
56 | |||
57 | if 'rev' in ud.parm: | ||
58 | ud.date = "" | ||
59 | ud.revision = ud.parm['rev'] | ||
60 | elif 'date' in ud.date: | ||
61 | ud.date = ud.parm['date'] | ||
62 | ud.revision = "" | ||
63 | else: | ||
64 | # | ||
65 | # ***Nasty hack*** | ||
66 | # If DATE in unexpanded PV, use ud.date (which is set from SRCDATE) | ||
67 | # Should warn people to switch to SRCREV here | ||
68 | # | ||
69 | pv = data.getVar("PV", d, 0) | ||
70 | if "DATE" in pv: | ||
71 | ud.revision = "" | ||
72 | else: | ||
73 | rev = Fetch.srcrev_internal_helper(ud, d) | ||
74 | if rev is True: | ||
75 | ud.revision = self.latest_revision(url, ud, d) | ||
76 | ud.date = "" | ||
77 | elif rev: | ||
78 | ud.revision = rev | ||
79 | ud.date = "" | ||
80 | else: | ||
81 | ud.revision = "" | ||
82 | |||
83 | ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d) | ||
84 | |||
85 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) | ||
86 | |||
87 | def _buildsvncommand(self, ud, d, command): | ||
88 | """ | ||
89 | Build up an svn commandline based on ud | ||
90 | command is "fetch", "update", "info" | ||
91 | """ | ||
92 | |||
93 | basecmd = data.expand('${FETCHCMD_svn}', d) | ||
94 | |||
95 | proto = "svn" | ||
96 | if "proto" in ud.parm: | ||
97 | proto = ud.parm["proto"] | ||
98 | |||
99 | svn_rsh = None | ||
100 | if proto == "svn+ssh" and "rsh" in ud.parm: | ||
101 | svn_rsh = ud.parm["rsh"] | ||
102 | |||
103 | svnroot = ud.host + ud.path | ||
104 | |||
105 | # either use the revision, or SRCDATE in braces, | ||
106 | options = [] | ||
107 | |||
108 | if ud.user: | ||
109 | options.append("--username %s" % ud.user) | ||
110 | |||
111 | if ud.pswd: | ||
112 | options.append("--password %s" % ud.pswd) | ||
113 | |||
114 | if command is "info": | ||
115 | svncmd = "%s info %s %s://%s/%s/" % (basecmd, " ".join(options), proto, svnroot, ud.module) | ||
116 | else: | ||
117 | suffix = "" | ||
118 | if ud.revision: | ||
119 | options.append("-r %s" % ud.revision) | ||
120 | suffix = "@%s" % (ud.revision) | ||
121 | elif ud.date: | ||
122 | options.append("-r {%s}" % ud.date) | ||
123 | |||
124 | if command is "fetch": | ||
125 | svncmd = "%s co %s %s://%s/%s%s %s" % (basecmd, " ".join(options), proto, svnroot, ud.module, suffix, ud.module) | ||
126 | elif command is "update": | ||
127 | svncmd = "%s update %s" % (basecmd, " ".join(options)) | ||
128 | else: | ||
129 | raise FetchError("Invalid svn command %s" % command) | ||
130 | |||
131 | if svn_rsh: | ||
132 | svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd) | ||
133 | |||
134 | return svncmd | ||
135 | |||
136 | def go(self, loc, ud, d): | ||
137 | """Fetch url""" | ||
138 | |||
139 | # try to use the tarball stash | ||
140 | if Fetch.try_mirror(d, ud.localfile): | ||
141 | bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % ud.localpath) | ||
142 | return | ||
143 | |||
144 | bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + ud.moddir + "'") | ||
145 | |||
146 | if os.access(os.path.join(ud.moddir, '.svn'), os.R_OK): | ||
147 | svnupdatecmd = self._buildsvncommand(ud, d, "update") | ||
148 | bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc) | ||
149 | # update sources there | ||
150 | os.chdir(ud.moddir) | ||
151 | bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnupdatecmd) | ||
152 | runfetchcmd(svnupdatecmd, d) | ||
153 | else: | ||
154 | svnfetchcmd = self._buildsvncommand(ud, d, "fetch") | ||
155 | bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc) | ||
156 | # check out sources there | ||
157 | bb.mkdirhier(ud.pkgdir) | ||
158 | os.chdir(ud.pkgdir) | ||
159 | bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnfetchcmd) | ||
160 | runfetchcmd(svnfetchcmd, d) | ||
161 | |||
162 | os.chdir(ud.pkgdir) | ||
163 | # tar them up to a defined filename | ||
164 | try: | ||
165 | runfetchcmd("tar -czf %s %s" % (ud.localpath, ud.module), d) | ||
166 | except: | ||
167 | t, v, tb = sys.exc_info() | ||
168 | try: | ||
169 | os.unlink(ud.localpath) | ||
170 | except OSError: | ||
171 | pass | ||
172 | raise t, v, tb | ||
173 | |||
174 | def suppports_srcrev(self): | ||
175 | return True | ||
176 | |||
177 | def _revision_key(self, url, ud, d): | ||
178 | """ | ||
179 | Return a unique key for the url | ||
180 | """ | ||
181 | return "svn:" + ud.moddir | ||
182 | |||
183 | def _latest_revision(self, url, ud, d): | ||
184 | """ | ||
185 | Return the latest upstream revision number | ||
186 | """ | ||
187 | bb.msg.debug(2, bb.msg.domain.Fetcher, "SVN fetcher hitting network for %s" % url) | ||
188 | |||
189 | output = runfetchcmd("LANG=C LC_ALL=C " + self._buildsvncommand(ud, d, "info"), d, True) | ||
190 | |||
191 | revision = None | ||
192 | for line in output.splitlines(): | ||
193 | if "Last Changed Rev" in line: | ||
194 | revision = line.split(":")[1].strip() | ||
195 | |||
196 | return revision | ||
197 | |||
198 | def _sortable_revision(self, url, ud, d): | ||
199 | """ | ||
200 | Return a sortable revision number which in our case is the revision number | ||
201 | """ | ||
202 | |||
203 | return self._build_revision(url, ud, d) | ||
204 | |||
205 | def _build_revision(self, url, ud, d): | ||
206 | return ud.revision | ||