manifest.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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', name))
  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. if isinstance(self.manifest, SubmoduleManifest):
  45. help += _doc('manifest_submodule.txt')
  46. return help
  47. def _Options(self, p):
  48. if isinstance(self.manifest, XmlManifest):
  49. p.add_option('-r', '--revision-as-HEAD',
  50. dest='peg_rev', action='store_true',
  51. help='Save revisions as current HEAD')
  52. p.add_option('-o', '--output-file',
  53. dest='output_file',
  54. help='File to save the manifest to',
  55. metavar='-|NAME.xml')
  56. def _Output(self, opt):
  57. if opt.output_file == '-':
  58. fd = sys.stdout
  59. else:
  60. fd = open(opt.output_file, 'w')
  61. self.manifest.Save(fd,
  62. peg_rev = opt.peg_rev)
  63. fd.close()
  64. if opt.output_file != '-':
  65. print >>sys.stderr, 'Saved manifest to %s' % opt.output_file
  66. def Execute(self, opt, args):
  67. if args:
  68. self.Usage()
  69. if isinstance(self.manifest, XmlManifest) \
  70. and opt.output_file is not None:
  71. self._Output(opt)
  72. return
  73. print >>sys.stderr, 'error: no operation to perform'
  74. print >>sys.stderr, 'error: see repo help manifest'
  75. sys.exit(1)