-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
179 lines (122 loc) · 4.05 KB
/
helper.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
def getArrDict(data):
ret = []
for item in data:
ret.append(item.getBlock())
return ret
class User:
def __init__(self, username):
self.name = username
def disp(self):
print(f'{self.name}')
def getBlock(self):
return self.name
class Admin:
def __init__(self, block:dict):
self.sharedUsers:User = []
self.name = ''
self.writable = False
if block != None:
self.name = '' if block.get('name') == None else block.get('name')
self.writable = False if block.get('writable') != True else True
for item in block.get('sharedUsers'):
self.sharedUsers.append(User(item))
def disp(self):
print(f'_______\nAdmin - {self.name}')
print(f'_______\nShared Users - ')
for item in self.sharedUsers:
item.disp()
def getBlock(self):
return {
"name" : self.name,
"writable" : self.writable,
"sharedUsers" : getArrDict(self.sharedUsers)
}
class Host:
def __init__(self, block:dict):
self.name = block.get('name')
self.path = block.get('path')
self.writable = block.get('writable')
self.public = block.get('public')
self.admin = Admin(block.get('admin'))
self.validUsers:User = []
for item in block.get('validUsers'):
self.validUsers.append(User(item))
def disp(self):
print(f'_______\nHost Name - {self.name}')
print(f'Path - {self.path}')
print(f'Writable - {self.writable}')
print(f'Public - {self.public}')
print(f'Valid user - ')
for item in self.validUsers:
item.disp()
def getBlock(self):
return {
"name": self.name,
"path": self.path,
"writable": self.writable,
"public": self.public,
"admin": self.admin.getBlock(),
"validUsers": getArrDict(self.validUsers)
}
class Server:
def __init__(self, block:dict):
self.id = block.get('_id')
self.name = block.get('name')
self.address = block.get('address')
self.autoStart = block.get('autoStart')
self.hosts:Host = []
for item in block.get('hosts'):
self.hosts.append(Host(item))
def disp(self):
print(f'\n\n-----\nServer Name - {self.name}')
print(f'Address - {self.address}')
print(f'Auto start - {self.autoStart}')
print(f'Hosts - ')
for item in self.hosts:
item.disp()
def getHost(self, hostName:str):
for host in self.hosts:
if host.name == hostName:
return host
return None
def getBlock(self):
return {
"name": self.name,
"id": str(self.id),
"address": self.address,
"autoStart": self.autoStart,
"hosts": getArrDict(self.hosts)
}
class Nas:
def __init__(self, block):
self.servers = []
for item in block:
self.servers.append(Server(item))
def disp(self):
for item in self.servers:
item.disp()
def getServer(self, serverName:str):
for server in self.servers:
if server.name == serverName:
return server
def getHost(self, serverName:str, hostName:str):
server:Server = self.getServer(serverName)
if server == None:
return None
else:
return server.getHost(hostName)
def getUsers(self, serverName:str, hostName:str):
server:Server = self.getServer(serverName)
if server == None:
return None
else:
host:Host = server.getHost(hostName)
if host == None:
return None
else:
return host.validUsers
def getBlock(self):
ret = []
for s in self.servers:
ret.append(s.getBlock())
return getArrDict(self.servers)