-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatcher.py
69 lines (61 loc) · 2.06 KB
/
patcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import io
import re
import sys
import stat
import time
import string
import random
import zipfile
import tempfile
import os.path
import platform
import subprocess
import threading
from packaging.version import parse as LooseVersion # جایگزین distutils.version
import urllib.request
IS_POSIX = sys.platform.startswith(("darwin", "cygwin", "linux"))
class Patcher(object):
# اینجا بقیه کدهای کلاس Patcher قرار میگیرد
# نیازی به کپی کردن کامل آن نیست، چون فقط قصد داریم تغییرات لازم را نشان دهیم
def __init__(self):
pass
def find_chrome_executable():
"""
Finds the chrome, chrome beta, chrome canary, chromium executable
Returns:
Optional[str]: Chrome path
"""
candidates = set()
if IS_POSIX:
for item in os.environ.get("PATH").split(os.pathsep):
for subitem in (
"google-chrome",
"chromium",
"chromium-browser",
"chrome",
"google-chrome-stable",
):
candidates.add(os.path.join(item, subitem))
if "darwin" in sys.platform:
candidates.update(
[
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"/Applications/Chromium.app/Contents/MacOS/Chromium",
]
)
else:
for item in map(
os.environ.get,
("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA", "PROGRAMW6432"),
):
if item is not None:
for subitem in (
"Google/Chrome/Application",
"Google/Chrome Beta/Application",
"Google/Chrome Canary/Application",
):
candidates.add(os.path.join(item, subitem, "chrome.exe"))
for candidate in candidates:
if os.path.exists(candidate) and os.access(candidate, os.X_OK):
return os.path.normpath(candidate)