manifest.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # -*- coding:utf-8 -*-
  2. #
  3. # Copyright (C) 2009 The Android Open Source Project
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from __future__ import print_function
  17. import os
  18. import sys
  19. from command import PagedCommand
  20. class Manifest(PagedCommand):
  21. common = False
  22. helpSummary = "Manifest inspection utility"
  23. helpUsage = """
  24. %prog [-o {-|NAME.xml}] [-m MANIFEST.xml] [-r]
  25. """
  26. _helpDescription = """
  27. With the -o option, exports the current manifest for inspection.
  28. The manifest and (if present) local_manifest.xml are combined
  29. together to produce a single manifest file. This file can be stored
  30. in a Git repository for use during future 'repo init' invocations.
  31. """
  32. @property
  33. def helpDescription(self):
  34. helptext = self._helpDescription + '\n'
  35. r = os.path.dirname(__file__)
  36. r = os.path.dirname(r)
  37. with open(os.path.join(r, 'docs', 'manifest-format.md')) as fd:
  38. for line in fd:
  39. helptext += line
  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('-m', '--manifest-name',
  46. help='temporary manifest to use for this sync', metavar='NAME.xml')
  47. p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream',
  48. default=True, action='store_false',
  49. help='If in -r mode, do not write the upstream field. '
  50. 'Only of use if the branch names for a sha1 manifest are '
  51. 'sensitive.')
  52. p.add_option('-o', '--output-file',
  53. dest='output_file',
  54. default='-',
  55. help='File to save the manifest to',
  56. metavar='-|NAME.xml')
  57. def _Output(self, opt):
  58. # If alternate manifest is specified, override the manifest file that we're using.
  59. if opt.manifest_name:
  60. self.manifest.Override(opt.manifest_name, False)
  61. if opt.output_file == '-':
  62. fd = sys.stdout
  63. else:
  64. fd = open(opt.output_file, 'w')
  65. self.manifest.Save(fd,
  66. peg_rev=opt.peg_rev,
  67. peg_rev_upstream=opt.peg_rev_upstream)
  68. fd.close()
  69. if opt.output_file != '-':
  70. print('Saved manifest to %s' % opt.output_file, file=sys.stderr)
  71. def ValidateOptions(self, opt, args):
  72. if args:
  73. self.Usage()
  74. def Execute(self, opt, args):
  75. self._Output(opt)