-
Notifications
You must be signed in to change notification settings - Fork 11
/
ChromeREPLHelpers.py
55 lines (38 loc) · 1.73 KB
/
ChromeREPLHelpers.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
import sublime
import os
import psutil
import requests
zombie_message_shown = False
def get_chrome_path():
settings = sublime.load_settings('ChromeREPL.sublime-settings')
return os.path.realpath(settings.get('path')[sublime.platform()])
def get_chrome_process():
user_basename = os.path.basename(get_chrome_path())
is_linux_chrome = sublime.platform() == 'linux' and user_basename != 'chromium-browser'
try:
basenames_to_check = (['chrome', 'google-chrome'] if is_linux_chrome else [user_basename])
for process in psutil.process_iter(attrs=['exe', 'status']):
basename_matches = ('exe' in process.info and process.info['exe'] is not None and
os.path.basename(process.info['exe']) in basenames_to_check)
is_zombie = 'status' in process.info and process.info['status'] == 'zombie'
if basename_matches and not is_zombie:
return process
except Exception as e:
global zombie_message_shown
if not zombie_message_shown:
sublime.error_message("You may have a zombie Chrome Process. If Chrome won't start, try killing it or restarting your machine")
zombie_message_shown = True
return None
def is_chrome_running():
return get_chrome_process() is not None
def request_json_from_chrome():
settings = sublime.load_settings('ChromeREPL.sublime-settings')
try:
return requests.get('http://{}:{}/json'.format(settings.get('hostname'),
settings.get('port')))
except requests.exceptions.ConnectionError as e:
return None
def is_remote_debugging_enabled():
return request_json_from_chrome() is not None
def is_chrome_running_with_remote_debugging():
return is_chrome_running() and is_remote_debugging_enabled()