manifest.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_manifests/ 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. The -r option can be used to generate a manifest file with project
  32. revisions set to the current commit hash. These are known as
  33. "revision locked manifests", as they don't follow a particular branch.
  34. In this case, the 'upstream' attribute is set to the ref we were on
  35. when the manifest was generated. The 'dest-branch' attribute is set
  36. to indicate the remote ref to push changes to via 'repo upload'.
  37. """
  38. @property
  39. def helpDescription(self):
  40. helptext = self._helpDescription + '\n'
  41. r = os.path.dirname(__file__)
  42. r = os.path.dirname(r)
  43. with open(os.path.join(r, 'docs', 'manifest-format.md')) as fd:
  44. for line in fd:
  45. helptext += line
  46. return helptext
  47. def _Options(self, p):
  48. p.add_option('-r', '--revision-as-HEAD',
  49. dest='peg_rev', action='store_true',
  50. help='Save revisions as current HEAD')
  51. p.add_option('-m', '--manifest-name',
  52. help='temporary manifest to use for this sync', metavar='NAME.xml')
  53. p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream',
  54. default=True, action='store_false',
  55. help='If in -r mode, do not write the upstream field. '
  56. 'Only of use if the branch names for a sha1 manifest are '
  57. 'sensitive.')
  58. p.add_option('--suppress-dest-branch', dest='peg_rev_dest_branch',
  59. default=True, action='store_false',
  60. help='If in -r mode, do not write the dest-branch field. '
  61. 'Only of use if the branch names for a sha1 manifest are '
  62. 'sensitive.')
  63. p.add_option('-o', '--output-file',
  64. dest='output_file',
  65. default='-',
  66. help='File to save the manifest to',
  67. metavar='-|NAME.xml')
  68. def _Output(self, opt):
  69. # If alternate manifest is specified, override the manifest file that we're using.
  70. if opt.manifest_name:
  71. self.manifest.Override(opt.manifest_name, False)
  72. if opt.output_file == '-':
  73. fd = sys.stdout
  74. else:
  75. fd = open(opt.output_file, 'w')
  76. self.manifest.Save(fd,
  77. peg_rev=opt.peg_rev,
  78. peg_rev_upstream=opt.peg_rev_upstream,
  79. peg_rev_dest_branch=opt.peg_rev_dest_branch)
  80. fd.close()
  81. if opt.output_file != '-':
  82. print('Saved manifest to %s' % opt.output_file, file=sys.stderr)
  83. def ValidateOptions(self, opt, args):
  84. if args:
  85. self.Usage()
  86. def Execute(self, opt, args):
  87. self._Output(opt)