Commit 039777ef authored by Bruce Dawson's avatar Bruce Dawson Committed by Commit Bot

Get bisect-builds.py working under Python 3

This change fixes bisect-builds.py so that it runs under Python 3 (while
still supporting Python 2). The changes are:

- Don't import httplib (unsupported but also unused)
- Import urllib.request as urllib on Python 3
- Don't use 16L syntax for 16
- Use input instead of raw_input on Python 3
- Convert integer division results to integer
- Use is_alive instead of IsAlive
- Use except Exception _as_ e instead of a comma

The new code needs to use two conditionals with the rest of the fixes
still working fine in Python 2.

Bug: 941669
Change-Id: I34cd995225233f3f97008c7e07e0537b4683c48f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2498954
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/master@{#820882}
parent c088fba3
...@@ -80,7 +80,6 @@ CREDENTIAL_ERROR_MESSAGE = ('You are attempting to access protected data with ' ...@@ -80,7 +80,6 @@ CREDENTIAL_ERROR_MESSAGE = ('You are attempting to access protected data with '
############################################################################### ###############################################################################
import glob import glob
import httplib
import json import json
import optparse import optparse
import os import os
...@@ -91,11 +90,15 @@ import subprocess ...@@ -91,11 +90,15 @@ import subprocess
import sys import sys
import tempfile import tempfile
import threading import threading
import urllib
from distutils.version import LooseVersion from distutils.version import LooseVersion
from xml.etree import ElementTree from xml.etree import ElementTree
import zipfile import zipfile
if sys.version_info[0] == 3:
import urllib.request as urllib
else:
import urllib
class PathContext(object): class PathContext(object):
"""A PathContext is used to carry the information used to construct URLs and """A PathContext is used to carry the information used to construct URLs and
...@@ -525,7 +528,7 @@ def UnzipFilenameToDir(filename, directory): ...@@ -525,7 +528,7 @@ def UnzipFilenameToDir(filename, directory):
out.write(zf.read(name)) out.write(zf.read(name))
out.close() out.close()
# Set permissions. Permission info in external_attr is shifted 16 bits. # Set permissions. Permission info in external_attr is shifted 16 bits.
os.chmod(name, info.external_attr >> 16L) os.chmod(name, info.external_attr >> 16)
os.chdir(cwd) os.chdir(cwd)
...@@ -652,9 +655,12 @@ def AskIsGoodBuild(rev, exit_status, stdout, stderr): ...@@ -652,9 +655,12 @@ def AskIsGoodBuild(rev, exit_status, stdout, stderr):
print('Chrome exit_status: %d. Use s to see output' % exit_status) print('Chrome exit_status: %d. Use s to see output' % exit_status)
# Loop until we get a response that we can parse. # Loop until we get a response that we can parse.
while True: while True:
response = raw_input('Revision %s is ' prompt = ('Revision %s is '
'[(g)ood/(b)ad/(r)etry/(u)nknown/(s)tdout/(q)uit]: ' % '[(g)ood/(b)ad/(r)etry/(u)nknown/(s)tdout/(q)uit]: ' % str(rev))
str(rev)) if sys.version_info[0] == 3:
response = input(prompt)
else:
response = raw_input(prompt)
if response in ('g', 'b', 'r', 'u'): if response in ('g', 'b', 'r', 'u'):
return response return response
if response == 'q': if response == 'q':
...@@ -730,7 +736,7 @@ class DownloadJob(object): ...@@ -730,7 +736,7 @@ class DownloadJob(object):
print('Downloading revision %s...' % str(self.rev)) print('Downloading revision %s...' % str(self.rev))
self.progress_event.set() # Display progress of download. self.progress_event.set() # Display progress of download.
try: try:
while self.thread.isAlive(): while self.thread.is_alive():
# The parameter to join is needed to keep the main thread responsive to # The parameter to join is needed to keep the main thread responsive to
# signals. Without it, the program will not respond to interruptions. # signals. Without it, the program will not respond to interruptions.
self.thread.join(1) self.thread.join(1)
...@@ -748,8 +754,8 @@ def VerifyEndpoint(fetch, context, rev, profile, num_runs, command, try_args, ...@@ -748,8 +754,8 @@ def VerifyEndpoint(fetch, context, rev, profile, num_runs, command, try_args,
while answer == 'r': while answer == 'r':
(exit_status, stdout, stderr) = RunRevision( (exit_status, stdout, stderr) = RunRevision(
context, rev, fetch.zip_file, profile, num_runs, command, try_args) context, rev, fetch.zip_file, profile, num_runs, command, try_args)
answer = evaluate(rev, exit_status, stdout, stderr); answer = evaluate(rev, exit_status, stdout, stderr)
except Exception, e: except Exception as e:
print(e, file=sys.stderr) print(e, file=sys.stderr)
raise SystemExit raise SystemExit
if (answer != expected_answer): if (answer != expected_answer):
...@@ -815,7 +821,7 @@ def Bisect(context, ...@@ -815,7 +821,7 @@ def Bisect(context,
# Figure out our bookends and first pivot point; fetch the pivot revision. # Figure out our bookends and first pivot point; fetch the pivot revision.
minrev = 0 minrev = 0
maxrev = len(revlist) - 1 maxrev = len(revlist) - 1
pivot = maxrev / 2 pivot = int(maxrev / 2)
rev = revlist[pivot] rev = revlist[pivot]
fetch = DownloadJob(context, 'initial_fetch', rev, _GetDownloadPath(rev)) fetch = DownloadJob(context, 'initial_fetch', rev, _GetDownloadPath(rev))
fetch.Start() fetch.Start()
...@@ -886,7 +892,7 @@ def Bisect(context, ...@@ -886,7 +892,7 @@ def Bisect(context,
try: try:
(exit_status, stdout, stderr) = RunRevision( (exit_status, stdout, stderr) = RunRevision(
context, rev, fetch.zip_file, profile, num_runs, command, try_args) context, rev, fetch.zip_file, profile, num_runs, command, try_args)
except Exception, e: except Exception as e:
print(e, file=sys.stderr) print(e, file=sys.stderr)
# Call the evaluate function to see if the current revision is good or bad. # Call the evaluate function to see if the current revision is good or bad.
......
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