manifest_xml.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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. from __future__ import print_function
  16. import itertools
  17. import os
  18. import re
  19. import sys
  20. import urlparse
  21. import xml.dom.minidom
  22. from git_config import GitConfig
  23. from git_refs import R_HEADS, HEAD
  24. from project import RemoteSpec, Project, MetaProject
  25. from error import ManifestParseError
  26. MANIFEST_FILE_NAME = 'manifest.xml'
  27. LOCAL_MANIFEST_NAME = 'local_manifest.xml'
  28. LOCAL_MANIFESTS_DIR_NAME = 'local_manifests'
  29. urlparse.uses_relative.extend(['ssh', 'git'])
  30. urlparse.uses_netloc.extend(['ssh', 'git'])
  31. class _Default(object):
  32. """Project defaults within the manifest."""
  33. revisionExpr = None
  34. remote = None
  35. sync_j = 1
  36. sync_c = False
  37. class _XmlRemote(object):
  38. def __init__(self,
  39. name,
  40. alias=None,
  41. fetch=None,
  42. manifestUrl=None,
  43. review=None):
  44. self.name = name
  45. self.fetchUrl = fetch
  46. self.manifestUrl = manifestUrl
  47. self.remoteAlias = alias
  48. self.reviewUrl = review
  49. self.resolvedFetchUrl = self._resolveFetchUrl()
  50. def __eq__(self, other):
  51. return self.__dict__ == other.__dict__
  52. def __ne__(self, other):
  53. return self.__dict__ != other.__dict__
  54. def _resolveFetchUrl(self):
  55. url = self.fetchUrl.rstrip('/')
  56. manifestUrl = self.manifestUrl.rstrip('/')
  57. # urljoin will get confused if there is no scheme in the base url
  58. # ie, if manifestUrl is of the form <hostname:port>
  59. if manifestUrl.find(':') != manifestUrl.find('/') - 1:
  60. manifestUrl = 'gopher://' + manifestUrl
  61. url = urlparse.urljoin(manifestUrl, url)
  62. return re.sub(r'^gopher://', '', url)
  63. def ToRemoteSpec(self, projectName):
  64. url = self.resolvedFetchUrl.rstrip('/') + '/' + projectName
  65. remoteName = self.name
  66. if self.remoteAlias:
  67. remoteName = self.remoteAlias
  68. return RemoteSpec(remoteName, url, self.reviewUrl)
  69. class XmlManifest(object):
  70. """manages the repo configuration file"""
  71. def __init__(self, repodir):
  72. self.repodir = os.path.abspath(repodir)
  73. self.topdir = os.path.dirname(self.repodir)
  74. self.manifestFile = os.path.join(self.repodir, MANIFEST_FILE_NAME)
  75. self.globalConfig = GitConfig.ForUser()
  76. self.repoProject = MetaProject(self, 'repo',
  77. gitdir = os.path.join(repodir, 'repo/.git'),
  78. worktree = os.path.join(repodir, 'repo'))
  79. self.manifestProject = MetaProject(self, 'manifests',
  80. gitdir = os.path.join(repodir, 'manifests.git'),
  81. worktree = os.path.join(repodir, 'manifests'))
  82. self._Unload()
  83. def Override(self, name):
  84. """Use a different manifest, just for the current instantiation.
  85. """
  86. path = os.path.join(self.manifestProject.worktree, name)
  87. if not os.path.isfile(path):
  88. raise ManifestParseError('manifest %s not found' % name)
  89. old = self.manifestFile
  90. try:
  91. self.manifestFile = path
  92. self._Unload()
  93. self._Load()
  94. finally:
  95. self.manifestFile = old
  96. def Link(self, name):
  97. """Update the repo metadata to use a different manifest.
  98. """
  99. self.Override(name)
  100. try:
  101. if os.path.exists(self.manifestFile):
  102. os.remove(self.manifestFile)
  103. os.symlink('manifests/%s' % name, self.manifestFile)
  104. except OSError:
  105. raise ManifestParseError('cannot link manifest %s' % name)
  106. def _RemoteToXml(self, r, doc, root):
  107. e = doc.createElement('remote')
  108. root.appendChild(e)
  109. e.setAttribute('name', r.name)
  110. e.setAttribute('fetch', r.fetchUrl)
  111. if r.reviewUrl is not None:
  112. e.setAttribute('review', r.reviewUrl)
  113. def Save(self, fd, peg_rev=False, peg_rev_upstream=True):
  114. """Write the current manifest out to the given file descriptor.
  115. """
  116. mp = self.manifestProject
  117. groups = mp.config.GetString('manifest.groups')
  118. if not groups:
  119. groups = 'all'
  120. groups = [x for x in re.split(r'[,\s]+', groups) if x]
  121. doc = xml.dom.minidom.Document()
  122. root = doc.createElement('manifest')
  123. doc.appendChild(root)
  124. # Save out the notice. There's a little bit of work here to give it the
  125. # right whitespace, which assumes that the notice is automatically indented
  126. # by 4 by minidom.
  127. if self.notice:
  128. notice_element = root.appendChild(doc.createElement('notice'))
  129. notice_lines = self.notice.splitlines()
  130. indented_notice = ('\n'.join(" "*4 + line for line in notice_lines))[4:]
  131. notice_element.appendChild(doc.createTextNode(indented_notice))
  132. d = self.default
  133. sort_remotes = list(self.remotes.keys())
  134. sort_remotes.sort()
  135. for r in sort_remotes:
  136. self._RemoteToXml(self.remotes[r], doc, root)
  137. if self.remotes:
  138. root.appendChild(doc.createTextNode(''))
  139. have_default = False
  140. e = doc.createElement('default')
  141. if d.remote:
  142. have_default = True
  143. e.setAttribute('remote', d.remote.name)
  144. if d.revisionExpr:
  145. have_default = True
  146. e.setAttribute('revision', d.revisionExpr)
  147. if d.sync_j > 1:
  148. have_default = True
  149. e.setAttribute('sync-j', '%d' % d.sync_j)
  150. if d.sync_c:
  151. have_default = True
  152. e.setAttribute('sync-c', 'true')
  153. if have_default:
  154. root.appendChild(e)
  155. root.appendChild(doc.createTextNode(''))
  156. if self._manifest_server:
  157. e = doc.createElement('manifest-server')
  158. e.setAttribute('url', self._manifest_server)
  159. root.appendChild(e)
  160. root.appendChild(doc.createTextNode(''))
  161. sort_projects = list(self.projects.keys())
  162. sort_projects.sort()
  163. for p in sort_projects:
  164. p = self.projects[p]
  165. if not p.MatchesGroups(groups):
  166. continue
  167. e = doc.createElement('project')
  168. root.appendChild(e)
  169. e.setAttribute('name', p.name)
  170. if p.relpath != p.name:
  171. e.setAttribute('path', p.relpath)
  172. if not d.remote or p.remote.name != d.remote.name:
  173. e.setAttribute('remote', p.remote.name)
  174. if peg_rev:
  175. if self.IsMirror:
  176. value = p.bare_git.rev_parse(p.revisionExpr + '^0')
  177. else:
  178. value = p.work_git.rev_parse(HEAD + '^0')
  179. e.setAttribute('revision', value)
  180. if peg_rev_upstream and value != p.revisionExpr:
  181. # Only save the origin if the origin is not a sha1, and the default
  182. # isn't our value, and the if the default doesn't already have that
  183. # covered.
  184. e.setAttribute('upstream', p.revisionExpr)
  185. elif not d.revisionExpr or p.revisionExpr != d.revisionExpr:
  186. e.setAttribute('revision', p.revisionExpr)
  187. for c in p.copyfiles:
  188. ce = doc.createElement('copyfile')
  189. ce.setAttribute('src', c.src)
  190. ce.setAttribute('dest', c.dest)
  191. e.appendChild(ce)
  192. default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath]
  193. egroups = [g for g in p.groups if g not in default_groups]
  194. if egroups:
  195. e.setAttribute('groups', ','.join(egroups))
  196. for a in p.annotations:
  197. if a.keep == "true":
  198. ae = doc.createElement('annotation')
  199. ae.setAttribute('name', a.name)
  200. ae.setAttribute('value', a.value)
  201. e.appendChild(ae)
  202. if p.sync_c:
  203. e.setAttribute('sync-c', 'true')
  204. if self._repo_hooks_project:
  205. root.appendChild(doc.createTextNode(''))
  206. e = doc.createElement('repo-hooks')
  207. e.setAttribute('in-project', self._repo_hooks_project.name)
  208. e.setAttribute('enabled-list',
  209. ' '.join(self._repo_hooks_project.enabled_repo_hooks))
  210. root.appendChild(e)
  211. doc.writexml(fd, '', ' ', '\n', 'UTF-8')
  212. @property
  213. def projects(self):
  214. self._Load()
  215. return self._projects
  216. @property
  217. def remotes(self):
  218. self._Load()
  219. return self._remotes
  220. @property
  221. def default(self):
  222. self._Load()
  223. return self._default
  224. @property
  225. def repo_hooks_project(self):
  226. self._Load()
  227. return self._repo_hooks_project
  228. @property
  229. def notice(self):
  230. self._Load()
  231. return self._notice
  232. @property
  233. def manifest_server(self):
  234. self._Load()
  235. return self._manifest_server
  236. @property
  237. def IsMirror(self):
  238. return self.manifestProject.config.GetBoolean('repo.mirror')
  239. def _Unload(self):
  240. self._loaded = False
  241. self._projects = {}
  242. self._remotes = {}
  243. self._default = None
  244. self._repo_hooks_project = None
  245. self._notice = None
  246. self.branch = None
  247. self._manifest_server = None
  248. def _Load(self):
  249. if not self._loaded:
  250. m = self.manifestProject
  251. b = m.GetBranch(m.CurrentBranch).merge
  252. if b is not None and b.startswith(R_HEADS):
  253. b = b[len(R_HEADS):]
  254. self.branch = b
  255. nodes = []
  256. nodes.append(self._ParseManifestXml(self.manifestFile,
  257. self.manifestProject.worktree))
  258. local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME)
  259. if os.path.exists(local):
  260. print('warning: %s is deprecated; put local manifests in %s instead'
  261. % (LOCAL_MANIFEST_NAME, LOCAL_MANIFESTS_DIR_NAME),
  262. file=sys.stderr)
  263. nodes.append(self._ParseManifestXml(local, self.repodir))
  264. local_dir = os.path.abspath(os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME))
  265. try:
  266. for local_file in sorted(os.listdir(local_dir)):
  267. if local_file.endswith('.xml'):
  268. try:
  269. nodes.append(self._ParseManifestXml(local_file, self.repodir))
  270. except ManifestParseError as e:
  271. print('%s' % str(e), file=sys.stderr)
  272. except OSError:
  273. pass
  274. self._ParseManifest(nodes)
  275. if self.IsMirror:
  276. self._AddMetaProjectMirror(self.repoProject)
  277. self._AddMetaProjectMirror(self.manifestProject)
  278. self._loaded = True
  279. def _ParseManifestXml(self, path, include_root):
  280. try:
  281. root = xml.dom.minidom.parse(path)
  282. except (OSError, xml.parsers.expat.ExpatError) as e:
  283. raise ManifestParseError("error parsing manifest %s: %s" % (path, e))
  284. if not root or not root.childNodes:
  285. raise ManifestParseError("no root node in %s" % (path,))
  286. for manifest in root.childNodes:
  287. if manifest.nodeName == 'manifest':
  288. break
  289. else:
  290. raise ManifestParseError("no <manifest> in %s" % (path,))
  291. nodes = []
  292. for node in manifest.childNodes: # pylint:disable=W0631
  293. # We only get here if manifest is initialised
  294. if node.nodeName == 'include':
  295. name = self._reqatt(node, 'name')
  296. fp = os.path.join(include_root, name)
  297. if not os.path.isfile(fp):
  298. raise ManifestParseError, \
  299. "include %s doesn't exist or isn't a file" % \
  300. (name,)
  301. try:
  302. nodes.extend(self._ParseManifestXml(fp, include_root))
  303. # should isolate this to the exact exception, but that's
  304. # tricky. actual parsing implementation may vary.
  305. except (KeyboardInterrupt, RuntimeError, SystemExit):
  306. raise
  307. except Exception as e:
  308. raise ManifestParseError(
  309. "failed parsing included manifest %s: %s", (name, e))
  310. else:
  311. nodes.append(node)
  312. return nodes
  313. def _ParseManifest(self, node_list):
  314. for node in itertools.chain(*node_list):
  315. if node.nodeName == 'remote':
  316. remote = self._ParseRemote(node)
  317. if remote:
  318. if remote.name in self._remotes:
  319. if remote != self._remotes[remote.name]:
  320. raise ManifestParseError(
  321. 'remote %s already exists with different attributes' %
  322. (remote.name))
  323. else:
  324. self._remotes[remote.name] = remote
  325. for node in itertools.chain(*node_list):
  326. if node.nodeName == 'default':
  327. if self._default is not None:
  328. raise ManifestParseError(
  329. 'duplicate default in %s' %
  330. (self.manifestFile))
  331. self._default = self._ParseDefault(node)
  332. if self._default is None:
  333. self._default = _Default()
  334. for node in itertools.chain(*node_list):
  335. if node.nodeName == 'notice':
  336. if self._notice is not None:
  337. raise ManifestParseError(
  338. 'duplicate notice in %s' %
  339. (self.manifestFile))
  340. self._notice = self._ParseNotice(node)
  341. for node in itertools.chain(*node_list):
  342. if node.nodeName == 'manifest-server':
  343. url = self._reqatt(node, 'url')
  344. if self._manifest_server is not None:
  345. raise ManifestParseError(
  346. 'duplicate manifest-server in %s' %
  347. (self.manifestFile))
  348. self._manifest_server = url
  349. for node in itertools.chain(*node_list):
  350. if node.nodeName == 'project':
  351. project = self._ParseProject(node)
  352. if self._projects.get(project.name):
  353. raise ManifestParseError(
  354. 'duplicate project %s in %s' %
  355. (project.name, self.manifestFile))
  356. self._projects[project.name] = project
  357. if node.nodeName == 'repo-hooks':
  358. # Get the name of the project and the (space-separated) list of enabled.
  359. repo_hooks_project = self._reqatt(node, 'in-project')
  360. enabled_repo_hooks = self._reqatt(node, 'enabled-list').split()
  361. # Only one project can be the hooks project
  362. if self._repo_hooks_project is not None:
  363. raise ManifestParseError(
  364. 'duplicate repo-hooks in %s' %
  365. (self.manifestFile))
  366. # Store a reference to the Project.
  367. try:
  368. self._repo_hooks_project = self._projects[repo_hooks_project]
  369. except KeyError:
  370. raise ManifestParseError(
  371. 'project %s not found for repo-hooks' %
  372. (repo_hooks_project))
  373. # Store the enabled hooks in the Project object.
  374. self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks
  375. if node.nodeName == 'remove-project':
  376. name = self._reqatt(node, 'name')
  377. try:
  378. del self._projects[name]
  379. except KeyError:
  380. raise ManifestParseError('remove-project element specifies non-existent '
  381. 'project: %s' % name)
  382. # If the manifest removes the hooks project, treat it as if it deleted
  383. # the repo-hooks element too.
  384. if self._repo_hooks_project and (self._repo_hooks_project.name == name):
  385. self._repo_hooks_project = None
  386. def _AddMetaProjectMirror(self, m):
  387. name = None
  388. m_url = m.GetRemote(m.remote.name).url
  389. if m_url.endswith('/.git'):
  390. raise ManifestParseError, 'refusing to mirror %s' % m_url
  391. if self._default and self._default.remote:
  392. url = self._default.remote.resolvedFetchUrl
  393. if not url.endswith('/'):
  394. url += '/'
  395. if m_url.startswith(url):
  396. remote = self._default.remote
  397. name = m_url[len(url):]
  398. if name is None:
  399. s = m_url.rindex('/') + 1
  400. manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
  401. remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl)
  402. name = m_url[s:]
  403. if name.endswith('.git'):
  404. name = name[:-4]
  405. if name not in self._projects:
  406. m.PreSync()
  407. gitdir = os.path.join(self.topdir, '%s.git' % name)
  408. project = Project(manifest = self,
  409. name = name,
  410. remote = remote.ToRemoteSpec(name),
  411. gitdir = gitdir,
  412. worktree = None,
  413. relpath = None,
  414. revisionExpr = m.revisionExpr,
  415. revisionId = None)
  416. self._projects[project.name] = project
  417. def _ParseRemote(self, node):
  418. """
  419. reads a <remote> element from the manifest file
  420. """
  421. name = self._reqatt(node, 'name')
  422. alias = node.getAttribute('alias')
  423. if alias == '':
  424. alias = None
  425. fetch = self._reqatt(node, 'fetch')
  426. review = node.getAttribute('review')
  427. if review == '':
  428. review = None
  429. manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
  430. return _XmlRemote(name, alias, fetch, manifestUrl, review)
  431. def _ParseDefault(self, node):
  432. """
  433. reads a <default> element from the manifest file
  434. """
  435. d = _Default()
  436. d.remote = self._get_remote(node)
  437. d.revisionExpr = node.getAttribute('revision')
  438. if d.revisionExpr == '':
  439. d.revisionExpr = None
  440. sync_j = node.getAttribute('sync-j')
  441. if sync_j == '' or sync_j is None:
  442. d.sync_j = 1
  443. else:
  444. d.sync_j = int(sync_j)
  445. sync_c = node.getAttribute('sync-c')
  446. if not sync_c:
  447. d.sync_c = False
  448. else:
  449. d.sync_c = sync_c.lower() in ("yes", "true", "1")
  450. return d
  451. def _ParseNotice(self, node):
  452. """
  453. reads a <notice> element from the manifest file
  454. The <notice> element is distinct from other tags in the XML in that the
  455. data is conveyed between the start and end tag (it's not an empty-element
  456. tag).
  457. The white space (carriage returns, indentation) for the notice element is
  458. relevant and is parsed in a way that is based on how python docstrings work.
  459. In fact, the code is remarkably similar to here:
  460. http://www.python.org/dev/peps/pep-0257/
  461. """
  462. # Get the data out of the node...
  463. notice = node.childNodes[0].data
  464. # Figure out minimum indentation, skipping the first line (the same line
  465. # as the <notice> tag)...
  466. minIndent = sys.maxint
  467. lines = notice.splitlines()
  468. for line in lines[1:]:
  469. lstrippedLine = line.lstrip()
  470. if lstrippedLine:
  471. indent = len(line) - len(lstrippedLine)
  472. minIndent = min(indent, minIndent)
  473. # Strip leading / trailing blank lines and also indentation.
  474. cleanLines = [lines[0].strip()]
  475. for line in lines[1:]:
  476. cleanLines.append(line[minIndent:].rstrip())
  477. # Clear completely blank lines from front and back...
  478. while cleanLines and not cleanLines[0]:
  479. del cleanLines[0]
  480. while cleanLines and not cleanLines[-1]:
  481. del cleanLines[-1]
  482. return '\n'.join(cleanLines)
  483. def _ParseProject(self, node):
  484. """
  485. reads a <project> element from the manifest file
  486. """
  487. name = self._reqatt(node, 'name')
  488. remote = self._get_remote(node)
  489. if remote is None:
  490. remote = self._default.remote
  491. if remote is None:
  492. raise ManifestParseError, \
  493. "no remote for project %s within %s" % \
  494. (name, self.manifestFile)
  495. revisionExpr = node.getAttribute('revision')
  496. if not revisionExpr:
  497. revisionExpr = self._default.revisionExpr
  498. if not revisionExpr:
  499. raise ManifestParseError, \
  500. "no revision for project %s within %s" % \
  501. (name, self.manifestFile)
  502. path = node.getAttribute('path')
  503. if not path:
  504. path = name
  505. if path.startswith('/'):
  506. raise ManifestParseError, \
  507. "project %s path cannot be absolute in %s" % \
  508. (name, self.manifestFile)
  509. rebase = node.getAttribute('rebase')
  510. if not rebase:
  511. rebase = True
  512. else:
  513. rebase = rebase.lower() in ("yes", "true", "1")
  514. sync_c = node.getAttribute('sync-c')
  515. if not sync_c:
  516. sync_c = False
  517. else:
  518. sync_c = sync_c.lower() in ("yes", "true", "1")
  519. upstream = node.getAttribute('upstream')
  520. groups = ''
  521. if node.hasAttribute('groups'):
  522. groups = node.getAttribute('groups')
  523. groups = [x for x in re.split(r'[,\s]+', groups) if x]
  524. default_groups = ['all', 'name:%s' % name, 'path:%s' % path]
  525. groups.extend(set(default_groups).difference(groups))
  526. if self.IsMirror:
  527. worktree = None
  528. gitdir = os.path.join(self.topdir, '%s.git' % name)
  529. else:
  530. worktree = os.path.join(self.topdir, path).replace('\\', '/')
  531. gitdir = os.path.join(self.repodir, 'projects/%s.git' % path)
  532. project = Project(manifest = self,
  533. name = name,
  534. remote = remote.ToRemoteSpec(name),
  535. gitdir = gitdir,
  536. worktree = worktree,
  537. relpath = path,
  538. revisionExpr = revisionExpr,
  539. revisionId = None,
  540. rebase = rebase,
  541. groups = groups,
  542. sync_c = sync_c,
  543. upstream = upstream)
  544. for n in node.childNodes:
  545. if n.nodeName == 'copyfile':
  546. self._ParseCopyFile(project, n)
  547. if n.nodeName == 'annotation':
  548. self._ParseAnnotation(project, n)
  549. return project
  550. def _ParseCopyFile(self, project, node):
  551. src = self._reqatt(node, 'src')
  552. dest = self._reqatt(node, 'dest')
  553. if not self.IsMirror:
  554. # src is project relative;
  555. # dest is relative to the top of the tree
  556. project.AddCopyFile(src, dest, os.path.join(self.topdir, dest))
  557. def _ParseAnnotation(self, project, node):
  558. name = self._reqatt(node, 'name')
  559. value = self._reqatt(node, 'value')
  560. try:
  561. keep = self._reqatt(node, 'keep').lower()
  562. except ManifestParseError:
  563. keep = "true"
  564. if keep != "true" and keep != "false":
  565. raise ManifestParseError, "optional \"keep\" attribute must be \"true\" or \"false\""
  566. project.AddAnnotation(name, value, keep)
  567. def _get_remote(self, node):
  568. name = node.getAttribute('remote')
  569. if not name:
  570. return None
  571. v = self._remotes.get(name)
  572. if not v:
  573. raise ManifestParseError, \
  574. "remote %s not defined in %s" % \
  575. (name, self.manifestFile)
  576. return v
  577. def _reqatt(self, node, attname):
  578. """
  579. reads a required attribute from the node.
  580. """
  581. v = node.getAttribute(attname)
  582. if not v:
  583. raise ManifestParseError, \
  584. "no %s in <%s> within %s" % \
  585. (attname, node.nodeName, self.manifestFile)
  586. return v