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