Skip to content

Commit

Permalink
bug 1463425 - Fix flake8/pep8 issue by hand in build/ r=gps
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: AZdcEWyVV6e
  • Loading branch information
sylvestre committed May 21, 2018
1 parent 9716032 commit b323297
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 80 deletions.
2 changes: 1 addition & 1 deletion build/build-clang/build-clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def delete(path):
else:
try:
os.unlink(path)
except:
except Exception:
pass


Expand Down
1 change: 1 addition & 0 deletions build/clang-plugin/ThirdPartyPaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json


def generate(output, tpp_txt):
"""
This file generates a ThirdPartyPaths.cpp file from the ThirdPartyPaths.txt
Expand Down
9 changes: 4 additions & 5 deletions build/clang-plugin/import_mozilla_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
import re
import sys
import glob
import shutil
Expand Down Expand Up @@ -129,20 +128,20 @@ def do_import(mozilla_path, clang_tidy_path):

def main():
if len(sys.argv) != 3:
print """\
print("""\
Usage: import_mozilla_checks.py <mozilla-clang-plugin-path> <clang-tidy-path>
Imports the Mozilla static analysis checks into a clang-tidy source tree.
"""
""")

return

mozilla_path = sys.argv[1]
if not os.path.isdir(mozilla_path):
print "Invalid path to mozilla clang plugin"
print("Invalid path to mozilla clang plugin")

clang_tidy_path = sys.argv[2]
if not os.path.isdir(mozilla_path):
print "Invalid path to clang-tidy source directory"
print("Invalid path to clang-tidy source directory")

do_import(mozilla_path, clang_tidy_path)

Expand Down
10 changes: 7 additions & 3 deletions build/compare-mozconfig/compare-mozconfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# originally from https://hg.mozilla.org/build/tools/file/4ab9c1a4e05b/scripts/release/compare-mozconfigs.py
# originally from https://hg.mozilla.org/build/tools/file/4ab9c1a4e05b/scripts/release/compare-mozconfigs.py # NOQA: E501

from __future__ import unicode_literals

Expand All @@ -28,14 +28,17 @@

log = logging.getLogger(__name__)


class ConfigError(Exception):
pass


def readConfig(configfile):
c = {}
execfile(configfile, c)
return c['whitelist']


def verify_mozconfigs(mozconfig_pair, nightly_mozconfig_pair, platform,
mozconfigWhitelist):
"""Compares mozconfig to nightly_mozconfig and compare to an optional
Expand All @@ -55,7 +58,8 @@ def verify_mozconfigs(mozconfig_pair, nightly_mozconfig_pair, platform,
success = True

diff_instance = difflib.Differ()
diff_result = diff_instance.compare(mozconfig_lines, nightly_mozconfig_lines)
diff_result = diff_instance.compare(
mozconfig_lines, nightly_mozconfig_lines)
diff_list = list(diff_result)

for line in diff_list:
Expand Down Expand Up @@ -98,6 +102,7 @@ def verify_mozconfigs(mozconfig_pair, nightly_mozconfig_pair, platform,
success = False
return success


def get_mozconfig(path):
"""Consumes a path and returns a list of lines from the mozconfig file."""
with open(path, 'rb') as fh:
Expand All @@ -114,7 +119,6 @@ def compare(topsrcdir):
def normalize_lines(lines):
return {l.strip() for l in lines}


for platform in PLATFORMS:
log.info('Comparing platform %s' % platform)

Expand Down
66 changes: 35 additions & 31 deletions build/mobile/remoteautomation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __init__(self, device, appName='', remoteProfile=None, remoteLog=None,
Automation.__init__(self)

# Set up what we need for the remote environment
def environment(self, env=None, xrePath=None, crashreporter=True, debugger=False, lsanPath=None, ubsanPath=None):
def environment(self, env=None, xrePath=None, crashreporter=True, debugger=False,
lsanPath=None, ubsanPath=None):
# Because we are running remote, we don't want to mimic the local env
# so no copying of os.environ
if env is None:
Expand Down Expand Up @@ -66,14 +67,15 @@ def environment(self, env=None, xrePath=None, crashreporter=True, debugger=False
# Set WebRTC logging in case it is not set yet.
# On Android, environment variables cannot contain ',' so the
# standard WebRTC setting for NSPR_LOG_MODULES is not available.
# env.setdefault('NSPR_LOG_MODULES', 'signaling:5,mtransport:5,datachannel:5,jsep:5,MediaPipelineFactory:5')
# env.setdefault('NSPR_LOG_MODULES', 'signaling:5,mtransport:5,datachannel:5,jsep:5,MediaPipelineFactory:5') # NOQA: E501
env.setdefault('R_LOG_LEVEL', '6')
env.setdefault('R_LOG_DESTINATION', 'stderr')
env.setdefault('R_LOG_VERBOSE', '1')

return env

def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo, symbolsPath, outputHandler=None):
def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo,
symbolsPath, outputHandler=None):
""" Wait for tests to finish.
If maxTime seconds elapse or no output is detected for timeout
seconds, kill the process and fail the test.
Expand All @@ -85,19 +87,20 @@ def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debugger

topActivity = self._device.get_top_activity(timeout=60)
if topActivity == proc.procName:
print "Browser unexpectedly found running. Killing..."
print("Browser unexpectedly found running. Killing...")
proc.kill(True)
if status == 1:
if maxTime:
print "TEST-UNEXPECTED-FAIL | %s | application ran for longer than " \
print("TEST-UNEXPECTED-FAIL | %s | application ran for longer than "
"allowed maximum time of %s seconds" % (
self.lastTestSeen, maxTime)
self.lastTestSeen, maxTime))
else:
print "TEST-UNEXPECTED-FAIL | %s | application ran for longer than " \
"allowed maximum time" % (self.lastTestSeen)
print("TEST-UNEXPECTED-FAIL | %s | application ran for longer than "
"allowed maximum time" % (self.lastTestSeen))
if status == 2:
print "TEST-UNEXPECTED-FAIL | %s | application timed out after %d seconds with no output" \
% (self.lastTestSeen, int(timeout))
print("TEST-UNEXPECTED-FAIL | %s | application timed out after %d seconds with"
"no output"
% (self.lastTestSeen, int(timeout)))

return status

Expand All @@ -109,7 +112,7 @@ def deleteANRs(self):
self._device.shell_output('echo > %s' % traces, root=True)
self._device.shell_output('chmod 666 %s' % traces, root=True)
except Exception as e:
print "Error deleting %s: %s" % (traces, str(e))
print("Error deleting %s: %s" % (traces, str(e)))

def checkForANRs(self):
traces = "/data/anr/traces.txt"
Expand All @@ -119,14 +122,14 @@ def checkForANRs(self):
if t:
stripped = t.strip()
if len(stripped) > 0:
print "Contents of %s:" % traces
print t
print("Contents of %s:" % traces)
print(t)
# Once reported, delete traces
self.deleteANRs()
except Exception as e:
print "Error pulling %s: %s" % (traces, str(e))
print("Error pulling %s: %s" % (traces, str(e)))
else:
print "%s not found" % traces
print("%s not found" % traces)

def deleteTombstones(self):
# delete any tombstone files from device
Expand Down Expand Up @@ -155,9 +158,9 @@ def checkForTombstones(self):
os.rename(f, newname)
break
else:
print "%s does not exist; tombstone check skipped" % remoteDir
print("%s does not exist; tombstone check skipped" % remoteDir)
else:
print "MOZ_UPLOAD_DIR not defined; tombstone check skipped"
print("MOZ_UPLOAD_DIR not defined; tombstone check skipped")

def checkForCrashes(self, directory, symbolsPath):
self.checkForANRs()
Expand All @@ -184,7 +187,8 @@ def checkForCrashes(self, directory, symbolsPath):
# minidumps directory is automatically created when Fennec
# (first) starts, so its lack of presence is a hint that
# something went wrong.
print "Automation Error: No crash directory (%s) found on remote device" % remoteCrashDir
print("Automation Error: No crash directory (%s) found on remote device" %
remoteCrashDir)
return True
self._device.pull(remoteCrashDir, dumpDir)

Expand All @@ -196,8 +200,8 @@ def checkForCrashes(self, directory, symbolsPath):
try:
shutil.rmtree(dumpDir)
except Exception as e:
print "WARNING: unable to remove directory %s: %s" % (
dumpDir, str(e))
print("WARNING: unable to remove directory %s: %s" % (
dumpDir, str(e)))
return crashed

def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
Expand All @@ -214,7 +218,7 @@ def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
self, app, debuggerInfo, profileDir, testURL, extraArgs)
try:
args.remove('-foreground')
except:
except Exception:
pass
return app, args

Expand Down Expand Up @@ -243,7 +247,7 @@ def __init__(self, device, cmd, stdout=None, env=None, cwd=None, app=None,
cmd = ' '.join(cmd)
self.procName = app
if not self.device.shell_bool(cmd):
print "remote_automation.py failed to launch %s" % cmd
print("remote_automation.py failed to launch %s" % cmd)
else:
args = cmd
if args[0] == app:
Expand Down Expand Up @@ -302,7 +306,7 @@ def read_stdout(self):
r"TEST-START \| ([^\s]*)", newLogContent)
if testStartFilenames:
self.lastTestSeen = testStartFilenames[-1]
print newLogContent
print(newLogContent)
return True

self.logBuffer += newLogContent
Expand Down Expand Up @@ -340,7 +344,7 @@ def read_stdout(self):
self.counts['fail'] += val
elif "Todo:" in line:
self.counts['todo'] += val
except:
except Exception:
pass

return True
Expand All @@ -359,7 +363,7 @@ def wait(self, timeout=None, noOutputTimeout=None):
timer = 0
noOutputTimer = 0
interval = 10
if timeout == None:
if timeout is None:
timeout = self.timeout
status = 0
top = self.procName
Expand Down Expand Up @@ -390,7 +394,7 @@ def wait(self, timeout=None, noOutputTimeout=None):
if not hasOutput:
top = self.device.get_top_activity(timeout=60)
if top is None:
print "Failed to get top activity, retrying, once..."
print("Failed to get top activity, retrying, once...")
top = self.device.get_top_activity(timeout=60)
# Flush anything added to stdout during the sleep
self.read_stdout()
Expand All @@ -408,27 +412,27 @@ def kill(self, stagedShutdown=False):
# Trigger an ANR report with "kill -3" (SIGQUIT)
try:
self.device.pkill(self.procName, sig=3, attempts=1)
except:
except: # NOQA: E722
pass
time.sleep(3)
# Trigger a breakpad dump with "kill -6" (SIGABRT)
try:
self.device.pkill(self.procName, sig=6, attempts=1)
except:
except: # NOQA: E722
pass
# Wait for process to end
retries = 0
while retries < 3:
if self.device.process_exist(self.procName):
print "%s still alive after SIGABRT: waiting..." % self.procName
print("%s still alive after SIGABRT: waiting..." % self.procName)
time.sleep(5)
else:
return
retries += 1
try:
self.device.pkill(self.procName, sig=9, attempts=1)
except:
print "%s still alive after SIGKILL!" % self.procName
except: # NOQA: E722
print("%s still alive after SIGKILL!" % self.procName)
if self.device.process_exist(self.procName):
self.device.stop_application(self.procName)
else:
Expand Down
26 changes: 14 additions & 12 deletions build/pgo/genpgocert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import shutil
import subprocess
import sys
import tempfile
import distutils

from mozbuild.base import MozbuildObject
Expand Down Expand Up @@ -81,7 +80,7 @@ def writeCertspecForServerLocations(fd):
if not customCertOption:
SAN.append(loc.host)

fd.write("issuer:printableString/CN=Temporary Certificate Authority/O=Mozilla Testing/OU=Profile Guided Optimization\n")
fd.write("issuer:printableString/CN=Temporary Certificate Authority/O=Mozilla Testing/OU=Profile Guided Optimization\n") # NOQA: E501
fd.write("subject:{}\n".format(SAN[0]))
fd.write("extension:subjectAlternativeName:{}\n".format(",".join(SAN)))

Expand All @@ -95,9 +94,7 @@ def constructCertDatabase(build, srcDir):
pykey = os.path.join(build.topsrcdir, "security", "manager", "ssl", "tests",
"unit", "pykey.py")

with NamedTemporaryFile() as pwfile, NamedTemporaryFile() as rndfile, TemporaryDirectory() as pemfolder:
pgoCAPath = os.path.join(srcDir, "pgoca.p12")

with NamedTemporaryFile() as pwfile, TemporaryDirectory() as pemfolder:
pwfile.write("\n")
pwfile.flush()

Expand Down Expand Up @@ -136,7 +133,9 @@ def constructCertDatabase(build, srcDir):
return status

status = runUtil(certutil, [
"-A", "-n", name, "-t", "P,,", "-i", pem, "-d", srcDir, "-f", pwfile.name])
"-A", "-n", name, "-t", "P,,", "-i", pem,
"-d", srcDir, "-f", pwfile.name
])
if status:
return status

Expand All @@ -145,8 +144,9 @@ def constructCertDatabase(build, srcDir):
name = parts[0]
key_type = parts[1]
if key_type not in ["ca", "client", "server"]:
raise Exception("{}: keyspec filenames must be of the form XXX.client.keyspec or XXX.ca.keyspec (key_type={})".format(
keyspec, key_type))
raise Exception("{}: keyspec filenames must be of the form XXX.client.keyspec "
"or XXX.ca.keyspec (key_type={})".format(
keyspec, key_type))
key_pem = os.path.join(pemfolder, "{}.key.pem".format(name))

print("Generating private key {} (pem={})".format(name, key_pem))
Expand All @@ -161,14 +161,16 @@ def constructCertDatabase(build, srcDir):

cert_pem = os.path.join(pemfolder, "{}.cert.pem".format(name))
if not os.path.exists(cert_pem):
raise Exception("There has to be a corresponding certificate named {} for the keyspec {}".format(
cert_pem, keyspec))
raise Exception("There has to be a corresponding certificate named {} for "
"the keyspec {}".format(
cert_pem, keyspec))

p12 = os.path.join(pemfolder, "{}.key.p12".format(name))
print("Converting private key {} to PKCS12 (p12={})".format(
key_pem, p12))
status = runUtil(openssl, ["pkcs12", "-export", "-inkey", key_pem, "-in",
cert_pem, "-name", name, "-out", p12, "-passout", "file:"+pwfile.name])
cert_pem, "-name", name, "-out", p12, "-passout",
"file:"+pwfile.name])
if status:
return status

Expand Down Expand Up @@ -197,5 +199,5 @@ def constructCertDatabase(build, srcDir):
certdir = os.path.join(build.topsrcdir, "build", "pgo", "certs")
certificateStatus = constructCertDatabase(build, certdir)
if certificateStatus:
print "TEST-UNEXPECTED-FAIL | SSL Server Certificate generation"
print("TEST-UNEXPECTED-FAIL | SSL Server Certificate generation")
sys.exit(certificateStatus)
Loading

0 comments on commit b323297

Please sign in to comment.