blob: 7a8b2ee8d18542a77627f96b22aefea390d76dad [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)
Shawn O. Pearce0125ae22009-07-03 18:05:23 -070025 fd = open(os.path.join(r, 'docs', name))
Shawn O. Pearce050e4fd2009-06-03 14:16:14 -070026 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. Pearce0125ae22009-07-03 18:05:23 -070051 if isinstance(self.manifest, SubmoduleManifest):
52 help += _doc('manifest_submodule.txt')
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080053 return help
54
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080055 def _Options(self, p):
Shawn O. Pearce67f45632009-05-19 18:17:51 -070056 if isinstance(self.manifest, XmlManifest):
57 p.add_option('-r', '--revision-as-HEAD',
58 dest='peg_rev', action='store_true',
59 help='Save revisions as current HEAD')
60 p.add_option('-o', '--output-file',
61 dest='output_file',
62 help='File to save the manifest to',
63 metavar='-|NAME.xml')
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080064
65 def _Output(self, opt):
66 if opt.output_file == '-':
67 fd = sys.stdout
68 else:
69 fd = open(opt.output_file, 'w')
70 self.manifest.Save(fd,
71 peg_rev = opt.peg_rev)
72 fd.close()
73 if opt.output_file != '-':
74 print >>sys.stderr, 'Saved manifest to %s' % opt.output_file
75
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080076 def Execute(self, opt, args):
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080077 if args:
78 self.Usage()
79
Shawn O. Pearce67f45632009-05-19 18:17:51 -070080 if isinstance(self.manifest, XmlManifest) \
81 and opt.output_file is not None:
82 self._Output(opt)
83 return
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080084
85 print >>sys.stderr, 'error: no operation to perform'
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080086 print >>sys.stderr, 'error: see repo help manifest'
87 sys.exit(1)