The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2008 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 16 | import itertools |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 17 | import os |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 18 | import re |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 19 | import sys |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 20 | import urlparse |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 21 | import xml.dom.minidom |
| 22 | |
David Pursehouse | e15c65a | 2012-08-22 10:46:11 +0900 | [diff] [blame] | 23 | from git_config import GitConfig |
David Pursehouse | e00aa6b | 2012-09-11 14:33:51 +0900 | [diff] [blame] | 24 | from git_refs import R_HEADS, HEAD |
| 25 | from project import RemoteSpec, Project, MetaProject |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 26 | from error import ManifestParseError |
| 27 | |
| 28 | MANIFEST_FILE_NAME = 'manifest.xml' |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 29 | LOCAL_MANIFEST_NAME = 'local_manifest.xml' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 30 | |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 31 | urlparse.uses_relative.extend(['ssh', 'git']) |
| 32 | urlparse.uses_netloc.extend(['ssh', 'git']) |
| 33 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 34 | class _Default(object): |
| 35 | """Project defaults within the manifest.""" |
| 36 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 37 | revisionExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 38 | remote = None |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 39 | sync_j = 1 |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 40 | sync_c = False |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 41 | |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 42 | class _XmlRemote(object): |
| 43 | def __init__(self, |
| 44 | name, |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 45 | alias=None, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 46 | fetch=None, |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 47 | manifestUrl=None, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 48 | review=None): |
| 49 | self.name = name |
| 50 | self.fetchUrl = fetch |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 51 | self.manifestUrl = manifestUrl |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 52 | self.remoteAlias = alias |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 53 | self.reviewUrl = review |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 54 | self.resolvedFetchUrl = self._resolveFetchUrl() |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 55 | |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 56 | def _resolveFetchUrl(self): |
| 57 | url = self.fetchUrl.rstrip('/') |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 58 | manifestUrl = self.manifestUrl.rstrip('/') |
| 59 | # urljoin will get confused if there is no scheme in the base url |
| 60 | # ie, if manifestUrl is of the form <hostname:port> |
| 61 | if manifestUrl.find(':') != manifestUrl.find('/') - 1: |
| 62 | manifestUrl = 'gopher://' + manifestUrl |
| 63 | url = urlparse.urljoin(manifestUrl, url) |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 64 | return re.sub(r'^gopher://', '', url) |
| 65 | |
| 66 | def ToRemoteSpec(self, projectName): |
Conley Owens | 9d8f914 | 2011-10-20 14:36:35 -0700 | [diff] [blame] | 67 | url = self.resolvedFetchUrl.rstrip('/') + '/' + projectName |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 68 | remoteName = self.name |
| 69 | if self.remoteAlias: |
| 70 | remoteName = self.remoteAlias |
| 71 | return RemoteSpec(remoteName, url, self.reviewUrl) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 72 | |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 73 | class XmlManifest(object): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 74 | """manages the repo configuration file""" |
| 75 | |
| 76 | def __init__(self, repodir): |
| 77 | self.repodir = os.path.abspath(repodir) |
| 78 | self.topdir = os.path.dirname(self.repodir) |
| 79 | self.manifestFile = os.path.join(self.repodir, MANIFEST_FILE_NAME) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 | self.globalConfig = GitConfig.ForUser() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 81 | |
| 82 | self.repoProject = MetaProject(self, 'repo', |
| 83 | gitdir = os.path.join(repodir, 'repo/.git'), |
| 84 | worktree = os.path.join(repodir, 'repo')) |
| 85 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 86 | self.manifestProject = MetaProject(self, 'manifests', |
Shawn O. Pearce | f5c25a6 | 2008-11-04 08:11:53 -0800 | [diff] [blame] | 87 | gitdir = os.path.join(repodir, 'manifests.git'), |
| 88 | worktree = os.path.join(repodir, 'manifests')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 89 | |
| 90 | self._Unload() |
| 91 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 92 | def Override(self, name): |
| 93 | """Use a different manifest, just for the current instantiation. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 94 | """ |
| 95 | path = os.path.join(self.manifestProject.worktree, name) |
| 96 | if not os.path.isfile(path): |
| 97 | raise ManifestParseError('manifest %s not found' % name) |
| 98 | |
| 99 | old = self.manifestFile |
| 100 | try: |
| 101 | self.manifestFile = path |
| 102 | self._Unload() |
| 103 | self._Load() |
| 104 | finally: |
| 105 | self.manifestFile = old |
| 106 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 107 | def Link(self, name): |
| 108 | """Update the repo metadata to use a different manifest. |
| 109 | """ |
| 110 | self.Override(name) |
| 111 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 112 | try: |
| 113 | if os.path.exists(self.manifestFile): |
| 114 | os.remove(self.manifestFile) |
| 115 | os.symlink('manifests/%s' % name, self.manifestFile) |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 116 | except OSError: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 117 | raise ManifestParseError('cannot link manifest %s' % name) |
| 118 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 119 | def _RemoteToXml(self, r, doc, root): |
| 120 | e = doc.createElement('remote') |
| 121 | root.appendChild(e) |
| 122 | e.setAttribute('name', r.name) |
| 123 | e.setAttribute('fetch', r.fetchUrl) |
| 124 | if r.reviewUrl is not None: |
| 125 | e.setAttribute('review', r.reviewUrl) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 126 | |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 127 | def Save(self, fd, peg_rev=False, peg_rev_upstream=True): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 128 | """Write the current manifest out to the given file descriptor. |
| 129 | """ |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 130 | mp = self.manifestProject |
| 131 | |
| 132 | groups = mp.config.GetString('manifest.groups') |
Colin Cross | c39864f | 2012-04-23 13:41:58 -0700 | [diff] [blame] | 133 | if not groups: |
Conley Owens | bb1b5f5 | 2012-08-13 13:11:18 -0700 | [diff] [blame] | 134 | groups = 'all' |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 135 | groups = [x for x in re.split(r'[,\s]+', groups) if x] |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 136 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 137 | doc = xml.dom.minidom.Document() |
| 138 | root = doc.createElement('manifest') |
| 139 | doc.appendChild(root) |
| 140 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 141 | # Save out the notice. There's a little bit of work here to give it the |
| 142 | # right whitespace, which assumes that the notice is automatically indented |
| 143 | # by 4 by minidom. |
| 144 | if self.notice: |
| 145 | notice_element = root.appendChild(doc.createElement('notice')) |
| 146 | notice_lines = self.notice.splitlines() |
| 147 | indented_notice = ('\n'.join(" "*4 + line for line in notice_lines))[4:] |
| 148 | notice_element.appendChild(doc.createTextNode(indented_notice)) |
| 149 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 150 | d = self.default |
| 151 | sort_remotes = list(self.remotes.keys()) |
| 152 | sort_remotes.sort() |
| 153 | |
| 154 | for r in sort_remotes: |
| 155 | self._RemoteToXml(self.remotes[r], doc, root) |
| 156 | if self.remotes: |
| 157 | root.appendChild(doc.createTextNode('')) |
| 158 | |
| 159 | have_default = False |
| 160 | e = doc.createElement('default') |
| 161 | if d.remote: |
| 162 | have_default = True |
| 163 | e.setAttribute('remote', d.remote.name) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 164 | if d.revisionExpr: |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 165 | have_default = True |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 166 | e.setAttribute('revision', d.revisionExpr) |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 167 | if d.sync_j > 1: |
| 168 | have_default = True |
| 169 | e.setAttribute('sync-j', '%d' % d.sync_j) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 170 | if d.sync_c: |
| 171 | have_default = True |
| 172 | e.setAttribute('sync-c', 'true') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 173 | if have_default: |
| 174 | root.appendChild(e) |
| 175 | root.appendChild(doc.createTextNode('')) |
| 176 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 177 | if self._manifest_server: |
| 178 | e = doc.createElement('manifest-server') |
| 179 | e.setAttribute('url', self._manifest_server) |
| 180 | root.appendChild(e) |
| 181 | root.appendChild(doc.createTextNode('')) |
| 182 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 183 | sort_projects = list(self.projects.keys()) |
| 184 | sort_projects.sort() |
| 185 | |
| 186 | for p in sort_projects: |
| 187 | p = self.projects[p] |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 188 | |
| 189 | if not p.MatchesGroups(groups): |
| 190 | continue |
| 191 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 192 | e = doc.createElement('project') |
| 193 | root.appendChild(e) |
| 194 | e.setAttribute('name', p.name) |
| 195 | if p.relpath != p.name: |
| 196 | e.setAttribute('path', p.relpath) |
| 197 | if not d.remote or p.remote.name != d.remote.name: |
| 198 | e.setAttribute('remote', p.remote.name) |
| 199 | if peg_rev: |
| 200 | if self.IsMirror: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 201 | value = p.bare_git.rev_parse(p.revisionExpr + '^0') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 202 | else: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 203 | value = p.work_git.rev_parse(HEAD + '^0') |
| 204 | e.setAttribute('revision', value) |
| 205 | if peg_rev_upstream and value != p.revisionExpr: |
| 206 | # Only save the origin if the origin is not a sha1, and the default |
| 207 | # isn't our value, and the if the default doesn't already have that |
| 208 | # covered. |
| 209 | e.setAttribute('upstream', p.revisionExpr) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 210 | elif not d.revisionExpr or p.revisionExpr != d.revisionExpr: |
| 211 | e.setAttribute('revision', p.revisionExpr) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 212 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 213 | for c in p.copyfiles: |
| 214 | ce = doc.createElement('copyfile') |
| 215 | ce.setAttribute('src', c.src) |
| 216 | ce.setAttribute('dest', c.dest) |
| 217 | e.appendChild(ce) |
| 218 | |
Conley Owens | bb1b5f5 | 2012-08-13 13:11:18 -0700 | [diff] [blame] | 219 | default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath] |
Dmitry Fink | 17f85ea | 2012-08-06 14:52:29 -0700 | [diff] [blame] | 220 | egroups = [g for g in p.groups if g not in default_groups] |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 221 | if egroups: |
| 222 | e.setAttribute('groups', ','.join(egroups)) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 223 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 224 | for a in p.annotations: |
| 225 | if a.keep == "true": |
| 226 | ae = doc.createElement('annotation') |
| 227 | ae.setAttribute('name', a.name) |
| 228 | ae.setAttribute('value', a.value) |
| 229 | e.appendChild(ae) |
| 230 | |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 231 | if p.sync_c: |
| 232 | e.setAttribute('sync-c', 'true') |
| 233 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 234 | if self._repo_hooks_project: |
| 235 | root.appendChild(doc.createTextNode('')) |
| 236 | e = doc.createElement('repo-hooks') |
| 237 | e.setAttribute('in-project', self._repo_hooks_project.name) |
| 238 | e.setAttribute('enabled-list', |
| 239 | ' '.join(self._repo_hooks_project.enabled_repo_hooks)) |
| 240 | root.appendChild(e) |
| 241 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 242 | doc.writexml(fd, '', ' ', '\n', 'UTF-8') |
| 243 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 244 | @property |
| 245 | def projects(self): |
| 246 | self._Load() |
| 247 | return self._projects |
| 248 | |
| 249 | @property |
| 250 | def remotes(self): |
| 251 | self._Load() |
| 252 | return self._remotes |
| 253 | |
| 254 | @property |
| 255 | def default(self): |
| 256 | self._Load() |
| 257 | return self._default |
| 258 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 259 | @property |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 260 | def repo_hooks_project(self): |
| 261 | self._Load() |
| 262 | return self._repo_hooks_project |
| 263 | |
| 264 | @property |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 265 | def notice(self): |
| 266 | self._Load() |
| 267 | return self._notice |
| 268 | |
| 269 | @property |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 270 | def manifest_server(self): |
| 271 | self._Load() |
Shawn O. Pearce | 34fb20f | 2011-11-30 13:41:02 -0800 | [diff] [blame] | 272 | return self._manifest_server |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 273 | |
| 274 | @property |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 275 | def IsMirror(self): |
| 276 | return self.manifestProject.config.GetBoolean('repo.mirror') |
| 277 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 278 | def _Unload(self): |
| 279 | self._loaded = False |
| 280 | self._projects = {} |
| 281 | self._remotes = {} |
| 282 | self._default = None |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 283 | self._repo_hooks_project = None |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 284 | self._notice = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 285 | self.branch = None |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 286 | self._manifest_server = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 287 | |
| 288 | def _Load(self): |
| 289 | if not self._loaded: |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 290 | m = self.manifestProject |
| 291 | b = m.GetBranch(m.CurrentBranch).merge |
Shawn O. Pearce | 21c5c34 | 2009-06-25 16:47:30 -0700 | [diff] [blame] | 292 | if b is not None and b.startswith(R_HEADS): |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 293 | b = b[len(R_HEADS):] |
| 294 | self.branch = b |
| 295 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 296 | nodes = [] |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 297 | nodes.append(self._ParseManifestXml(self.manifestFile, |
| 298 | self.manifestProject.worktree)) |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 299 | |
| 300 | local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) |
| 301 | if os.path.exists(local): |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 302 | nodes.append(self._ParseManifestXml(local, self.repodir)) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 303 | |
| 304 | self._ParseManifest(nodes) |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 305 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 306 | if self.IsMirror: |
| 307 | self._AddMetaProjectMirror(self.repoProject) |
| 308 | self._AddMetaProjectMirror(self.manifestProject) |
| 309 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 310 | self._loaded = True |
| 311 | |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 312 | def _ParseManifestXml(self, path, include_root): |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 313 | root = xml.dom.minidom.parse(path) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 314 | if not root or not root.childNodes: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 315 | raise ManifestParseError("no root node in %s" % (path,)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 316 | |
Jooncheol Park | 34acdd2 | 2012-08-27 02:25:59 +0900 | [diff] [blame] | 317 | for manifest in root.childNodes: |
| 318 | if manifest.nodeName == 'manifest': |
| 319 | break |
| 320 | else: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 321 | raise ManifestParseError("no <manifest> in %s" % (path,)) |
| 322 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 323 | nodes = [] |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 324 | for node in manifest.childNodes: # pylint:disable-msg=W0631 |
| 325 | # We only get here if manifest is initialised |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 326 | if node.nodeName == 'include': |
| 327 | name = self._reqatt(node, 'name') |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 328 | fp = os.path.join(include_root, name) |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 329 | if not os.path.isfile(fp): |
| 330 | raise ManifestParseError, \ |
| 331 | "include %s doesn't exist or isn't a file" % \ |
| 332 | (name,) |
| 333 | try: |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 334 | nodes.extend(self._ParseManifestXml(fp, include_root)) |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 335 | # should isolate this to the exact exception, but that's |
| 336 | # tricky. actual parsing implementation may vary. |
| 337 | except (KeyboardInterrupt, RuntimeError, SystemExit): |
| 338 | raise |
| 339 | except Exception, e: |
| 340 | raise ManifestParseError( |
| 341 | "failed parsing included manifest %s: %s", (name, e)) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 342 | else: |
| 343 | nodes.append(node) |
| 344 | return nodes |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 345 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 346 | def _ParseManifest(self, node_list): |
| 347 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 348 | if node.nodeName == 'remote': |
| 349 | remote = self._ParseRemote(node) |
| 350 | if self._remotes.get(remote.name): |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 351 | raise ManifestParseError( |
| 352 | 'duplicate remote %s in %s' % |
| 353 | (remote.name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 354 | self._remotes[remote.name] = remote |
| 355 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 356 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 357 | if node.nodeName == 'default': |
| 358 | if self._default is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 359 | raise ManifestParseError( |
| 360 | 'duplicate default in %s' % |
| 361 | (self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 362 | self._default = self._ParseDefault(node) |
| 363 | if self._default is None: |
| 364 | self._default = _Default() |
| 365 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 366 | for node in itertools.chain(*node_list): |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 367 | if node.nodeName == 'notice': |
| 368 | if self._notice is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 369 | raise ManifestParseError( |
| 370 | 'duplicate notice in %s' % |
| 371 | (self.manifestFile)) |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 372 | self._notice = self._ParseNotice(node) |
| 373 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 374 | for node in itertools.chain(*node_list): |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 375 | if node.nodeName == 'manifest-server': |
| 376 | url = self._reqatt(node, 'url') |
| 377 | if self._manifest_server is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 378 | raise ManifestParseError( |
| 379 | 'duplicate manifest-server in %s' % |
| 380 | (self.manifestFile)) |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 381 | self._manifest_server = url |
| 382 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 383 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 384 | if node.nodeName == 'project': |
| 385 | project = self._ParseProject(node) |
| 386 | if self._projects.get(project.name): |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 387 | raise ManifestParseError( |
| 388 | 'duplicate project %s in %s' % |
| 389 | (project.name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 390 | self._projects[project.name] = project |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 391 | if node.nodeName == 'repo-hooks': |
| 392 | # Get the name of the project and the (space-separated) list of enabled. |
| 393 | repo_hooks_project = self._reqatt(node, 'in-project') |
| 394 | enabled_repo_hooks = self._reqatt(node, 'enabled-list').split() |
| 395 | |
| 396 | # Only one project can be the hooks project |
| 397 | if self._repo_hooks_project is not None: |
| 398 | raise ManifestParseError( |
| 399 | 'duplicate repo-hooks in %s' % |
| 400 | (self.manifestFile)) |
| 401 | |
| 402 | # Store a reference to the Project. |
| 403 | try: |
| 404 | self._repo_hooks_project = self._projects[repo_hooks_project] |
| 405 | except KeyError: |
| 406 | raise ManifestParseError( |
| 407 | 'project %s not found for repo-hooks' % |
| 408 | (repo_hooks_project)) |
| 409 | |
| 410 | # Store the enabled hooks in the Project object. |
| 411 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 412 | if node.nodeName == 'remove-project': |
| 413 | name = self._reqatt(node, 'name') |
| 414 | try: |
| 415 | del self._projects[name] |
| 416 | except KeyError: |
| 417 | raise ManifestParseError( |
| 418 | 'project %s not found' % |
| 419 | (name)) |
| 420 | |
| 421 | # If the manifest removes the hooks project, treat it as if it deleted |
| 422 | # the repo-hooks element too. |
| 423 | if self._repo_hooks_project and (self._repo_hooks_project.name == name): |
| 424 | self._repo_hooks_project = None |
| 425 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 426 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 427 | def _AddMetaProjectMirror(self, m): |
| 428 | name = None |
| 429 | m_url = m.GetRemote(m.remote.name).url |
| 430 | if m_url.endswith('/.git'): |
| 431 | raise ManifestParseError, 'refusing to mirror %s' % m_url |
| 432 | |
| 433 | if self._default and self._default.remote: |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 434 | url = self._default.remote.resolvedFetchUrl |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 435 | if not url.endswith('/'): |
| 436 | url += '/' |
| 437 | if m_url.startswith(url): |
| 438 | remote = self._default.remote |
| 439 | name = m_url[len(url):] |
| 440 | |
| 441 | if name is None: |
| 442 | s = m_url.rindex('/') + 1 |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 443 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Shawn O. Pearce | f35b2d9 | 2012-08-02 11:46:22 -0700 | [diff] [blame] | 444 | remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 445 | name = m_url[s:] |
| 446 | |
| 447 | if name.endswith('.git'): |
| 448 | name = name[:-4] |
| 449 | |
| 450 | if name not in self._projects: |
| 451 | m.PreSync() |
| 452 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 453 | project = Project(manifest = self, |
| 454 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 455 | remote = remote.ToRemoteSpec(name), |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 456 | gitdir = gitdir, |
| 457 | worktree = None, |
| 458 | relpath = None, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 459 | revisionExpr = m.revisionExpr, |
| 460 | revisionId = None) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 461 | self._projects[project.name] = project |
| 462 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 463 | def _ParseRemote(self, node): |
| 464 | """ |
| 465 | reads a <remote> element from the manifest file |
| 466 | """ |
| 467 | name = self._reqatt(node, 'name') |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 468 | alias = node.getAttribute('alias') |
| 469 | if alias == '': |
| 470 | alias = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 471 | fetch = self._reqatt(node, 'fetch') |
| 472 | review = node.getAttribute('review') |
Shawn O. Pearce | ae6e094 | 2008-11-06 10:25:35 -0800 | [diff] [blame] | 473 | if review == '': |
| 474 | review = None |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 475 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 476 | return _XmlRemote(name, alias, fetch, manifestUrl, review) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 477 | |
| 478 | def _ParseDefault(self, node): |
| 479 | """ |
| 480 | reads a <default> element from the manifest file |
| 481 | """ |
| 482 | d = _Default() |
| 483 | d.remote = self._get_remote(node) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 484 | d.revisionExpr = node.getAttribute('revision') |
| 485 | if d.revisionExpr == '': |
| 486 | d.revisionExpr = None |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 487 | |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 488 | sync_j = node.getAttribute('sync-j') |
| 489 | if sync_j == '' or sync_j is None: |
| 490 | d.sync_j = 1 |
| 491 | else: |
| 492 | d.sync_j = int(sync_j) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 493 | |
| 494 | sync_c = node.getAttribute('sync-c') |
| 495 | if not sync_c: |
| 496 | d.sync_c = False |
| 497 | else: |
| 498 | d.sync_c = sync_c.lower() in ("yes", "true", "1") |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 499 | return d |
| 500 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 501 | def _ParseNotice(self, node): |
| 502 | """ |
| 503 | reads a <notice> element from the manifest file |
| 504 | |
| 505 | The <notice> element is distinct from other tags in the XML in that the |
| 506 | data is conveyed between the start and end tag (it's not an empty-element |
| 507 | tag). |
| 508 | |
| 509 | The white space (carriage returns, indentation) for the notice element is |
| 510 | relevant and is parsed in a way that is based on how python docstrings work. |
| 511 | In fact, the code is remarkably similar to here: |
| 512 | http://www.python.org/dev/peps/pep-0257/ |
| 513 | """ |
| 514 | # Get the data out of the node... |
| 515 | notice = node.childNodes[0].data |
| 516 | |
| 517 | # Figure out minimum indentation, skipping the first line (the same line |
| 518 | # as the <notice> tag)... |
| 519 | minIndent = sys.maxint |
| 520 | lines = notice.splitlines() |
| 521 | for line in lines[1:]: |
| 522 | lstrippedLine = line.lstrip() |
| 523 | if lstrippedLine: |
| 524 | indent = len(line) - len(lstrippedLine) |
| 525 | minIndent = min(indent, minIndent) |
| 526 | |
| 527 | # Strip leading / trailing blank lines and also indentation. |
| 528 | cleanLines = [lines[0].strip()] |
| 529 | for line in lines[1:]: |
| 530 | cleanLines.append(line[minIndent:].rstrip()) |
| 531 | |
| 532 | # Clear completely blank lines from front and back... |
| 533 | while cleanLines and not cleanLines[0]: |
| 534 | del cleanLines[0] |
| 535 | while cleanLines and not cleanLines[-1]: |
| 536 | del cleanLines[-1] |
| 537 | |
| 538 | return '\n'.join(cleanLines) |
| 539 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 540 | def _ParseProject(self, node): |
| 541 | """ |
| 542 | reads a <project> element from the manifest file |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 543 | """ |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 544 | name = self._reqatt(node, 'name') |
| 545 | |
| 546 | remote = self._get_remote(node) |
| 547 | if remote is None: |
| 548 | remote = self._default.remote |
| 549 | if remote is None: |
| 550 | raise ManifestParseError, \ |
| 551 | "no remote for project %s within %s" % \ |
| 552 | (name, self.manifestFile) |
| 553 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 554 | revisionExpr = node.getAttribute('revision') |
| 555 | if not revisionExpr: |
| 556 | revisionExpr = self._default.revisionExpr |
| 557 | if not revisionExpr: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 558 | raise ManifestParseError, \ |
| 559 | "no revision for project %s within %s" % \ |
| 560 | (name, self.manifestFile) |
| 561 | |
| 562 | path = node.getAttribute('path') |
| 563 | if not path: |
| 564 | path = name |
| 565 | if path.startswith('/'): |
| 566 | raise ManifestParseError, \ |
| 567 | "project %s path cannot be absolute in %s" % \ |
| 568 | (name, self.manifestFile) |
| 569 | |
Mike Pontillo | d315382 | 2012-02-28 11:53:24 -0800 | [diff] [blame] | 570 | rebase = node.getAttribute('rebase') |
| 571 | if not rebase: |
| 572 | rebase = True |
| 573 | else: |
| 574 | rebase = rebase.lower() in ("yes", "true", "1") |
| 575 | |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 576 | sync_c = node.getAttribute('sync-c') |
| 577 | if not sync_c: |
| 578 | sync_c = False |
| 579 | else: |
| 580 | sync_c = sync_c.lower() in ("yes", "true", "1") |
| 581 | |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 582 | upstream = node.getAttribute('upstream') |
| 583 | |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 584 | groups = '' |
| 585 | if node.hasAttribute('groups'): |
| 586 | groups = node.getAttribute('groups') |
| 587 | groups = [x for x in re.split('[,\s]+', groups) if x] |
Brian Harring | 7da1314 | 2012-06-15 02:24:20 -0700 | [diff] [blame] | 588 | |
David Holmer | 9779565 | 2012-09-26 01:58:48 -0400 | [diff] [blame] | 589 | default_groups = ['all', 'name:%s' % name, 'path:%s' % path] |
Brian Harring | 7da1314 | 2012-06-15 02:24:20 -0700 | [diff] [blame] | 590 | groups.extend(set(default_groups).difference(groups)) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 591 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 592 | if self.IsMirror: |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 593 | worktree = None |
| 594 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 595 | else: |
Anthony Newnam | df14a70 | 2011-01-09 17:31:57 -0800 | [diff] [blame] | 596 | worktree = os.path.join(self.topdir, path).replace('\\', '/') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 597 | gitdir = os.path.join(self.repodir, 'projects/%s.git' % path) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 598 | |
| 599 | project = Project(manifest = self, |
| 600 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 601 | remote = remote.ToRemoteSpec(name), |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 602 | gitdir = gitdir, |
| 603 | worktree = worktree, |
| 604 | relpath = path, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 605 | revisionExpr = revisionExpr, |
Mike Pontillo | d315382 | 2012-02-28 11:53:24 -0800 | [diff] [blame] | 606 | revisionId = None, |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 607 | rebase = rebase, |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 608 | groups = groups, |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 609 | sync_c = sync_c, |
| 610 | upstream = upstream) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 611 | |
| 612 | for n in node.childNodes: |
Shawn O. Pearce | 242b526 | 2009-05-19 13:00:29 -0700 | [diff] [blame] | 613 | if n.nodeName == 'copyfile': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 614 | self._ParseCopyFile(project, n) |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 615 | if n.nodeName == 'annotation': |
| 616 | self._ParseAnnotation(project, n) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 617 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 618 | return project |
| 619 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 620 | def _ParseCopyFile(self, project, node): |
| 621 | src = self._reqatt(node, 'src') |
| 622 | dest = self._reqatt(node, 'dest') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 623 | if not self.IsMirror: |
| 624 | # src is project relative; |
| 625 | # dest is relative to the top of the tree |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 626 | project.AddCopyFile(src, dest, os.path.join(self.topdir, dest)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 627 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 628 | def _ParseAnnotation(self, project, node): |
| 629 | name = self._reqatt(node, 'name') |
| 630 | value = self._reqatt(node, 'value') |
| 631 | try: |
| 632 | keep = self._reqatt(node, 'keep').lower() |
| 633 | except ManifestParseError: |
| 634 | keep = "true" |
| 635 | if keep != "true" and keep != "false": |
| 636 | raise ManifestParseError, "optional \"keep\" attribute must be \"true\" or \"false\"" |
| 637 | project.AddAnnotation(name, value, keep) |
| 638 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 639 | def _get_remote(self, node): |
| 640 | name = node.getAttribute('remote') |
| 641 | if not name: |
| 642 | return None |
| 643 | |
| 644 | v = self._remotes.get(name) |
| 645 | if not v: |
| 646 | raise ManifestParseError, \ |
| 647 | "remote %s not defined in %s" % \ |
| 648 | (name, self.manifestFile) |
| 649 | return v |
| 650 | |
| 651 | def _reqatt(self, node, attname): |
| 652 | """ |
| 653 | reads a required attribute from the node. |
| 654 | """ |
| 655 | v = node.getAttribute(attname) |
| 656 | if not v: |
| 657 | raise ManifestParseError, \ |
| 658 | "no %s in <%s> within %s" % \ |
| 659 | (attname, node.nodeName, self.manifestFile) |
| 660 | return v |