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