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 | |
| 16 | import os |
| 17 | import sys |
| 18 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 19 | from command import PagedCommand |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 20 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 21 | class Manifest(PagedCommand): |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 22 | common = False |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 23 | helpSummary = "Manifest inspection utility" |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 24 | helpUsage = """ |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 25 | %prog [-o {-|NAME.xml} [-r]] |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 26 | """ |
| 27 | _helpDescription = """ |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 28 | |
| 29 | With the -o option, exports the current manifest for inspection. |
| 30 | The manifest and (if present) local_manifest.xml are combined |
| 31 | together to produce a single manifest file. This file can be stored |
| 32 | in a Git repository for use during future 'repo init' invocations. |
| 33 | |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 34 | """ |
| 35 | |
| 36 | @property |
| 37 | def helpDescription(self): |
| 38 | help = self._helpDescription + '\n' |
| 39 | r = os.path.dirname(__file__) |
| 40 | r = os.path.dirname(r) |
| 41 | fd = open(os.path.join(r, 'docs', 'manifest-format.txt')) |
| 42 | for line in fd: |
| 43 | help += line |
| 44 | fd.close() |
| 45 | return help |
| 46 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 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('-o', '--output-file', |
| 52 | dest='output_file', |
Conley Owens | 918ff85 | 2012-08-07 10:44:01 -0700 | [diff] [blame] | 53 | default='-', |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 54 | help='File to save the manifest to', |
| 55 | metavar='-|NAME.xml') |
| 56 | |
| 57 | def _Output(self, opt): |
| 58 | if opt.output_file == '-': |
| 59 | fd = sys.stdout |
| 60 | else: |
| 61 | fd = open(opt.output_file, 'w') |
| 62 | self.manifest.Save(fd, |
| 63 | peg_rev = opt.peg_rev) |
| 64 | fd.close() |
| 65 | if opt.output_file != '-': |
| 66 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file |
| 67 | |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 68 | def Execute(self, opt, args): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 69 | if args: |
| 70 | self.Usage() |
| 71 | |
| 72 | if opt.output_file is not None: |
| 73 | self._Output(opt) |
| 74 | return |
| 75 | |
| 76 | print >>sys.stderr, 'error: no operation to perform' |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 77 | print >>sys.stderr, 'error: see repo help manifest' |
| 78 | sys.exit(1) |