summaryrefslogtreecommitdiffstats
path: root/subcmds/manifest.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/manifest.py')
-rw-r--r--subcmds/manifest.py70
1 files changed, 56 insertions, 14 deletions
diff --git a/subcmds/manifest.py b/subcmds/manifest.py
index 9c1b3f0c..0fbdeac0 100644
--- a/subcmds/manifest.py
+++ b/subcmds/manifest.py
@@ -1,5 +1,3 @@
1# -*- coding:utf-8 -*-
2#
3# Copyright (C) 2009 The Android Open Source Project 1# Copyright (C) 2009 The Android Open Source Project
4# 2#
5# Licensed under the Apache License, Version 2.0 (the "License"); 3# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,25 +12,32 @@
14# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
15# limitations under the License. 13# limitations under the License.
16 14
17from __future__ import print_function 15import json
18import os 16import os
19import sys 17import sys
20 18
21from command import PagedCommand 19from command import PagedCommand
22 20
21
23class Manifest(PagedCommand): 22class Manifest(PagedCommand):
24 common = False 23 COMMON = False
25 helpSummary = "Manifest inspection utility" 24 helpSummary = "Manifest inspection utility"
26 helpUsage = """ 25 helpUsage = """
27%prog [-o {-|NAME.xml} [-r]] 26%prog [-o {-|NAME.xml}] [-m MANIFEST.xml] [-r]
28""" 27"""
29 _helpDescription = """ 28 _helpDescription = """
30 29
31With the -o option, exports the current manifest for inspection. 30With the -o option, exports the current manifest for inspection.
32The manifest and (if present) local_manifest.xml are combined 31The manifest and (if present) local_manifests/ are combined
33together to produce a single manifest file. This file can be stored 32together to produce a single manifest file. This file can be stored
34in a Git repository for use during future 'repo init' invocations. 33in a Git repository for use during future 'repo init' invocations.
35 34
35The -r option can be used to generate a manifest file with project
36revisions set to the current commit hash. These are known as
37"revision locked manifests", as they don't follow a particular branch.
38In this case, the 'upstream' attribute is set to the ref we were on
39when the manifest was generated. The 'dest-branch' attribute is set
40to indicate the remote ref to push changes to via 'repo upload'.
36""" 41"""
37 42
38 @property 43 @property
@@ -48,26 +53,63 @@ in a Git repository for use during future 'repo init' invocations.
48 def _Options(self, p): 53 def _Options(self, p):
49 p.add_option('-r', '--revision-as-HEAD', 54 p.add_option('-r', '--revision-as-HEAD',
50 dest='peg_rev', action='store_true', 55 dest='peg_rev', action='store_true',
51 help='Save revisions as current HEAD') 56 help='save revisions as current HEAD')
57 p.add_option('-m', '--manifest-name',
58 help='temporary manifest to use for this sync', metavar='NAME.xml')
52 p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream', 59 p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream',
53 default=True, action='store_false', 60 default=True, action='store_false',
54 help='If in -r mode, do not write the upstream field. ' 61 help='if in -r mode, do not write the upstream field '
55 'Only of use if the branch names for a sha1 manifest are ' 62 '(only of use if the branch names for a sha1 manifest are '
56 'sensitive.') 63 'sensitive)')
64 p.add_option('--suppress-dest-branch', dest='peg_rev_dest_branch',
65 default=True, action='store_false',
66 help='if in -r mode, do not write the dest-branch field '
67 '(only of use if the branch names for a sha1 manifest are '
68 'sensitive)')
69 p.add_option('--json', default=False, action='store_true',
70 help='output manifest in JSON format (experimental)')
71 p.add_option('--pretty', default=False, action='store_true',
72 help='format output for humans to read')
73 p.add_option('--no-local-manifests', default=False, action='store_true',
74 dest='ignore_local_manifests', help='ignore local manifests')
57 p.add_option('-o', '--output-file', 75 p.add_option('-o', '--output-file',
58 dest='output_file', 76 dest='output_file',
59 default='-', 77 default='-',
60 help='File to save the manifest to', 78 help='file to save the manifest to',
61 metavar='-|NAME.xml') 79 metavar='-|NAME.xml')
62 80
63 def _Output(self, opt): 81 def _Output(self, opt):
82 # If alternate manifest is specified, override the manifest file that we're using.
83 if opt.manifest_name:
84 self.manifest.Override(opt.manifest_name, False)
85
64 if opt.output_file == '-': 86 if opt.output_file == '-':
65 fd = sys.stdout 87 fd = sys.stdout
66 else: 88 else:
67 fd = open(opt.output_file, 'w') 89 fd = open(opt.output_file, 'w')
68 self.manifest.Save(fd, 90
69 peg_rev = opt.peg_rev, 91 self.manifest.SetUseLocalManifests(not opt.ignore_local_manifests)
70 peg_rev_upstream = opt.peg_rev_upstream) 92
93 if opt.json:
94 print('warning: --json is experimental!', file=sys.stderr)
95 doc = self.manifest.ToDict(peg_rev=opt.peg_rev,
96 peg_rev_upstream=opt.peg_rev_upstream,
97 peg_rev_dest_branch=opt.peg_rev_dest_branch)
98
99 json_settings = {
100 # JSON style guide says Uunicode characters are fully allowed.
101 'ensure_ascii': False,
102 # We use 2 space indent to match JSON style guide.
103 'indent': 2 if opt.pretty else None,
104 'separators': (',', ': ') if opt.pretty else (',', ':'),
105 'sort_keys': True,
106 }
107 fd.write(json.dumps(doc, **json_settings))
108 else:
109 self.manifest.Save(fd,
110 peg_rev=opt.peg_rev,
111 peg_rev_upstream=opt.peg_rev_upstream,
112 peg_rev_dest_branch=opt.peg_rev_dest_branch)
71 fd.close() 113 fd.close()
72 if opt.output_file != '-': 114 if opt.output_file != '-':
73 print('Saved manifest to %s' % opt.output_file, file=sys.stderr) 115 print('Saved manifest to %s' % opt.output_file, file=sys.stderr)