Commit a2e91dbb authored by Takuto Ikuta's avatar Takuto Ikuta Committed by LUCI CQ

apply yapf for ninjalog*.py

This is preparation to fix the issue.

Bug: 992282
Change-Id: I64b237670bf460ff765df3eaf069b0e0bdcfb31d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2237268
Commit-Queue: Ye Kuang <yekuang@google.com>
Reviewed-by: 's avatarYe Kuang <yekuang@google.com>
Auto-Submit: Takuto Ikuta <tikuta@chromium.org>
parent 37e56211
......@@ -2,7 +2,6 @@
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
This is script to upload ninja_log from googler.
......@@ -32,20 +31,21 @@ import httplib2
# These build configs affect build performance a lot.
# TODO(tikuta): Add 'blink_symbol_level', 'closure_compile' and
# 'use_jumbo_build'.
WHITELISTED_CONFIGS = (
'symbol_level', 'use_goma', 'is_debug', 'is_component_build', 'enable_nacl',
'host_os', 'host_cpu', 'target_os', 'target_cpu'
)
WHITELISTED_CONFIGS = ('symbol_level', 'use_goma', 'is_debug',
'is_component_build', 'enable_nacl', 'host_os',
'host_cpu', 'target_os', 'target_cpu')
def IsGoogler(server):
"""Check whether this script run inside corp network."""
try:
h = httplib2.Http()
_, content = h.request('https://'+server+'/should-upload', 'GET')
_, content = h.request('https://' + server + '/should-upload', 'GET')
return content == 'Success'
except httplib2.HttpLib2Error:
return False
def ParseGNArgs(gn_args):
"""Parse gn_args as json and return config dictionary."""
configs = json.loads(gn_args)
......@@ -62,6 +62,7 @@ def ParseGNArgs(gn_args):
return build_configs
def GetBuildTargetFromCommandLine(cmdline):
"""Get build targets from commandline."""
......@@ -80,8 +81,7 @@ def GetBuildTargetFromCommandLine(cmdline):
idx += 2
continue
if (cmdline[idx][:2] in onearg_flags or
cmdline[idx] in zeroarg_flags):
if (cmdline[idx][:2] in onearg_flags or cmdline[idx] in zeroarg_flags):
idx += 1
continue
......@@ -90,16 +90,16 @@ def GetBuildTargetFromCommandLine(cmdline):
return targets
def GetJflag(cmdline):
"""Parse cmdline to get flag value for -j"""
for i in range(len(cmdline)):
if (cmdline[i] == '-j' and i + 1 < len(cmdline) and
cmdline[i+1].isdigit()):
return int(cmdline[i+1])
if (cmdline[i] == '-j' and i + 1 < len(cmdline)
and cmdline[i + 1].isdigit()):
return int(cmdline[i + 1])
if (cmdline[i].startswith('-j') and
cmdline[i][len('-j'):].isdigit()):
if (cmdline[i].startswith('-j') and cmdline[i][len('-j'):].isdigit()):
return int(cmdline[i][len('-j'):])
......@@ -145,6 +145,7 @@ def GetMetadata(cmdline, ninjalog):
return metadata
def GetNinjalog(cmdline):
"""GetNinjalog returns the path to ninjalog from cmdline."""
# ninjalog is in current working directory by default.
......@@ -164,15 +165,19 @@ def GetNinjalog(cmdline):
return os.path.join(ninjalog_dir, '.ninja_log')
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--server',
default='chromium-build-stats.appspot.com',
help='server to upload ninjalog file.')
parser.add_argument('--ninjalog', help='ninjalog file to upload.')
parser.add_argument('--verbose', action='store_true',
parser.add_argument('--verbose',
action='store_true',
help='Enable verbose logging.')
parser.add_argument('--cmdline', required=True, nargs=argparse.REMAINDER,
parser.add_argument('--cmdline',
required=True,
nargs=argparse.REMAINDER,
help='command line args passed to ninja.')
args = parser.parse_args()
......@@ -186,7 +191,6 @@ def main():
if not IsGoogler(args.server):
return 0
ninjalog = args.ninjalog or GetNinjalog(args.cmdline)
if not os.path.isfile(ninjalog):
logging.warn("ninjalog is not found in %s", ninjalog)
......@@ -210,18 +214,20 @@ def main():
g.write(json.dumps(metadata))
h = httplib2.Http()
resp_headers, content = h.request(
'https://'+args.server+'/upload_ninja_log/', 'POST',
body=output.getvalue(), headers={'Content-Encoding': 'gzip'})
resp_headers, content = h.request('https://' + args.server +
'/upload_ninja_log/',
'POST',
body=output.getvalue(),
headers={'Content-Encoding': 'gzip'})
if resp_headers.status != 200:
logging.warn("unexpected status code for response: %s",
resp_headers.status)
logging.warn("unexpected status code for response: %s", resp_headers.status)
return 1
logging.info('response header: %s', resp_headers)
logging.info('response content: %s', content)
return 0
if __name__ == '__main__':
sys.exit(main())
......@@ -27,8 +27,8 @@ def LoadConfig():
return config
return {
'is-googler': ninjalog_uploader.IsGoogler(
'chromium-build-stats.appspot.com'),
'is-googler':
ninjalog_uploader.IsGoogler('chromium-build-stats.appspot.com'),
'countdown': 10,
'version': VERSION,
}
......@@ -40,8 +40,8 @@ def SaveConfig(config):
def ShowMessage(countdown):
whitelisted = '\n'.join([' * %s' % config for config in
ninjalog_uploader.WHITELISTED_CONFIGS])
whitelisted = '\n'.join(
[' * %s' % config for config in ninjalog_uploader.WHITELISTED_CONFIGS])
print("""
Your ninjalog will be uploaded to build stats server. The uploaded log will be
used to analyze user side build performance.
......@@ -111,7 +111,8 @@ def main():
# Run upload script without wait.
devnull = open(os.devnull, "w")
subprocess2.Popen(['vpython', UPLOADER] + sys.argv[1:],
stdout=devnull, stderr=devnull)
stdout=devnull,
stderr=devnull)
if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment