diff options
author | Jaewan Kim <jaewan@google.com> | 2024-05-09 14:01:09 +0900 |
---|---|---|
committer | Jaewan Kim <jaewan@google.com> | 2024-05-09 07:04:32 +0000 |
commit | 0b07f76c2dbbeb765aa349f0be44c5fd8f1855dc (patch) | |
tree | ef0d9a6303c98f1221eb9bc8b4cc2fbc6414c820 | |
parent | f9133cdaf7b3584eb69f1c0e9ec11b352170067e (diff) | |
download | development-0b07f76c2dbbeb765aa349f0be44c5fd8f1855dc.tar.gz |
gerrit: Add parsing friendly output format
Added `--format porcelain` (name is borrowed from git),
so items are deliminated by tab instead of spaces.
Test: Manually
Change-Id: If99fff5df3eb9f94d3dda940de8f4d489f680fcd
-rwxr-xr-x | tools/repo_pull/gerrit.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/tools/repo_pull/gerrit.py b/tools/repo_pull/gerrit.py index c93461d25..601c3ff5c 100755 --- a/tools/repo_pull/gerrit.py +++ b/tools/repo_pull/gerrit.py @@ -608,7 +608,7 @@ def _parse_args(): parser = argparse.ArgumentParser() add_common_parse_args(parser) parser.add_argument('--format', default='json', - choices=['json', 'oneline'], + choices=['json', 'oneline', 'porcelain'], help='Print format') return parser.parse_args() @@ -635,16 +635,22 @@ def main(): if args.format == 'json': json.dump(change_lists, sys.stdout, indent=4, separators=(', ', ': ')) print() # Print the end-of-line - elif args.format == 'oneline': + else: + if args.format == 'oneline': + format_str = ('{i:<8} {number:<16} {status:<20} ' + '{change_id:<60} {project:<120} ' + '{subject}') + else: + format_str = ('{i}\t{number}\t{status}\t' + '{change_id}\t{project}\t{subject}') + for i, change in enumerate(change_lists): - print('{i:<8} {number:<16} {status:<20} ' \ - '{change_id:<60} {project:<120} ' \ - '{subject}'.format(i=i, - project=change['project'], - change_id=change['change_id'], - status=change['status'], - number=change['_number'], - subject=change['subject'])) + print(format_str.format(i=i, + project=change['project'], + change_id=change['change_id'], + status=change['status'], + number=change['_number'], + subject=change['subject'])) if __name__ == '__main__': |