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 | 050e4fd | 2009-06-03 14:16:14 -0700 | [diff] [blame^] | 21 | def _doc(name): |
| 22 | r = os.path.dirname(__file__) |
| 23 | r = os.path.dirname(r) |
| 24 | fd = open(os.path.join(r, 'docs', 'manifest_xml.txt')) |
| 25 | try: |
| 26 | return fd.read() |
| 27 | finally: |
| 28 | fd.close() |
| 29 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 30 | class Manifest(PagedCommand): |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 31 | common = False |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 32 | helpSummary = "Manifest inspection utility" |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 33 | helpUsage = """ |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 34 | %prog [-o {-|NAME.xml} [-r]] |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 35 | """ |
Shawn O. Pearce | 050e4fd | 2009-06-03 14:16:14 -0700 | [diff] [blame^] | 36 | _xmlHelp = """ |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 37 | |
| 38 | With the -o option, exports the current manifest for inspection. |
| 39 | The manifest and (if present) local_manifest.xml are combined |
| 40 | together to produce a single manifest file. This file can be stored |
| 41 | in a Git repository for use during future 'repo init' invocations. |
| 42 | |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 43 | """ |
| 44 | |
| 45 | @property |
| 46 | def helpDescription(self): |
Shawn O. Pearce | 050e4fd | 2009-06-03 14:16:14 -0700 | [diff] [blame^] | 47 | help = '' |
| 48 | if isinstance(self.manifest, XmlManifest): |
| 49 | help += self._xmlHelp + '\n' + _doc('manifest_xml.txt') |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 50 | return help |
| 51 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 52 | def _Options(self, p): |
| 53 | p.add_option('-r', '--revision-as-HEAD', |
| 54 | dest='peg_rev', action='store_true', |
| 55 | help='Save revisions as current HEAD') |
| 56 | p.add_option('-o', '--output-file', |
| 57 | dest='output_file', |
| 58 | help='File to save the manifest to', |
| 59 | metavar='-|NAME.xml') |
| 60 | |
| 61 | def _Output(self, opt): |
| 62 | if opt.output_file == '-': |
| 63 | fd = sys.stdout |
| 64 | else: |
| 65 | fd = open(opt.output_file, 'w') |
| 66 | self.manifest.Save(fd, |
| 67 | peg_rev = opt.peg_rev) |
| 68 | fd.close() |
| 69 | if opt.output_file != '-': |
| 70 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file |
| 71 | |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 72 | def Execute(self, opt, args): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 73 | if args: |
| 74 | self.Usage() |
| 75 | |
| 76 | if opt.output_file is not None: |
| 77 | self._Output(opt) |
| 78 | return |
| 79 | |
| 80 | print >>sys.stderr, 'error: no operation to perform' |
Shawn O. Pearce | 43c3d9e | 2009-03-04 14:26:50 -0800 | [diff] [blame] | 81 | print >>sys.stderr, 'error: see repo help manifest' |
| 82 | sys.exit(1) |