-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
83 lines (63 loc) · 1.99 KB
/
util.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import subprocess
import os
import logger
import time
from sys import platform
from win32com.client import Dispatch
TYPE_LINUX = 0
TYPE_MACOS = 1
TYPE_WINDOWS = 2
os_type = None
def is_revssh_running():
path = get_home_folder() + "/start.revssh"
if os.path.exists(path):
f = open(path, "r")
output = f.read().replace("\n", "").replace("\r", "")
f.close()
if not output or float(output) < (time.time() - 11 * 60):
return False
else:
return True
else:
return False
def get_os_type():
global os_type
if os_type is None:
if platform == "linux" or platform == "linux2":
os_type = TYPE_LINUX
elif platform == "darwin":
os_type = TYPE_MACOS
elif platform == "win32":
os_type = TYPE_WINDOWS
return os_type
def get_home_folder():
if get_os_type() is TYPE_LINUX or get_os_type() is TYPE_LINUX:
return "~"
else:
return "$HOME"
def get_username():
output = subprocess.Popen("whoami", stdout=subprocess.PIPE)
return str(output.communicate()[0]).replace("\n", "").replace("\r", "")
def get_hostname():
return
def reboot():
logger.info("Rebooting system")
output = subprocess.Popen("reboot", stdout=subprocess.PIPE)
return output.returncode == 0
def execute_command(command):
output = subprocess.Popen(command, stdout=subprocess.PIPE)
return output.communicate()[0].replace("\n", "").replace("\r", "")
def create_shortcut(path, target='', wdir='', icon=''):
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = wdir
if icon == '':
pass
else:
shortcut.IconLocation = icon
shortcut.save()
def install_ssh():
if get_os_type() == TYPE_WINDOWS:
execute_command('powershell -command "& {&\'Get-WindowsCapability -Online | Where-Object Name -like '
'\'OpenSSH*\'\'}" ')