blob: 4415b99e675031a14894f969e4b72f261003abe6 [file] [log] [blame]
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -08001#
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
16import os
17import sys
18
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080019from command import PagedCommand
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080020
Shawn O. Pearce050e4fd2009-06-03 14:16:14 -070021def _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. Pearcec7a4eef2009-03-05 10:32:38 -080030class Manifest(PagedCommand):
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080031 common = False
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080032 helpSummary = "Manifest inspection utility"
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080033 helpUsage = """
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080034%prog [-o {-|NAME.xml} [-r]]
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080035"""
Shawn O. Pearce050e4fd2009-06-03 14:16:14 -070036 _xmlHelp = """
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080037
38With the -o option, exports the current manifest for inspection.
39The manifest and (if present) local_manifest.xml are combined
40together to produce a single manifest file. This file can be stored
41in a Git repository for use during future 'repo init' invocations.
42
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080043"""
44
45 @property
46 def helpDescription(self):
Shawn O. Pearce050e4fd2009-06-03 14:16:14 -070047 help = ''
48 if isinstance(self.manifest, XmlManifest):
49 help += self._xmlHelp + '\n' + _doc('manifest_xml.txt')
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080050 return help
51
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080052 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. Pearce43c3d9e2009-03-04 14:26:50 -080072 def Execute(self, opt, args):
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080073 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. Pearce43c3d9e2009-03-04 14:26:50 -080081 print >>sys.stderr, 'error: see repo help manifest'
82 sys.exit(1)