manifest.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. 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.
  36. """
  37. @property
  38. def helpDescription(self):
  39. helptext = self._helpDescription + '\n'
  40. r = os.path.dirname(__file__)
  41. r = os.path.dirname(r)
  42. with open(os.path.join(r, 'docs', 'manifest-format.md')) as fd:
  43. for line in fd:
  44. helptext += line
  45. return helptext
  46. def _Options(self, p):
  47. p.add_option('-r', '--revision-as-HEAD',
  48. dest='peg_rev', action='store_true',
  49. help='Save revisions as current HEAD')
  50. p.add_option('-m', '--manifest-name',
  51. help='temporary manifest to use for this sync', metavar='NAME.xml')
  52. p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream',
  53. default=True, action='store_false',
  54. help='If in -r mode, do not write the upstream field. '
  55. 'Only of use if the branch names for a sha1 manifest are '
  56. 'sensitive.')
  57. p.add_option('-o', '--output-file',
  58. dest='output_file',
  59. default='-',
  60. help='File to save the manifest to',
  61. metavar='-|NAME.xml')
  62. def _Output(self, opt):
  63. # If alternate manifest is specified, override the manifest file that we're using.
  64. if opt.manifest_name:
  65. self.manifest.Override(opt.manifest_name, False)
  66. if opt.output_file == '-':
  67. fd = sys.stdout
  68. else:
  69. fd = open(opt.output_file, 'w')
  70. self.manifest.Save(fd,
  71. peg_rev=opt.peg_rev,
  72. peg_rev_upstream=opt.peg_rev_upstream)
  73. fd.close()
  74. if opt.output_file != '-':
  75. print('Saved manifest to %s' % opt.output_file, file=sys.stderr)
  76. def ValidateOptions(self, opt, args):
  77. if args:
  78. self.Usage()
  79. def Execute(self, opt, args):
  80. self._Output(opt)