blob: 551b13bdfe3741e50d78b85e7e9eb9471bb2ab13 [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. Pearce67f45632009-05-19 18:17:51 -070020from manifest_xml import XmlManifest
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080021
Shawn O. Pearce050e4fd2009-06-03 14:16:14 -070022def _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. Pearcec7a4eef2009-03-05 10:32:38 -080031class Manifest(PagedCommand):
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080032 common = False
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080033 helpSummary = "Manifest inspection utility"
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080034 helpUsage = """
Shawn O. Pearce67f45632009-05-19 18:17:51 -070035%prog [options]
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080036"""
Shawn O. Pearce050e4fd2009-06-03 14:16:14 -070037 _xmlHelp = """
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080038
39With the -o option, exports the current manifest for inspection.
40The manifest and (if present) local_manifest.xml are combined
41together to produce a single manifest file. This file can be stored
42in a Git repository for use during future 'repo init' invocations.
43
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080044"""
45
46 @property
47 def helpDescription(self):
Shawn O. Pearce050e4fd2009-06-03 14:16:14 -070048 help = ''
49 if isinstance(self.manifest, XmlManifest):
50 help += self._xmlHelp + '\n' + _doc('manifest_xml.txt')
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080051 return help
52
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080053 def _Options(self, p):
Shawn O. Pearce67f45632009-05-19 18:17:51 -070054 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. Pearcec7a4eef2009-03-05 10:32:38 -080062
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. Pearce43c3d9e2009-03-04 14:26:50 -080074 def Execute(self, opt, args):
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080075 if args:
76 self.Usage()
77
Shawn O. Pearce67f45632009-05-19 18:17:51 -070078 if isinstance(self.manifest, XmlManifest) \
79 and opt.output_file is not None:
80 self._Output(opt)
81 return
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080082
83 print >>sys.stderr, 'error: no operation to perform'
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080084 print >>sys.stderr, 'error: see repo help manifest'
85 sys.exit(1)