-
Notifications
You must be signed in to change notification settings - Fork 1
/
cross_platform.py
43 lines (38 loc) · 1.16 KB
/
cross_platform.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
import sys
import subprocess
IS_LINUX = IS_WINDOWS = IS_MAC = False
PLATFORM = None
if sys.platform in ['linux', 'linux2']:
PLATFORM = "linux"
IS_LINUX = True
elif sys.platform in ['Windows', 'win32', 'cygwin']:
PLATFORM = "windows"
IS_WINDOWS = True
elif sys.platform in ['Mac', 'darwin', 'os2', 'os2emx']:
PLATFORM = "mac"
IS_MAC = True
else:
print("sys.platform=%s is unknown. Please report." % sys.platform)
import os
def get_cmd_output(cmd, temp_file=None, **kwargs):
"""
:param cmd:
:return:
"""
if temp_file:
os.system('%s > %s' % (cmd, temp_file))
with open(temp_file) as f:
return f.read()
if isinstance(cmd, str):
cmd = cmd.split(' ')
return subprocess.check_output(cmd, **kwargs).decode('utf-8')[:-1]
if IS_WINDOWS:
from win10toast import ToastNotifier
def notify(message, topic=''):
if IS_LINUX:
os.system('notify-send "%s" "%s"' % (topic, message))
elif IS_MAC:
os.system("osascript -e 'display notification \"%s\" sound name \"Submarine\"'" % message)
elif IS_WINDOWS:
toaster = ToastNotifier()
toaster.show_toast(topic, message)