-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatastructures.py
More file actions
319 lines (247 loc) · 5.88 KB
/
datastructures.py
File metadata and controls
319 lines (247 loc) · 5.88 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# Copyright (c) 2024 FileCloud. All Rights Reserved.
from dataclasses import dataclass
from enum import Enum
from typing import Optional
from xml.etree.ElementTree import Element
class EntryType(Enum):
dir = "dir"
file = "file"
class SharedType(Enum):
notshared = ""
private = "private"
public = "public"
class AclEntryType(Enum):
user = "user"
ETag = str
@dataclass
class FileListEntry:
path: str
dirpath: str
name: str
ext: str
fullsize: int
modified: str
type: EntryType
fullfilename: str
size: str
modifiedepoch: str
isroot: bool
locked: bool
isshared: SharedType
modifiedepochutc: str
canupload: bool
candownload: bool
canrename: bool
cansetacls: bool
isshareable: bool
issyncable: bool
isdatasyncable: bool
etag: ETag
@dataclass
class FileVersion:
versionnumber: str
size: str
how: str
createdon: str
createdby: str
filename: str
sizeinbytes: str
fileid: str
@dataclass
class FileList:
parentpath: str
total: int
realpath: str
isroot: bool
entries: list[FileListEntry]
class SortBy(Enum):
NAME = "name"
DATE = "date"
SIZE = "size"
class SortDir(Enum):
ascending = 1
descending = -1
@dataclass
class FCShare:
shareid: str
sharename: str
sharelocation: str
allowpublicaccess: bool
allowpublicupload: bool
allowpublicviewonly: bool
allowpublicuploadonly: bool
maxdownloads: Optional[int] = 0
validityperiod: Optional[str] = ""
@dataclass
class FCShareUser:
name: str
read: bool
write: bool
sync: bool
share: bool
download: bool
disallowdelete: bool
allowmanage: bool
def __getitem__(self, key):
if key in self.__annotations__:
return getattr(self, key)
else:
raise KeyError(f"'{key}' property not found")
@dataclass
class FCShareGroup:
groupid: str
groupname: str
read: bool
write: bool
sync: bool
share: bool
download: bool
disallowdelete: bool
def __getitem__(self, key):
if key in self.__annotations__:
return getattr(self, key)
else:
raise KeyError(f"'{key}' property not found")
@dataclass
class ShareActivity:
shareid: str
path: str
name: str
actioncode: int
who: str
when: str
how: str
ip: str
@dataclass
class FileLockInfo:
locked: bool
readlock: bool
lockedby: str
@dataclass
class TeamFolderInfo:
teamfolderenabled: bool
teamfolderaccount: str
aclenabled: bool
teamfolderpath: Optional[str] = None
@dataclass
class NetworkFolderInfo:
networkfoldername: str
@dataclass
class RMCClient:
rid: str
remote_client_id: str
remote_client_disp_name: str
remote_client_last_login: str
remote_client_status: int
remote_client_status_message: str
@dataclass
class PolicyUser:
username: str
status: int
adminstatus: int
authtype: int
@dataclass
class SyncFolder:
path: str
update_version: int
@dataclass
class SyncDeltaItem:
type: EntryType
size: int
modified: str
name: str
fullpath: str
flags: str
isdeleted: bool
updateversion: int
candownload: bool
canupload: bool
canrename: bool
@dataclass
class AclPermissions:
has_read_permission: bool
has_write_permssion: bool
has_share_permission: bool
has_delete_permission: bool
def __init__(self, fromstr: str):
self.has_read_permission = False
self.has_write_permssion = False
self.has_share_permission = False
self.has_delete_permission = False
if "R" in fromstr:
self.has_read_permission = True
if "W" in fromstr:
self.has_write_permssion = True
if "S" in fromstr:
self.has_share_permission = True
if "D" in fromstr:
self.has_delete_permission = True
def __str__(self) -> str:
ret = ""
if self.has_read_permission:
ret += "R"
if self.has_write_permssion:
ret += "W"
if self.has_share_permission:
ret += "S"
if self.has_delete_permission:
ret += "D"
return ret
class UserStatus(Enum):
GUEST = 0
FULL = 1
DISABLED = 2
EXTERNAL = 3
UNKNOWN = -1
@dataclass
class PolicyEntry:
"""Represents a policy entry"""
policyid: str
policyname: str
class PolicyList:
"""Convienience class represents policy list"""
entries: list[PolicyEntry] = []
def first(self) -> PolicyEntry | None:
if len(self.entries) >= 1:
return self.entries[0]
return None
def __iter__(self):
return iter(self.entries)
def __init__(self, a_response: Element):
""""""
self._set_entries(response=a_response)
def _set_entries(self, response: Element):
a_list = list(response)
for elem in a_list:
if elem.tag != "policy":
continue
an_entry = PolicyEntry(
policyid=list(elem)[0].text, # type:ignore
policyname=list(elem)[1].text, # type:ignore
)
self.entries.append(an_entry)
class ServerSettings:
"""Convienience class represents server settings"""
entries: dict = {}
def __iter__(self):
return iter(self.entries)
def __init__(self, a_response: Element):
""""""
self._set_entries(response=a_response)
def _set_entries(self, response: Element):
a_list = list(response)
for elem in a_list:
if elem.tag != "setting":
continue
self.entries[list(elem)[0].text] = list(elem)[1].text
@dataclass
class StorageRootDetails:
type: str
name: str
@dataclass
class ProfileSettings:
nickname: str
peerid: str
displayname: str
email: str
isremote: int