-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
101 lines (65 loc) · 1.97 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import subprocess
import os
import platform
from serviceHandler import getCurrentUser
from dotenv import load_dotenv
load_dotenv('.env')
RESERVED:list = ['root', getCurrentUser()] #exclude these names while processing usernames
def getLines(RAW):
return RAW.split('\n')
def getConfigs(lines):
tmpLines = []
flag = None
for line in lines:
if flag == False:
break
if flag == True:
tmpLines.append(line)
if "###SMBNAS###" in line:
flag = True
if "###/SMBNAS###" in line:
flag = False
tmpConfigLines = []
tmp = ""
for line in tmpLines:
tmp += line + '\n'
while "#END#" in tmp:
tmpConfigLines.append(tmp[tmp.find('#START#\n')+8: tmp.find('#END#')])
tmp = tmp[tmp.find('#END#\n')+6: ]
hostLine = []
for config in tmpConfigLines:
hostLine.append(config.split('\n'))
return hostLine
def parseHost(hosts):
hostConfig = {
"name": "HOST",
"comment" : "SAMPLE COMMENT"
}
def isUserName(name:str):
if name == None:
return False
name = name.strip()
for keyword in RESERVED:
if keyword.lower() == name.lower():
return False
return False if name == '' else True
def getCurrentUser():
if platform.system() != "Windows":
p = subprocess.Popen("whoami", stdout=subprocess.PIPE)
(output, err) = p.communicate()
return output.decode()
else:
return "Window_Mock"
#To check if all the required data available or not
def isRequiredDataAvailable(data, keys):
if data == None:
return None
length = len(keys)
operationCounter = 0
for item in data:
for key in keys:
if item.__str__() == key:
if item != None:
operationCounter += 1
break
return True if operationCounter == length else False