Skip to content

Commit

Permalink
browser.py code cleanup
Browse files Browse the repository at this point in the history
Some code cleanup that was recommended in #13185
  • Loading branch information
Cactusmachete authored and jgraham committed Nov 9, 2018
1 parent 726725b commit 7c568fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 44 deletions.
69 changes: 25 additions & 44 deletions tools/wpt/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,28 @@ class Firefox(Browser):
platform_ini = "browsers/firefox/platform.ini"
requirements = "requirements_firefox.txt"

def platform_string_geckodriver(self):
platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "macos"
}.get(uname[0])
platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "macos"
}.get(uname[0])

application_name = {
"stable": "Firefox.app",
"beta": "Firefox.app",
"nightly": "Firefox Nightly.app"
}

if platform is None:
def platform_string_geckodriver(self):
if self.platform is None:
raise ValueError("Unable to construct a valid Geckodriver package name for current platform")

if platform in ("linux", "win"):
if self.platform in ("linux", "win"):
bits = "64" if uname[4] == "x86_64" else "32"
else:
bits = ""

return "%s%s" % (platform, bits)
return "%s%s" % (self.platform, bits)

def install(self, dest=None, channel="nightly"):
"""Install Firefox."""
Expand All @@ -102,24 +108,14 @@ def install(self, dest=None, channel="nightly"):
"beta": "latest-beta",
"nightly": "latest"
}
application_name = {
"stable": "Firefox.app",
"beta": "Firefox.app",
"nightly": "Firefox Nightly.app"
}

if channel not in branch:
raise ValueError("Unrecognised release channel: %s" % channel)

from mozdownload import FactoryScraper
import mozinstall

platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "mac"
}.get(uname[0])

if platform is None:
if self.platform is None:
raise ValueError("Unable to construct a valid Firefox package name for current platform")

if dest is None:
Expand All @@ -136,10 +132,10 @@ def install(self, dest=None, channel="nightly"):
try:
mozinstall.install(filename, dest)
except mozinstall.mozinstall.InstallError:
if platform == "mac" and os.path.exists(os.path.join(dest, application_name[channel])):
if self.platform == "macos" and os.path.exists(os.path.join(dest, self.application_name.get(channel, "Firefox Nightly.app"))):
# mozinstall will fail if nightly is already installed in the venv because
# mac installation uses shutil.copy_tree
mozinstall.uninstall(os.path.join(dest, application_name[channel]))
mozinstall.uninstall(os.path.join(dest, self.application_name.get(channel, "Firefox Nightly.app")))
mozinstall.install(filename, dest)
else:
raise
Expand All @@ -150,46 +146,31 @@ def install(self, dest=None, channel="nightly"):
def find_binary_path(self,path=None, channel="nightly"):
"""Looks for the firefox binary in the virtual environment"""

platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "mac"
}.get(uname[0])

application_name = {
"stable": "Firefox.app",
"beta": "Firefox.app",
"nightly": "Firefox Nightly.app"
}.get(channel)

if path is None:
#os.getcwd() doesn't include the venv path
path = os.path.join(os.getcwd(), "_venv", "browsers", channel)

binary = None

if platform == "linux":
if self.platform == "linux":
binary = find_executable("firefox", os.path.join(path, "firefox"))
elif platform == "win":
elif self.platform == "win":
import mozinstall
binary = mozinstall.get_binary(path, "firefox")
elif platform == "mac":
binary = find_executable("firefox", os.path.join(path, application_name,
elif self.platform == "macos":
binary = find_executable("firefox", os.path.join(path, self.application_name.get(channel, "Firefox Nightly.app"),
"Contents", "MacOS"))

return binary

def find_binary(self, venv_path=None, channel=None):
def find_binary(self, venv_path=None, channel="nightly"):
if venv_path is None:
venv_path = os.path.join(os.getcwd(), "_venv")

if channel is None:
channel = "nightly"

path = os.path.join(venv_path, "browsers", channel)
binary = self.find_binary_path(path, channel)

if not binary and uname[0] == "Darwin":
if not binary and self.platform == "macos":
macpaths = ["/Applications/Firefox Nightly.app/Contents/MacOS",
os.path.expanduser("~/Applications/Firefox Nightly.app/Contents/MacOS"),
"/Applications/Firefox Developer Edition.app/Contents/MacOS",
Expand Down
1 change: 1 addition & 0 deletions tools/wpt/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class Firefox(BrowserSetup):
def setup_kwargs(self, kwargs):
if kwargs["binary"] is None:
if kwargs["browser_channel"] is None:
kwargs["browser_channel"] = "nightly"
logger.info("No browser channel specified. Running nightly instead.")

binary = self.browser.find_binary(self.venv.path,
Expand Down

0 comments on commit 7c568fd

Please sign in to comment.