manifest.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. class Manifest(PagedCommand):
  19. common = False
  20. helpSummary = "Manifest inspection utility"
  21. helpUsage = """
  22. %prog [-o {-|NAME.xml} [-r]]
  23. """
  24. _helpDescription = """
  25. With the -o option, exports the current manifest for inspection.
  26. The manifest and (if present) local_manifest.xml are combined
  27. together to produce a single manifest file. This file can be stored
  28. in a Git repository for use during future 'repo init' invocations.
  29. """
  30. @property
  31. def helpDescription(self):
  32. help = self._helpDescription + '\n'
  33. r = os.path.dirname(__file__)
  34. r = os.path.dirname(r)
  35. fd = open(os.path.join(r, 'docs', 'manifest-format.txt'))
  36. for line in fd:
  37. help += line
  38. fd.close()
  39. return help
  40. def _Options(self, p):
  41. p.add_option('-r', '--revision-as-HEAD',
  42. dest='peg_rev', action='store_true',
  43. help='Save revisions as current HEAD')
  44. p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream',
  45. default=True, action='store_false',
  46. help='If in -r mode, do not write the upstream field. '
  47. 'Only of use if the branch names for a sha1 manifest are '
  48. 'sensitive.')
  49. p.add_option('-o', '--output-file',
  50. dest='output_file',
  51. default='-',
  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. peg_rev_upstream = opt.peg_rev_upstream)
  62. fd.close()
  63. if opt.output_file != '-':
  64. print >>sys.stderr, 'Saved manifest to %s' % opt.output_file
  65. def Execute(self, opt, args):
  66. if args:
  67. self.Usage()
  68. if 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)