manifest_xml.py 21 KB

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