diff options
Diffstat (limited to 'subcmds/manifest.py')
| -rw-r--r-- | subcmds/manifest.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/subcmds/manifest.py b/subcmds/manifest.py index f0a0d069..0052d7aa 100644 --- a/subcmds/manifest.py +++ b/subcmds/manifest.py | |||
| @@ -15,6 +15,8 @@ | |||
| 15 | # limitations under the License. | 15 | # limitations under the License. |
| 16 | 16 | ||
| 17 | from __future__ import print_function | 17 | from __future__ import print_function |
| 18 | |||
| 19 | import json | ||
| 18 | import os | 20 | import os |
| 19 | import sys | 21 | import sys |
| 20 | 22 | ||
| @@ -68,6 +70,10 @@ to indicate the remote ref to push changes to via 'repo upload'. | |||
| 68 | help='If in -r mode, do not write the dest-branch field. ' | 70 | help='If in -r mode, do not write the dest-branch field. ' |
| 69 | 'Only of use if the branch names for a sha1 manifest are ' | 71 | 'Only of use if the branch names for a sha1 manifest are ' |
| 70 | 'sensitive.') | 72 | 'sensitive.') |
| 73 | p.add_option('--json', default=False, action='store_true', | ||
| 74 | help='Output manifest in JSON format (experimental).') | ||
| 75 | p.add_option('--pretty', default=False, action='store_true', | ||
| 76 | help='Format output for humans to read.') | ||
| 71 | p.add_option('-o', '--output-file', | 77 | p.add_option('-o', '--output-file', |
| 72 | dest='output_file', | 78 | dest='output_file', |
| 73 | default='-', | 79 | default='-', |
| @@ -83,10 +89,26 @@ to indicate the remote ref to push changes to via 'repo upload'. | |||
| 83 | fd = sys.stdout | 89 | fd = sys.stdout |
| 84 | else: | 90 | else: |
| 85 | fd = open(opt.output_file, 'w') | 91 | fd = open(opt.output_file, 'w') |
| 86 | self.manifest.Save(fd, | 92 | if opt.json: |
| 87 | peg_rev=opt.peg_rev, | 93 | print('warning: --json is experimental!', file=sys.stderr) |
| 88 | peg_rev_upstream=opt.peg_rev_upstream, | 94 | doc = self.manifest.ToDict(peg_rev=opt.peg_rev, |
| 89 | peg_rev_dest_branch=opt.peg_rev_dest_branch) | 95 | peg_rev_upstream=opt.peg_rev_upstream, |
| 96 | peg_rev_dest_branch=opt.peg_rev_dest_branch) | ||
| 97 | |||
| 98 | json_settings = { | ||
| 99 | # JSON style guide says Uunicode characters are fully allowed. | ||
| 100 | 'ensure_ascii': False, | ||
| 101 | # We use 2 space indent to match JSON style guide. | ||
| 102 | 'indent': 2 if opt.pretty else None, | ||
| 103 | 'separators': (',', ': ') if opt.pretty else (',', ':'), | ||
| 104 | 'sort_keys': True, | ||
| 105 | } | ||
| 106 | fd.write(json.dumps(doc, **json_settings)) | ||
| 107 | else: | ||
| 108 | self.manifest.Save(fd, | ||
| 109 | peg_rev=opt.peg_rev, | ||
| 110 | peg_rev_upstream=opt.peg_rev_upstream, | ||
| 111 | peg_rev_dest_branch=opt.peg_rev_dest_branch) | ||
| 90 | fd.close() | 112 | fd.close() |
| 91 | if opt.output_file != '-': | 113 | if opt.output_file != '-': |
| 92 | print('Saved manifest to %s' % opt.output_file, file=sys.stderr) | 114 | print('Saved manifest to %s' % opt.output_file, file=sys.stderr) |
