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 | |
| 16 | import os |
| 17 | import sys |
| 18 | import xml.dom.minidom |
| 19 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | from git_config import GitConfig, IsId |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 21 | from manifest import Manifest |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 22 | from project import RemoteSpec, Project, MetaProject, R_HEADS, HEAD |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 23 | from error import ManifestParseError |
| 24 | |
| 25 | MANIFEST_FILE_NAME = 'manifest.xml' |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 26 | LOCAL_MANIFEST_NAME = 'local_manifest.xml' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 27 | |
| 28 | class _Default(object): |
| 29 | """Project defaults within the manifest.""" |
| 30 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 31 | revisionExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 32 | remote = None |
| 33 | |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 34 | class _XmlRemote(object): |
| 35 | def __init__(self, |
| 36 | name, |
| 37 | fetch=None, |
| 38 | review=None): |
| 39 | self.name = name |
| 40 | self.fetchUrl = fetch |
| 41 | self.reviewUrl = review |
| 42 | |
| 43 | def ToRemoteSpec(self, projectName): |
| 44 | url = self.fetchUrl |
| 45 | while url.endswith('/'): |
| 46 | url = url[:-1] |
| 47 | url += '/%s.git' % projectName |
| 48 | return RemoteSpec(self.name, url, self.reviewUrl) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 50 | class XmlManifest(Manifest): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 51 | """manages the repo configuration file""" |
| 52 | |
| 53 | def __init__(self, repodir): |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 54 | Manifest.__init__(self, repodir) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 55 | |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 56 | self._manifestFile = os.path.join(repodir, MANIFEST_FILE_NAME) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 57 | self.manifestProject = MetaProject(self, 'manifests', |
Shawn O. Pearce | f5c25a6 | 2008-11-04 08:11:53 -0800 | [diff] [blame] | 58 | gitdir = os.path.join(repodir, 'manifests.git'), |
| 59 | worktree = os.path.join(repodir, 'manifests')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 60 | |
| 61 | self._Unload() |
| 62 | |
| 63 | def Link(self, name): |
| 64 | """Update the repo metadata to use a different manifest. |
| 65 | """ |
| 66 | path = os.path.join(self.manifestProject.worktree, name) |
| 67 | if not os.path.isfile(path): |
| 68 | raise ManifestParseError('manifest %s not found' % name) |
| 69 | |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 70 | old = self._manifestFile |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 71 | try: |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 72 | self._manifestFile = path |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 73 | self._Unload() |
| 74 | self._Load() |
| 75 | finally: |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 76 | self._manifestFile = old |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | |
| 78 | try: |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 79 | if os.path.exists(self._manifestFile): |
| 80 | os.remove(self._manifestFile) |
| 81 | os.symlink('manifests/%s' % name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 82 | except OSError, e: |
| 83 | raise ManifestParseError('cannot link manifest %s' % name) |
| 84 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 85 | def _RemoteToXml(self, r, doc, root): |
| 86 | e = doc.createElement('remote') |
| 87 | root.appendChild(e) |
| 88 | e.setAttribute('name', r.name) |
| 89 | e.setAttribute('fetch', r.fetchUrl) |
| 90 | if r.reviewUrl is not None: |
| 91 | e.setAttribute('review', r.reviewUrl) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 92 | |
| 93 | def Save(self, fd, peg_rev=False): |
| 94 | """Write the current manifest out to the given file descriptor. |
| 95 | """ |
| 96 | doc = xml.dom.minidom.Document() |
| 97 | root = doc.createElement('manifest') |
| 98 | doc.appendChild(root) |
| 99 | |
| 100 | d = self.default |
| 101 | sort_remotes = list(self.remotes.keys()) |
| 102 | sort_remotes.sort() |
| 103 | |
| 104 | for r in sort_remotes: |
| 105 | self._RemoteToXml(self.remotes[r], doc, root) |
| 106 | if self.remotes: |
| 107 | root.appendChild(doc.createTextNode('')) |
| 108 | |
| 109 | have_default = False |
| 110 | e = doc.createElement('default') |
| 111 | if d.remote: |
| 112 | have_default = True |
| 113 | e.setAttribute('remote', d.remote.name) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 114 | if d.revisionExpr: |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 115 | have_default = True |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 116 | e.setAttribute('revision', d.revisionExpr) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 117 | if have_default: |
| 118 | root.appendChild(e) |
| 119 | root.appendChild(doc.createTextNode('')) |
| 120 | |
| 121 | sort_projects = list(self.projects.keys()) |
| 122 | sort_projects.sort() |
| 123 | |
| 124 | for p in sort_projects: |
| 125 | p = self.projects[p] |
| 126 | e = doc.createElement('project') |
| 127 | root.appendChild(e) |
| 128 | e.setAttribute('name', p.name) |
| 129 | if p.relpath != p.name: |
| 130 | e.setAttribute('path', p.relpath) |
| 131 | if not d.remote or p.remote.name != d.remote.name: |
| 132 | e.setAttribute('remote', p.remote.name) |
| 133 | if peg_rev: |
| 134 | if self.IsMirror: |
| 135 | e.setAttribute('revision', |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 136 | p.bare_git.rev_parse(p.revisionExpr + '^0')) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 137 | else: |
| 138 | e.setAttribute('revision', |
| 139 | p.work_git.rev_parse(HEAD + '^0')) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 140 | elif not d.revisionExpr or p.revisionExpr != d.revisionExpr: |
| 141 | e.setAttribute('revision', p.revisionExpr) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 142 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 143 | for c in p.copyfiles: |
| 144 | ce = doc.createElement('copyfile') |
| 145 | ce.setAttribute('src', c.src) |
| 146 | ce.setAttribute('dest', c.dest) |
| 147 | e.appendChild(ce) |
| 148 | |
| 149 | doc.writexml(fd, '', ' ', '\n', 'UTF-8') |
| 150 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 151 | @property |
| 152 | def projects(self): |
| 153 | self._Load() |
| 154 | return self._projects |
| 155 | |
| 156 | @property |
| 157 | def remotes(self): |
| 158 | self._Load() |
| 159 | return self._remotes |
| 160 | |
| 161 | @property |
| 162 | def default(self): |
| 163 | self._Load() |
| 164 | return self._default |
| 165 | |
| 166 | def _Unload(self): |
| 167 | self._loaded = False |
| 168 | self._projects = {} |
| 169 | self._remotes = {} |
| 170 | self._default = None |
| 171 | self.branch = None |
| 172 | |
| 173 | def _Load(self): |
| 174 | if not self._loaded: |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 175 | m = self.manifestProject |
| 176 | b = m.GetBranch(m.CurrentBranch).merge |
Shawn O. Pearce | 21c5c34 | 2009-06-25 16:47:30 -0700 | [diff] [blame] | 177 | if b is not None and b.startswith(R_HEADS): |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 178 | b = b[len(R_HEADS):] |
| 179 | self.branch = b |
| 180 | |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 181 | self._ParseManifest(True) |
| 182 | |
| 183 | local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) |
| 184 | if os.path.exists(local): |
| 185 | try: |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 186 | real = self._manifestFile |
| 187 | self._manifestFile = local |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 188 | self._ParseManifest(False) |
| 189 | finally: |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 190 | self._manifestFile = real |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 191 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 192 | if self.IsMirror: |
| 193 | self._AddMetaProjectMirror(self.repoProject) |
| 194 | self._AddMetaProjectMirror(self.manifestProject) |
| 195 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 196 | self._loaded = True |
| 197 | |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 198 | def _ParseManifest(self, is_root_file): |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 199 | root = xml.dom.minidom.parse(self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 200 | if not root or not root.childNodes: |
| 201 | raise ManifestParseError, \ |
| 202 | "no root node in %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 203 | self._manifestFile |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 204 | |
| 205 | config = root.childNodes[0] |
| 206 | if config.nodeName != 'manifest': |
| 207 | raise ManifestParseError, \ |
| 208 | "no <manifest> in %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 209 | self._manifestFile |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 210 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 211 | for node in config.childNodes: |
Shawn O. Pearce | 03eaf07 | 2008-11-20 11:42:22 -0800 | [diff] [blame] | 212 | if node.nodeName == 'remove-project': |
| 213 | name = self._reqatt(node, 'name') |
| 214 | try: |
| 215 | del self._projects[name] |
| 216 | except KeyError: |
| 217 | raise ManifestParseError, \ |
| 218 | 'project %s not found' % \ |
| 219 | (name) |
| 220 | |
| 221 | for node in config.childNodes: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 222 | if node.nodeName == 'remote': |
| 223 | remote = self._ParseRemote(node) |
| 224 | if self._remotes.get(remote.name): |
| 225 | raise ManifestParseError, \ |
| 226 | 'duplicate remote %s in %s' % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 227 | (remote.name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 228 | self._remotes[remote.name] = remote |
| 229 | |
| 230 | for node in config.childNodes: |
| 231 | if node.nodeName == 'default': |
| 232 | if self._default is not None: |
| 233 | raise ManifestParseError, \ |
| 234 | 'duplicate default in %s' % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 235 | (self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 236 | self._default = self._ParseDefault(node) |
| 237 | if self._default is None: |
| 238 | self._default = _Default() |
| 239 | |
| 240 | for node in config.childNodes: |
| 241 | if node.nodeName == 'project': |
| 242 | project = self._ParseProject(node) |
| 243 | if self._projects.get(project.name): |
| 244 | raise ManifestParseError, \ |
| 245 | 'duplicate project %s in %s' % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 246 | (project.name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 247 | self._projects[project.name] = project |
| 248 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 249 | def _AddMetaProjectMirror(self, m): |
| 250 | name = None |
| 251 | m_url = m.GetRemote(m.remote.name).url |
| 252 | if m_url.endswith('/.git'): |
| 253 | raise ManifestParseError, 'refusing to mirror %s' % m_url |
| 254 | |
| 255 | if self._default and self._default.remote: |
| 256 | url = self._default.remote.fetchUrl |
| 257 | if not url.endswith('/'): |
| 258 | url += '/' |
| 259 | if m_url.startswith(url): |
| 260 | remote = self._default.remote |
| 261 | name = m_url[len(url):] |
| 262 | |
| 263 | if name is None: |
| 264 | s = m_url.rindex('/') + 1 |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 265 | remote = _XmlRemote('origin', m_url[:s]) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 266 | name = m_url[s:] |
| 267 | |
| 268 | if name.endswith('.git'): |
| 269 | name = name[:-4] |
| 270 | |
| 271 | if name not in self._projects: |
| 272 | m.PreSync() |
| 273 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 274 | project = Project(manifest = self, |
| 275 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 276 | remote = remote.ToRemoteSpec(name), |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 277 | gitdir = gitdir, |
| 278 | worktree = None, |
| 279 | relpath = None, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 280 | revisionExpr = m.revisionExpr, |
| 281 | revisionId = None) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 282 | self._projects[project.name] = project |
| 283 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 284 | def _ParseRemote(self, node): |
| 285 | """ |
| 286 | reads a <remote> element from the manifest file |
| 287 | """ |
| 288 | name = self._reqatt(node, 'name') |
| 289 | fetch = self._reqatt(node, 'fetch') |
| 290 | review = node.getAttribute('review') |
Shawn O. Pearce | ae6e094 | 2008-11-06 10:25:35 -0800 | [diff] [blame] | 291 | if review == '': |
| 292 | review = None |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 293 | return _XmlRemote(name, fetch, review) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 294 | |
| 295 | def _ParseDefault(self, node): |
| 296 | """ |
| 297 | reads a <default> element from the manifest file |
| 298 | """ |
| 299 | d = _Default() |
| 300 | d.remote = self._get_remote(node) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 301 | d.revisionExpr = node.getAttribute('revision') |
| 302 | if d.revisionExpr == '': |
| 303 | d.revisionExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 304 | return d |
| 305 | |
| 306 | def _ParseProject(self, node): |
| 307 | """ |
| 308 | reads a <project> element from the manifest file |
| 309 | """ |
| 310 | name = self._reqatt(node, 'name') |
| 311 | |
| 312 | remote = self._get_remote(node) |
| 313 | if remote is None: |
| 314 | remote = self._default.remote |
| 315 | if remote is None: |
| 316 | raise ManifestParseError, \ |
| 317 | "no remote for project %s within %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 318 | (name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 319 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 320 | revisionExpr = node.getAttribute('revision') |
| 321 | if not revisionExpr: |
| 322 | revisionExpr = self._default.revisionExpr |
| 323 | if not revisionExpr: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 324 | raise ManifestParseError, \ |
| 325 | "no revision for project %s within %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 326 | (name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 327 | |
| 328 | path = node.getAttribute('path') |
| 329 | if not path: |
| 330 | path = name |
| 331 | if path.startswith('/'): |
| 332 | raise ManifestParseError, \ |
| 333 | "project %s path cannot be absolute in %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 334 | (name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 335 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 336 | if self.IsMirror: |
| 337 | relpath = None |
| 338 | worktree = None |
| 339 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 340 | else: |
| 341 | worktree = os.path.join(self.topdir, path) |
| 342 | 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] | 343 | |
| 344 | project = Project(manifest = self, |
| 345 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 346 | remote = remote.ToRemoteSpec(name), |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 347 | gitdir = gitdir, |
| 348 | worktree = worktree, |
| 349 | relpath = path, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 350 | revisionExpr = revisionExpr, |
| 351 | revisionId = None) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 352 | |
| 353 | for n in node.childNodes: |
Shawn O. Pearce | 242b526 | 2009-05-19 13:00:29 -0700 | [diff] [blame] | 354 | if n.nodeName == 'copyfile': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 355 | self._ParseCopyFile(project, n) |
| 356 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 357 | return project |
| 358 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 359 | def _ParseCopyFile(self, project, node): |
| 360 | src = self._reqatt(node, 'src') |
| 361 | dest = self._reqatt(node, 'dest') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 362 | if not self.IsMirror: |
| 363 | # src is project relative; |
| 364 | # dest is relative to the top of the tree |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 365 | 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] | 366 | |
| 367 | def _get_remote(self, node): |
| 368 | name = node.getAttribute('remote') |
| 369 | if not name: |
| 370 | return None |
| 371 | |
| 372 | v = self._remotes.get(name) |
| 373 | if not v: |
| 374 | raise ManifestParseError, \ |
| 375 | "remote %s not defined in %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 376 | (name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 377 | return v |
| 378 | |
| 379 | def _reqatt(self, node, attname): |
| 380 | """ |
| 381 | reads a required attribute from the node. |
| 382 | """ |
| 383 | v = node.getAttribute(attname) |
| 384 | if not v: |
| 385 | raise ManifestParseError, \ |
| 386 | "no %s in <%s> within %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 387 | (attname, node.nodeName, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 388 | return v |