-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
executable file
·48 lines (32 loc) · 1.17 KB
/
utils.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
import json
import os
import inspect
from http.client import RemoteDisconnected
from urllib.error import URLError
from urllib.request import urlopen
import mango
def loadJSON(file_name):
# print('Load file : '+file_name)
file = open(file_name)
data = json.loads(file.read())
return data
def getMangoFolder():
return os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
def getAbsoluteFilePath(filename: str):
return os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), filename)
def getPluginsPath():
return os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), mango.get_plugins_folder())
def getConfigFile(file_name):
global config_path
return os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), mango.get_config_folder(), file_name)
def internet_reachable():
google_server = 'http://216.58.192.142'
try:
urlopen(google_server, timeout=4)
return True
except URLError:
return False
except RemoteDisconnected:
return False
except ConnectionResetError:
return False