manifest.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #
  2. # Copyright (C) 2009 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 os
  16. import sys
  17. from command import PagedCommand
  18. from manifest_xml import XmlManifest
  19. def _doc(name):
  20. r = os.path.dirname(__file__)
  21. r = os.path.dirname(r)
  22. fd = open(os.path.join(r, 'docs', 'manifest_xml.txt'))
  23. try:
  24. return fd.read()
  25. finally:
  26. fd.close()
  27. class Manifest(PagedCommand):
  28. common = False
  29. helpSummary = "Manifest inspection utility"
  30. helpUsage = """
  31. %prog [options]
  32. """
  33. _xmlHelp = """
  34. With the -o option, exports the current manifest for inspection.
  35. The manifest and (if present) local_manifest.xml are combined
  36. together to produce a single manifest file. This file can be stored
  37. in a Git repository for use during future 'repo init' invocations.
  38. """
  39. @property
  40. def helpDescription(self):
  41. help = ''
  42. if isinstance(self.manifest, XmlManifest):
  43. help += self._xmlHelp + '\n' + _doc('manifest_xml.txt')
  44. return help
  45. def _Options(self, p):
  46. if isinstance(self.manifest, XmlManifest):
  47. p.add_option('-r', '--revision-as-HEAD',
  48. dest='peg_rev', action='store_true',
  49. help='Save revisions as current HEAD')
  50. p.add_option('-o', '--output-file',
  51. dest='output_file',
  52. help='File to save the manifest to',
  53. metavar='-|NAME.xml')
  54. def _Output(self, opt):
  55. if opt.output_file == '-':
  56. fd = sys.stdout
  57. else:
  58. fd = open(opt.output_file, 'w')
  59. self.manifest.Save(fd,
  60. peg_rev = opt.peg_rev)
  61. fd.close()
  62. if opt.output_file != '-':
  63. print >>sys.stderr, 'Saved manifest to %s' % opt.output_file
  64. def Execute(self, opt, args):
  65. if args:
  66. self.Usage()
  67. if isinstance(self.manifest, XmlManifest) \
  68. and opt.output_file is not None:
  69. self._Output(opt)
  70. return
  71. print >>sys.stderr, 'error: no operation to perform'
  72. print >>sys.stderr, 'error: see repo help manifest'
  73. sys.exit(1)