mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-02-23 08:09:48 -05:00
Merge pull request #324 from mistydemeo/mdfind
CLI: improve Chrome finding on Mac
This commit is contained in:
commit
69d682beb9
@ -29,6 +29,7 @@ import requests
|
|||||||
import doublethink
|
import doublethink
|
||||||
import signal
|
import signal
|
||||||
import string
|
import string
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@ -126,8 +127,36 @@ def configure_logging(args):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def suggest_default_chrome_exe():
|
def mdfind(identifier):
|
||||||
# mac os x application executable paths
|
try:
|
||||||
|
result = subprocess.check_output(
|
||||||
|
["mdfind", f"kMDItemCFBundleIdentifier == {identifier}"], text=True
|
||||||
|
)
|
||||||
|
# Just treat any errors as "couldn't find app"
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if result:
|
||||||
|
return result.rstrip("\n")
|
||||||
|
|
||||||
|
|
||||||
|
def suggest_default_chrome_exe_mac():
|
||||||
|
path = None
|
||||||
|
# Try Chromium first, then Chrome
|
||||||
|
result = mdfind("org.chromium.Chromium")
|
||||||
|
if result is not None:
|
||||||
|
path = f"{result}/Contents/MacOS/Chromium"
|
||||||
|
|
||||||
|
result = mdfind("com.google.Chrome")
|
||||||
|
if result is not None:
|
||||||
|
path = f"{result}/Contents/MacOS/Google Chrome"
|
||||||
|
|
||||||
|
if path is not None and os.path.exists(path):
|
||||||
|
return path
|
||||||
|
|
||||||
|
# Fall back to default paths if mdfind couldn't find it
|
||||||
|
# (mdfind might fail to find them even in their default paths
|
||||||
|
# if the system has Spotlight disabled.)
|
||||||
for path in [
|
for path in [
|
||||||
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
||||||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
||||||
@ -135,6 +164,14 @@ def suggest_default_chrome_exe():
|
|||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def suggest_default_chrome_exe():
|
||||||
|
# First ask mdfind, which lets us find it in non-default paths
|
||||||
|
if sys.platform == "darwin":
|
||||||
|
path = suggest_default_chrome_exe_mac()
|
||||||
|
if path is not None:
|
||||||
|
return path
|
||||||
|
|
||||||
# "chromium-browser" is the executable on ubuntu trusty
|
# "chromium-browser" is the executable on ubuntu trusty
|
||||||
# https://github.com/internetarchive/brozzler/pull/6/files uses "chromium"
|
# https://github.com/internetarchive/brozzler/pull/6/files uses "chromium"
|
||||||
# google chrome executable names taken from these packages:
|
# google chrome executable names taken from these packages:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user