blob: 5592a37d137e104b4d7125803c965c15ef6cb0b4 [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. Pearcec7a4eef2009-03-05 10:32:38 -080021class Manifest(PagedCommand):
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080022 common = False
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080023 helpSummary = "Manifest inspection utility"
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080024 helpUsage = """
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080025%prog [-o {-|NAME.xml} [-r]]
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080026"""
27 _helpDescription = """
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080028
29With the -o option, exports the current manifest for inspection.
30The manifest and (if present) local_manifest.xml are combined
31together to produce a single manifest file. This file can be stored
32in a Git repository for use during future 'repo init' invocations.
33
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080034"""
35
36 @property
37 def helpDescription(self):
David Pursehouse8a68ff92012-09-24 12:15:13 +090038 helptext = self._helpDescription + '\n'
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080039 r = os.path.dirname(__file__)
40 r = os.path.dirname(r)
41 fd = open(os.path.join(r, 'docs', 'manifest-format.txt'))
42 for line in fd:
David Pursehouse8a68ff92012-09-24 12:15:13 +090043 helptext += line
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080044 fd.close()
David Pursehouse8a68ff92012-09-24 12:15:13 +090045 return helptext
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080046
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080047 def _Options(self, p):
48 p.add_option('-r', '--revision-as-HEAD',
49 dest='peg_rev', action='store_true',
50 help='Save revisions as current HEAD')
Brian Harring14a66742012-09-28 20:21:57 -070051 p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream',
52 default=True, action='store_false',
53 help='If in -r mode, do not write the upstream field. '
54 'Only of use if the branch names for a sha1 manifest are '
55 'sensitive.')
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080056 p.add_option('-o', '--output-file',
57 dest='output_file',
Conley Owens918ff852012-08-07 10:44:01 -070058 default='-',
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080059 help='File to save the manifest to',
60 metavar='-|NAME.xml')
61
62 def _Output(self, opt):
63 if opt.output_file == '-':
64 fd = sys.stdout
65 else:
66 fd = open(opt.output_file, 'w')
67 self.manifest.Save(fd,
Brian Harring14a66742012-09-28 20:21:57 -070068 peg_rev = opt.peg_rev,
69 peg_rev_upstream = opt.peg_rev_upstream)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080070 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
78 if opt.output_file is not None:
79 self._Output(opt)
80 return
81
82 print >>sys.stderr, 'error: no operation to perform'
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080083 print >>sys.stderr, 'error: see repo help manifest'
84 sys.exit(1)