-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceHandler.py
49 lines (38 loc) 路 1.32 KB
/
serviceHandler.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
import subprocess
from os import system
import platform
def isAlive():
return True if isProcessAlive("smbd") else False
def wake():
if platform.system() != 'Windows':
ret = system("sudo systemctl start smbd")
return True if ret == 0 else False
else:
return True
def kill():
if platform.system() != 'Windows':
ret = system("sudo systemctl stop smbd")
return True if ret == 0 else False
else:
return True
def isProcessAlive(processName:str):
if platform.system() != 'Windows':
p = subprocess.Popen(["systemctl", "is-active", processName], stdout=subprocess.PIPE)
(output, err) = p.communicate()
output:str = output.decode('utf-8')
return True if output.strip().lower() == "active" else False
else:
return True
def getCurrentUser():
if platform.system() != 'Windows':
p = subprocess.Popen('grep -Po \'^sudo.+:\K.*$\' /etc/group', stdout=subprocess.PIPE, shell = True)
(output, err) = p.communicate()
return output.decode('utf-8').strip()
else:
return "Windows Mock User"
def changeOwner(path):
if platform.system() != 'Windows':
exit_code = system((f'chown {getCurrentUser()} \"{path}\"'))
return True if exit_code == 0 else False
else:
return True