summaryrefslogtreecommitdiffstats
path: root/subcmds/manifest.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/manifest.py')
-rw-r--r--subcmds/manifest.py72
1 files changed, 41 insertions, 31 deletions
diff --git a/subcmds/manifest.py b/subcmds/manifest.py
index 0fbdeac0..08905cb4 100644
--- a/subcmds/manifest.py
+++ b/subcmds/manifest.py
@@ -15,6 +15,7 @@
15import json 15import json
16import os 16import os
17import sys 17import sys
18import optparse
18 19
19from command import PagedCommand 20from command import PagedCommand
20 21
@@ -75,7 +76,7 @@ to indicate the remote ref to push changes to via 'repo upload'.
75 p.add_option('-o', '--output-file', 76 p.add_option('-o', '--output-file',
76 dest='output_file', 77 dest='output_file',
77 default='-', 78 default='-',
78 help='file to save the manifest to', 79 help='file to save the manifest to. (Filename prefix for multi-tree.)',
79 metavar='-|NAME.xml') 80 metavar='-|NAME.xml')
80 81
81 def _Output(self, opt): 82 def _Output(self, opt):
@@ -83,36 +84,45 @@ to indicate the remote ref to push changes to via 'repo upload'.
83 if opt.manifest_name: 84 if opt.manifest_name:
84 self.manifest.Override(opt.manifest_name, False) 85 self.manifest.Override(opt.manifest_name, False)
85 86
86 if opt.output_file == '-': 87 for manifest in self.ManifestList(opt):
87 fd = sys.stdout 88 output_file = opt.output_file
88 else: 89 if output_file == '-':
89 fd = open(opt.output_file, 'w') 90 fd = sys.stdout
90 91 else:
91 self.manifest.SetUseLocalManifests(not opt.ignore_local_manifests) 92 if manifest.path_prefix:
92 93 output_file = f'{opt.output_file}:{manifest.path_prefix.replace("/", "%2f")}'
93 if opt.json: 94 fd = open(output_file, 'w')
94 print('warning: --json is experimental!', file=sys.stderr) 95
95 doc = self.manifest.ToDict(peg_rev=opt.peg_rev, 96 manifest.SetUseLocalManifests(not opt.ignore_local_manifests)
96 peg_rev_upstream=opt.peg_rev_upstream, 97
97 peg_rev_dest_branch=opt.peg_rev_dest_branch) 98 if opt.json:
98 99 print('warning: --json is experimental!', file=sys.stderr)
99 json_settings = { 100 doc = manifest.ToDict(peg_rev=opt.peg_rev,
100 # JSON style guide says Uunicode characters are fully allowed. 101 peg_rev_upstream=opt.peg_rev_upstream,
101 'ensure_ascii': False, 102 peg_rev_dest_branch=opt.peg_rev_dest_branch)
102 # We use 2 space indent to match JSON style guide. 103
103 'indent': 2 if opt.pretty else None, 104 json_settings = {
104 'separators': (',', ': ') if opt.pretty else (',', ':'), 105 # JSON style guide says Uunicode characters are fully allowed.
105 'sort_keys': True, 106 'ensure_ascii': False,
106 } 107 # We use 2 space indent to match JSON style guide.
107 fd.write(json.dumps(doc, **json_settings)) 108 'indent': 2 if opt.pretty else None,
108 else: 109 'separators': (',', ': ') if opt.pretty else (',', ':'),
109 self.manifest.Save(fd, 110 'sort_keys': True,
110 peg_rev=opt.peg_rev, 111 }
111 peg_rev_upstream=opt.peg_rev_upstream, 112 fd.write(json.dumps(doc, **json_settings))
112 peg_rev_dest_branch=opt.peg_rev_dest_branch) 113 else:
113 fd.close() 114 manifest.Save(fd,
114 if opt.output_file != '-': 115 peg_rev=opt.peg_rev,
115 print('Saved manifest to %s' % opt.output_file, file=sys.stderr) 116 peg_rev_upstream=opt.peg_rev_upstream,
117 peg_rev_dest_branch=opt.peg_rev_dest_branch)
118 if output_file != '-':
119 fd.close()
120 if manifest.path_prefix:
121 print(f'Saved {manifest.path_prefix} submanifest to {output_file}',
122 file=sys.stderr)
123 else:
124 print(f'Saved manifest to {output_file}', file=sys.stderr)
125
116 126
117 def ValidateOptions(self, opt, args): 127 def ValidateOptions(self, opt, args):
118 if args: 128 if args: