Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace optparse by argparse #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions ninjatracing
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Usage:

import json
import os
import optparse
import argparse
import re
import sys

Expand Down Expand Up @@ -158,29 +158,25 @@ def log_to_dicts(log, pid, options):

def main(argv):
usage = __doc__
parser = optparse.OptionParser(usage)
parser.add_option('-a', '--showall', action='store_true', dest='showall',
default=False,
help='report on last build step for all outputs. Default '
'is to report just on the last (possibly incremental) '
'build')
parser.add_option('-g', '--granularity', type='int', default=50000,
dest='granularity',
help='minimum length time-trace event to embed in '
'microseconds. Default: %default')
parser.add_option('-e', '--embed-time-trace', action='store_true',
default=False, dest='embed_time_trace',
help='embed clang -ftime-trace json file found adjacent '
'to a target file')
(options, args) = parser.parse_args()

if len(args) == 0:
print('Must specify at least one .ninja_log file')
parser.print_help()
return 1
parser = argparse.ArgumentParser(usage)
parser.add_argument("logfiles", nargs="*", help=argparse.SUPPRESS)
parser.add_argument('-a', '--showall', action='store_true',
dest='showall', default=False,
help='report on last build step for all outputs. '
'Default is to report just on the last '
'(possibly incremental) build')
parser.add_argument('-g', '--granularity', type=int, default=50000,
dest='granularity',
help='minimum length time-trace event to embed in '
'microseconds. Default: 50000')
parser.add_argument('-e', '--embed-time-trace', action='store_true',
default=False, dest='embed_time_trace',
help='embed clang -ftime-trace json file found '
'adjacent to a target file')
options = parser.parse_args()

entries = []
for pid, log_file in enumerate(args):
for pid, log_file in enumerate(options.logfiles):
with open(log_file, 'r') as log:
entries += list(log_to_dicts(log, pid, vars(options)))
json.dump(entries, sys.stdout)
Expand Down