blob: d9f242eedab58ab22911678aba46d5b39b466e80 [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -08002#
3# Copyright (C) 2009 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Sarah Owenscecd1d82012-11-01 22:59:27 -070017from __future__ import print_function
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080018import os
19import sys
20
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080021from command import PagedCommand
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080022
David Pursehouse819827a2020-02-12 15:20:19 +090023
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080024class Manifest(PagedCommand):
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080025 common = False
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080026 helpSummary = "Manifest inspection utility"
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080027 helpUsage = """
Sean McAllisterd38300c2020-02-20 13:49:01 -070028%prog [-o {-|NAME.xml}] [-m MANIFEST.xml] [-r]
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080029"""
30 _helpDescription = """
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080031
32With the -o option, exports the current manifest for inspection.
33The manifest and (if present) local_manifest.xml are combined
34together to produce a single manifest file. This file can be stored
35in a Git repository for use during future 'repo init' invocations.
36
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080037"""
38
39 @property
40 def helpDescription(self):
David Pursehouse8a68ff92012-09-24 12:15:13 +090041 helptext = self._helpDescription + '\n'
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080042 r = os.path.dirname(__file__)
43 r = os.path.dirname(r)
Mike Frysinger3164d402019-11-11 05:40:22 -050044 with open(os.path.join(r, 'docs', 'manifest-format.md')) as fd:
45 for line in fd:
46 helptext += line
David Pursehouse8a68ff92012-09-24 12:15:13 +090047 return helptext
Shawn O. Pearce43c3d9e2009-03-04 14:26:50 -080048
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080049 def _Options(self, p):
50 p.add_option('-r', '--revision-as-HEAD',
51 dest='peg_rev', action='store_true',
52 help='Save revisions as current HEAD')
Sean McAllisterd38300c2020-02-20 13:49:01 -070053 p.add_option('-m', '--manifest-name',
54 help='temporary manifest to use for this sync', metavar='NAME.xml')
Brian Harring14a66742012-09-28 20:21:57 -070055 p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream',
56 default=True, action='store_false',
57 help='If in -r mode, do not write the upstream field. '
58 'Only of use if the branch names for a sha1 manifest are '
59 'sensitive.')
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080060 p.add_option('-o', '--output-file',
61 dest='output_file',
Conley Owens918ff852012-08-07 10:44:01 -070062 default='-',
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080063 help='File to save the manifest to',
64 metavar='-|NAME.xml')
65
66 def _Output(self, opt):
Sean McAllisterd38300c2020-02-20 13:49:01 -070067 # If alternate manifest is specified, override the manifest file that we're using.
68 if opt.manifest_name:
69 self.manifest.Override(opt.manifest_name, False)
70
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080071 if opt.output_file == '-':
72 fd = sys.stdout
73 else:
74 fd = open(opt.output_file, 'w')
75 self.manifest.Save(fd,
David Pursehousee5913ae2020-02-12 13:56:59 +090076 peg_rev=opt.peg_rev,
77 peg_rev_upstream=opt.peg_rev_upstream)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080078 fd.close()
79 if opt.output_file != '-':
Sarah Owenscecd1d82012-11-01 22:59:27 -070080 print('Saved manifest to %s' % opt.output_file, file=sys.stderr)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080081
Mike Frysingerae6cb082019-08-27 01:10:59 -040082 def ValidateOptions(self, opt, args):
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -080083 if args:
84 self.Usage()
85
Mike Frysingerae6cb082019-08-27 01:10:59 -040086 def Execute(self, opt, args):
87 self._Output(opt)