manifest.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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} [-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('--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 ValidateOptions(self, opt, args):
  67. if args:
  68. self.Usage()
  69. def Execute(self, opt, args):
  70. self._Output(opt)