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
This diff is collapsed.
......@@ -19,30 +19,30 @@ VERSION = 2
def LoadConfig():
if os.path.isfile(CONFIG):
with open(CONFIG, 'rb') as f:
config = json.load(f)
if config['version'] == VERSION:
config['countdown'] = max(0, config['countdown'] - 1)
return config
if os.path.isfile(CONFIG):
with open(CONFIG, 'rb') as f:
config = json.load(f)
if config['version'] == VERSION:
config['countdown'] = max(0, config['countdown'] - 1)
return config
return {
'is-googler': ninjalog_uploader.IsGoogler(
'chromium-build-stats.appspot.com'),
'countdown': 10,
'version': VERSION,
}
return {
'is-googler':
ninjalog_uploader.IsGoogler('chromium-build-stats.appspot.com'),
'countdown': 10,
'version': VERSION,
}
def SaveConfig(config):
with open(CONFIG, 'wb') as f:
json.dump(config, f)
with open(CONFIG, 'wb') as f:
json.dump(config, f)
def ShowMessage(countdown):
whitelisted = '\n'.join([' * %s' % config for config in
ninjalog_uploader.WHITELISTED_CONFIGS])
print("""
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.
......@@ -73,46 +73,47 @@ You can find a more detailed explanation in
def main():
config = LoadConfig()
if len(sys.argv) == 2 and sys.argv[1] == 'opt-in':
config['opt-in'] = True
config['countdown'] = 0
SaveConfig(config)
print('ninjalog upload is opted in.')
return 0
if len(sys.argv) == 2 and sys.argv[1] == 'opt-out':
config['opt-in'] = False
SaveConfig(config)
print('ninjalog upload is opted out.')
return 0
if 'opt-in' in config and not config['opt-in']:
# Upload is opted out.
return 0
if not config.get("is-googler", False):
# Not googler.
return 0
if config.get("countdown", 0) > 0:
# Need to show message.
ShowMessage(config["countdown"])
# Only save config if something has meaningfully changed.
SaveConfig(config)
return 0
if len(sys.argv) == 1:
# dry-run for debugging.
print("upload ninjalog dry-run")
return 0
# Run upload script without wait.
devnull = open(os.devnull, "w")
subprocess2.Popen(['vpython', UPLOADER] + sys.argv[1:],
stdout=devnull, stderr=devnull)
config = LoadConfig()
if len(sys.argv) == 2 and sys.argv[1] == 'opt-in':
config['opt-in'] = True
config['countdown'] = 0
SaveConfig(config)
print('ninjalog upload is opted in.')
return 0
if len(sys.argv) == 2 and sys.argv[1] == 'opt-out':
config['opt-in'] = False
SaveConfig(config)
print('ninjalog upload is opted out.')
return 0
if 'opt-in' in config and not config['opt-in']:
# Upload is opted out.
return 0
if not config.get("is-googler", False):
# Not googler.
return 0
if config.get("countdown", 0) > 0:
# Need to show message.
ShowMessage(config["countdown"])
# Only save config if something has meaningfully changed.
SaveConfig(config)
return 0
if len(sys.argv) == 1:
# dry-run for debugging.
print("upload ninjalog dry-run")
return 0
# Run upload script without wait.
devnull = open(os.devnull, "w")
subprocess2.Popen(['vpython', UPLOADER] + sys.argv[1:],
stdout=devnull,
stderr=devnull)
if __name__ == '__main__':
sys.exit(main())
sys.exit(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