Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2009 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 16 | from __future__ import print_function |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 17 | import os |
| 18 | import sys |
| 19 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 20 | from command import PagedCommand |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 21 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 22 | class Manifest(PagedCommand): |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 23 | common = False |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 24 | helpSummary = "Manifest inspection utility" |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 25 | helpUsage = """ |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 26 | %prog [-o {-|NAME.xml} [-r]] |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 27 | """ |
| 28 | _helpDescription = """ |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 29 | |
| 30 | With the -o option, exports the current manifest for inspection. |
| 31 | The manifest and (if present) local_manifest.xml are combined |
| 32 | together to produce a single manifest file. This file can be stored |
| 33 | in a Git repository for use during future 'repo init' invocations. |
| 34 | |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 35 | """ |
| 36 | |
| 37 | @property |
| 38 | def helpDescription(self): |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 39 | helptext = self._helpDescription + '\n' |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 40 | r = os.path.dirname(__file__) |
| 41 | r = os.path.dirname(r) |
Mike Frysinger | 3891b75 | 2018-10-05 19:26:15 -0400 | [diff] [blame] | 42 | fd = open(os.path.join(r, 'docs', 'manifest-format.md')) |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 43 | for line in fd: |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 44 | helptext += line |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 45 | fd.close() |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 46 | return helptext |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 47 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 48 | def _Options(self, p): |
| 49 | p.add_option('-r', '--revision-as-HEAD', |
| 50 | dest='peg_rev', action='store_true', |
| 51 | help='Save revisions as current HEAD') |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 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.') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 57 | p.add_option('-o', '--output-file', |
| 58 | dest='output_file', |
Conley Owens | 918ff85 | 2012-08-07 10:44:01 -0700 | [diff] [blame] | 59 | default='-', |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 60 | help='File to save the manifest to', |
| 61 | metavar='-|NAME.xml') |
| 62 | |
| 63 | def _Output(self, opt): |
| 64 | if opt.output_file == '-': |
| 65 | fd = sys.stdout |
| 66 | else: |
| 67 | fd = open(opt.output_file, 'w') |
| 68 | self.manifest.Save(fd, |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 69 | peg_rev = opt.peg_rev, |
| 70 | peg_rev_upstream = opt.peg_rev_upstream) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 71 | fd.close() |
| 72 | if opt.output_file != '-': |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 73 | print('Saved manifest to %s' % opt.output_file, file=sys.stderr) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 74 | |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 75 | def Execute(self, opt, args): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 76 | if args: |
| 77 | self.Usage() |
| 78 | |
| 79 | if opt.output_file is not None: |
| 80 | self._Output(opt) |
| 81 | return |
| 82 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 83 | print('error: no operation to perform', file=sys.stderr) |
| 84 | print('error: see repo help manifest', file=sys.stderr) |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 85 | sys.exit(1) |