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