| Mike Frysinger | f601376 | 2019-06-13 02:30:51 -0400 | [diff] [blame] | 1 | # -*- coding:utf-8 -*- | 
| Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 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 |  | 
| Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 17 | from __future__ import print_function | 
| Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 18 | import os | 
 | 19 | import sys | 
 | 20 |  | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 21 | from command import PagedCommand | 
| Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 22 |  | 
| David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 23 |  | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 24 | class Manifest(PagedCommand): | 
| Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 25 |   common = False | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 26 |   helpSummary = "Manifest inspection utility" | 
| Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 27 |   helpUsage = """ | 
| Sean McAllister | d38300c | 2020-02-20 13:49:01 -0700 | [diff] [blame] | 28 | %prog [-o {-|NAME.xml}] [-m MANIFEST.xml] [-r] | 
| Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 29 | """ | 
 | 30 |   _helpDescription = """ | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 31 |  | 
 | 32 | With the -o option, exports the current manifest for inspection. | 
 | 33 | The manifest and (if present) local_manifest.xml are combined | 
 | 34 | together to produce a single manifest file.  This file can be stored | 
 | 35 | in a Git repository for use during future 'repo init' invocations. | 
 | 36 |  | 
| Sean McAllister | 74e8ed4 | 2020-04-15 12:24:43 -0600 | [diff] [blame^] | 37 | The -r option can be used to generate a manifest file with project | 
 | 38 | revisions set to the current commit hash.  These are known as | 
 | 39 | "revision locked manifests", as they don't follow a particular branch. | 
 | 40 | In this case, the 'upstream' attribute is set to the ref we were on | 
 | 41 | when the manifest was generated. | 
| Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 42 | """ | 
 | 43 |  | 
 | 44 |   @property | 
 | 45 |   def helpDescription(self): | 
| David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 46 |     helptext = self._helpDescription + '\n' | 
| Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 47 |     r = os.path.dirname(__file__) | 
 | 48 |     r = os.path.dirname(r) | 
| Mike Frysinger | 3164d40 | 2019-11-11 05:40:22 -0500 | [diff] [blame] | 49 |     with open(os.path.join(r, 'docs', 'manifest-format.md')) as fd: | 
 | 50 |       for line in fd: | 
 | 51 |         helptext += line | 
| David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 52 |     return helptext | 
| Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 53 |  | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 54 |   def _Options(self, p): | 
 | 55 |     p.add_option('-r', '--revision-as-HEAD', | 
 | 56 |                  dest='peg_rev', action='store_true', | 
 | 57 |                  help='Save revisions as current HEAD') | 
| Sean McAllister | d38300c | 2020-02-20 13:49:01 -0700 | [diff] [blame] | 58 |     p.add_option('-m', '--manifest-name', | 
 | 59 |                  help='temporary manifest to use for this sync', metavar='NAME.xml') | 
| Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 60 |     p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream', | 
 | 61 |                  default=True, action='store_false', | 
 | 62 |                  help='If in -r mode, do not write the upstream field.  ' | 
 | 63 |                  'Only of use if the branch names for a sha1 manifest are ' | 
 | 64 |                  'sensitive.') | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 65 |     p.add_option('-o', '--output-file', | 
 | 66 |                  dest='output_file', | 
| Conley Owens | 918ff85 | 2012-08-07 10:44:01 -0700 | [diff] [blame] | 67 |                  default='-', | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 68 |                  help='File to save the manifest to', | 
 | 69 |                  metavar='-|NAME.xml') | 
 | 70 |  | 
 | 71 |   def _Output(self, opt): | 
| Sean McAllister | d38300c | 2020-02-20 13:49:01 -0700 | [diff] [blame] | 72 |     # If alternate manifest is specified, override the manifest file that we're using. | 
 | 73 |     if opt.manifest_name: | 
 | 74 |       self.manifest.Override(opt.manifest_name, False) | 
 | 75 |  | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 76 |     if opt.output_file == '-': | 
 | 77 |       fd = sys.stdout | 
 | 78 |     else: | 
 | 79 |       fd = open(opt.output_file, 'w') | 
 | 80 |     self.manifest.Save(fd, | 
| David Pursehouse | e5913ae | 2020-02-12 13:56:59 +0900 | [diff] [blame] | 81 |                        peg_rev=opt.peg_rev, | 
 | 82 |                        peg_rev_upstream=opt.peg_rev_upstream) | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 83 |     fd.close() | 
 | 84 |     if opt.output_file != '-': | 
| Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 85 |       print('Saved manifest to %s' % opt.output_file, file=sys.stderr) | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 86 |  | 
| Mike Frysinger | ae6cb08 | 2019-08-27 01:10:59 -0400 | [diff] [blame] | 87 |   def ValidateOptions(self, opt, args): | 
| Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 88 |     if args: | 
 | 89 |       self.Usage() | 
 | 90 |  | 
| Mike Frysinger | ae6cb08 | 2019-08-27 01:10:59 -0400 | [diff] [blame] | 91 |   def Execute(self, opt, args): | 
 | 92 |     self._Output(opt) |