diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/svn.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/svn.py | 202 |
1 files changed, 202 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..1116795e87 --- /dev/null +++ b/bitbake/lib/bb/fetch2/svn.py | |||
@@ -0,0 +1,202 @@ | |||
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 logging | ||
29 | import bb | ||
30 | from bb import data | ||
31 | from bb.fetch2 import Fetch | ||
32 | from bb.fetch2 import FetchError | ||
33 | from bb.fetch2 import MissingParameterError | ||
34 | from bb.fetch2 import runfetchcmd | ||
35 | from bb.fetch2 import logger | ||
36 | |||
37 | class 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 urldata_init(self, ud, d): | ||
46 | """ | ||
47 | init svn specific variable within url data | ||
48 | """ | ||
49 | if not "module" in ud.parm: | ||
50 | raise MissingParameterError("svn method needs a 'module' parameter") | ||
51 | |||
52 | ud.module = ud.parm["module"] | ||
53 | |||
54 | # Create paths to svn checkouts | ||
55 | relpath = self._strip_leading_slashes(ud.path) | ||
56 | ud.pkgdir = os.path.join(data.expand('${SVNDIR}', d), ud.host, relpath) | ||
57 | ud.moddir = os.path.join(ud.pkgdir, ud.module) | ||
58 | |||
59 | def localpath(self, url, ud, d): | ||
60 | if 'rev' in ud.parm: | ||
61 | ud.date = "" | ||
62 | ud.revision = ud.parm['rev'] | ||
63 | elif 'date' in ud.date: | ||
64 | ud.date = ud.parm['date'] | ||
65 | ud.revision = "" | ||
66 | else: | ||
67 | # | ||
68 | # ***Nasty hack*** | ||
69 | # If DATE in unexpanded PV, use ud.date (which is set from SRCDATE) | ||
70 | # Should warn people to switch to SRCREV here | ||
71 | # | ||
72 | pv = data.getVar("PV", d, 0) | ||
73 | if "DATE" in pv: | ||
74 | ud.revision = "" | ||
75 | else: | ||
76 | # use the initizlied revision | ||
77 | if ud.revision: | ||
78 | ud.date = "" | ||
79 | |||
80 | ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d) | ||
81 | |||
82 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) | ||
83 | |||
84 | def _buildsvncommand(self, ud, d, command): | ||
85 | """ | ||
86 | Build up an svn commandline based on ud | ||
87 | command is "fetch", "update", "info" | ||
88 | """ | ||
89 | |||
90 | basecmd = data.expand('${FETCHCMD_svn}', d) | ||
91 | |||
92 | proto = ud.parm.get('proto', 'svn') | ||
93 | |||
94 | svn_rsh = None | ||
95 | if proto == "svn+ssh" and "rsh" in ud.parm: | ||
96 | svn_rsh = ud.parm["rsh"] | ||
97 | |||
98 | svnroot = ud.host + ud.path | ||
99 | |||
100 | # either use the revision, or SRCDATE in braces, | ||
101 | options = [] | ||
102 | |||
103 | if ud.user: | ||
104 | options.append("--username %s" % ud.user) | ||
105 | |||
106 | if ud.pswd: | ||
107 | options.append("--password %s" % ud.pswd) | ||
108 | |||
109 | if command is "info": | ||
110 | svncmd = "%s info %s %s://%s/%s/" % (basecmd, " ".join(options), proto, svnroot, ud.module) | ||
111 | else: | ||
112 | suffix = "" | ||
113 | if ud.revision: | ||
114 | options.append("-r %s" % ud.revision) | ||
115 | suffix = "@%s" % (ud.revision) | ||
116 | elif ud.date: | ||
117 | options.append("-r {%s}" % ud.date) | ||
118 | |||
119 | if command is "fetch": | ||
120 | svncmd = "%s co %s %s://%s/%s%s %s" % (basecmd, " ".join(options), proto, svnroot, ud.module, suffix, ud.module) | ||
121 | elif command is "update": | ||
122 | svncmd = "%s update %s" % (basecmd, " ".join(options)) | ||
123 | else: | ||
124 | raise FetchError("Invalid svn command %s" % command) | ||
125 | |||
126 | if svn_rsh: | ||
127 | svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd) | ||
128 | |||
129 | return svncmd | ||
130 | |||
131 | def go(self, loc, ud, d): | ||
132 | """Fetch url""" | ||
133 | |||
134 | logger.debug(2, "Fetch: checking for module directory '" + ud.moddir + "'") | ||
135 | |||
136 | if os.access(os.path.join(ud.moddir, '.svn'), os.R_OK): | ||
137 | svnupdatecmd = self._buildsvncommand(ud, d, "update") | ||
138 | logger.info("Update " + loc) | ||
139 | # update sources there | ||
140 | os.chdir(ud.moddir) | ||
141 | logger.debug(1, "Running %s", svnupdatecmd) | ||
142 | runfetchcmd(svnupdatecmd, d) | ||
143 | else: | ||
144 | svnfetchcmd = self._buildsvncommand(ud, d, "fetch") | ||
145 | logger.info("Fetch " + loc) | ||
146 | # check out sources there | ||
147 | bb.mkdirhier(ud.pkgdir) | ||
148 | os.chdir(ud.pkgdir) | ||
149 | logger.debug(1, "Running %s", svnfetchcmd) | ||
150 | runfetchcmd(svnfetchcmd, d) | ||
151 | |||
152 | scmdata = ud.parm.get("scmdata", "") | ||
153 | if scmdata == "keep": | ||
154 | tar_flags = "" | ||
155 | else: | ||
156 | tar_flags = "--exclude '.svn'" | ||
157 | |||
158 | os.chdir(ud.pkgdir) | ||
159 | # tar them up to a defined filename | ||
160 | try: | ||
161 | runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d) | ||
162 | except: | ||
163 | t, v, tb = sys.exc_info() | ||
164 | try: | ||
165 | os.unlink(ud.localpath) | ||
166 | except OSError: | ||
167 | pass | ||
168 | raise t, v, tb | ||
169 | |||
170 | def supports_srcrev(self): | ||
171 | return True | ||
172 | |||
173 | def _revision_key(self, url, ud, d): | ||
174 | """ | ||
175 | Return a unique key for the url | ||
176 | """ | ||
177 | return "svn:" + ud.moddir | ||
178 | |||
179 | def _latest_revision(self, url, ud, d): | ||
180 | """ | ||
181 | Return the latest upstream revision number | ||
182 | """ | ||
183 | logger.debug(2, "SVN fetcher hitting network for %s", url) | ||
184 | |||
185 | output = runfetchcmd("LANG=C LC_ALL=C " + self._buildsvncommand(ud, d, "info"), d, True) | ||
186 | |||
187 | revision = None | ||
188 | for line in output.splitlines(): | ||
189 | if "Last Changed Rev" in line: | ||
190 | revision = line.split(":")[1].strip() | ||
191 | |||
192 | return revision | ||
193 | |||
194 | def _sortable_revision(self, url, ud, d): | ||
195 | """ | ||
196 | Return a sortable revision number which in our case is the revision number | ||
197 | """ | ||
198 | |||
199 | return self._build_revision(url, ud, d) | ||
200 | |||
201 | def _build_revision(self, url, ud, d): | ||
202 | return ud.revision | ||