-
Notifications
You must be signed in to change notification settings - Fork 2
/
show_tables.py
279 lines (187 loc) · 10.9 KB
/
show_tables.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
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
from datenbank import *
from datetime import datetime
from prettytable import PrettyTable
class ShowTables:
"""Class ShowTables. Shows the following objects: Jewels, Blobs, Files, skipped Files
ShowTables shows objectes with different verbose levels.
Level 0: short display
Level 1: medium display
Level 2: full display
"""
def __init__(self):
"""Constructor"""
self.daten = Datenbank()
def generate_jewel_table(self, jewels:list[Jewel], verbose_level:int) ->None:
"""Adjusts the jewel table to the verbose level and prints the table.
Args:
jewels: a list of jewel objects that should be displayed
verbose_level: the level that should be displayed"""
table = PrettyTable()
if verbose_level == 0:
table.field_names = ["Jewel ID","Monitoring startdate","Source of the jewel"]
table.align["Jewel ID"] = "l"
for jewel in jewels:
startdate = str(jewel.monitoring_Startdate).split(" ")[0]
table.add_row([str(jewel.id), startdate, jewel.jewelSource])
elif verbose_level == 1:
table.field_names = ["Jewel ID","Monitoring startdate","Source of the jewel", "Fullbackup source"]
table.align["Jewel ID"] = "l"
for jewel in jewels:
startdate = str(jewel.monitoring_Startdate).split(".")[0]
table.add_row([str(jewel.id), startdate, jewel.jewelSource, jewel.fullbackup_source])
else:
table.field_names = ["Jewel ID", "Comment", "Monitoring startdate", "Source of the jewel", "Device name", "Fullbackup source"]
table.align["Jewel ID"] = "l"
for jewel in jewels:
startdate = str(jewel.monitoring_Startdate)
table.add_row([str(jewel.id),jewel.comment, startdate, jewel.jewelSource, jewel.device_name, jewel.fullbackup_source])
print(table)
def generate_file_table(self, files:list[File], verbose_level:int) ->None:
"""Adjusts the file table to the verbose level and prints the table.
Args:
files: a list of file objects that should be displayed
verbose_level: the level that should be displayed"""
table = PrettyTable()
table.field_names = ["File ID","File versions","File birth"]
table.align["File ID"] = "l"
for file in files:
birth = str(file.birth)
if verbose_level == 0: birth = birth.split(" ")[0]
elif verbose_level == 1: birth = birth.split(".")[0]
table.add_row([file.id, str(len(file.blobs)), birth])
print(table)
def generate_blobs_table(self, blobs:list[Blob], verbose_level:int) ->None:
"""Adjusts the blob table to the verbose level and prints the table.
Args:
blobs: a list of blob objects that should be displayed
verbose_level: the level that should be displayed"""
table = PrettyTable()
if verbose_level == 0:
table.field_names = ["Blob ID"," File version", "Creationdate", "File ID", "Origin name"]
table.align["Blob ID"] = "l"
for blob in blobs:
table.add_row([str(blob.id), str(blob.number), str(blob.creationDate).split(" ")[0], blob.iD_File, blob.origin_name ])
print(table)
elif verbose_level == 1:
secound_table = PrettyTable()
table.field_names = ["Blob ID"," File version", "File size in kB", "Creationdate", "File ID"]
table.align["Blob ID"] = "l"
secound_table.field_names = ["Blob ID", "Origin name", " Source path", "Store destination "]
secound_table.align["Blob ID"] = "l"
for blob in blobs:
table.add_row([str(blob.id), str(blob.number), str(blob.fileSize), str(blob.creationDate).split(".")[0], blob.iD_File])
secound_table.add_row([str(blob.id), blob.origin_name, blob.source_path, blob.store_destination])
print("-------------------------the first part of the blob table.----------------------------------------------------------\n")
print(table)
print("\n-------------------------the secound part of the blob table.---------------------------------------------------------\n")
print(secound_table)
else:
secound_table = PrettyTable()
table.field_names = ["Blob ID"," File version", "Hash", "File size in kB", "Creationdate", "Modifydate"]
table.align["Blob ID"] = "l"
secound_table.field_names = ["Blob ID", "File ID", "Origin name", " Source path", "Store destination "]
secound_table.align["Blob ID"] = "l"
for blob in blobs:
table.add_row([str(blob.id), str(blob.number), blob.hash, str(blob.fileSize), str(blob.creationDate), str(blob.modify)])
secound_table.add_row([str(blob.id), blob.iD_File, blob.origin_name, blob.source_path, blob.store_destination])
print("-------------------------the first part of the blob table.----------------------------------------------------------\n")
print(table)
print("\n-------------------------the secound part of the blob table.---------------------------------------------------------\n")
print(secound_table)
def generate_sfiles_table(self, sfiles:tuple, verbose_level:int) ->None:
"""Adjusts the blob table to the verbose level and prints the table.
Args:
sfiles: a list of sfiles as tuple that should be displayed
verbose_level: the level that should be displayed"""
table = PrettyTable()
if verbose_level == 0:
table.field_names = ["File id","Jewel id", "UUID", "Occurance date"]
table.align["File id"] = "l"
for file in sfiles:
table.add_row([str(file[0]), str(file[1]), file[2], str(file[3]).split(" ")[0]])
elif verbose_level == 1:
table.field_names = ["File id","Jewel id", "UUID", "Occurance date", "Reason", "Connected file to jewel"]
table.align["File id"] = "l"
for file in sfiles:
table.add_row([str(file[0]), str(file[1]), file[2], str(file[3]).split(".")[0], file[5], str(file[7])])
else:
table.field_names = ["File id","Jewel id", "UUID", "Occurance date", "Hash", "Reason", "Additional information", "Connected file to jewel"]
table.align["File id"] = "l"
for file in sfiles:
table.add_row([str(file[0]), str(file[1]), file[2], str(file[3]), file[4], file[5], file[6], str(file[7])])
print(table)
def show_all_jewels(self, verbose_level:int) ->None:
"""Prints all jewels in table form in the console
Args:
verbose_level: the level that should be displayed"""
jewels = self.daten.get_all_Jewels()
if jewels is not None:
self.generate_jewel_table(jewels, verbose_level)
else:
print("\nNo jewels have been created by the user yet")
def show_all_files(self, verbose_level:int) ->None:
"""Prints all files in table form in the console
Args:
verbose_level: the level that should be displayed"""
files = self.daten.get_all_Files()
if files is not None:
self.generate_file_table(files, verbose_level)
else:
print("\nNo files have been created by the user yet")
def show_all_blobs(self, verbose_level:int) ->None:
"""Prints all blobs in table form in the console
Args:
verbose_level: the level that should be displayed"""
blobs = self.daten.get_all_Blobs()
if blobs is not None:
self.generate_blobs_table(blobs, verbose_level)
else: print("\nNo blobs have been created by the user yet")
def show_jewel_via_id(self,id:int, verbose_level:int) ->None:
"""Prints a jewel and all associated files in table form in the console
Args:
id: the id of the jewel that should be displayed
verbose_level: the level that should be displayed"""
jewel = self.daten.get_Jewel_via_id(id)
if jewel is not None:
self.generate_jewel_table([jewel], verbose_level)
files = self.daten.get_Files_via_jewel_id(id)
self.generate_file_table(files, verbose_level)
else: print("\nThere is no jewel with the id " + str(id))
def show_file_via_id (self,id:str, verbose_level:int) ->None:
"""Prints a file and all associated blobs in table form in the console
Args:
id: the id of the file that should be displayed
verbose_level: the level that should be displayed"""
file = self.daten.get_File_via_id(id)
if file is not None:
self.generate_file_table([file], verbose_level)
self.generate_blobs_table(file.blobs, verbose_level)
else: print("\nThere is no file with the id " + str(id))
def show_blob_via_id (self,id:int, verbose_level:int) ->None:
"""Prints a blob in table form in the console
Args:
id: the id of the blob that should be displayed
verbose_level: the level that should be displayed"""
blob = self.daten.get_Blob_via_id(id)
if blob is not None:
self.generate_blobs_table([blob], verbose_level)
else:
print("\nThere is no blob with the id " + str(id))
def show_all_skipped_Files(self, verbose_level:int) ->None:
"""Prints all skipped files in table form in the console
Args:
verbose_level: the level that should be displayed"""
files = self.daten.get_all_skipped_files()
if files is not None:
self.generate_sfiles_table(files, verbose_level)
else:
print("\nThere are no skipped files yet")
def show_skipped_file_via_id(self,id:int, verbose_level:int) ->None:
"""Prints a skipped file in table form in the console
Args:
id: the id of the skipped file that should be displayed
verbose_level: the level that should be displayed"""
fi = self.daten.get_skipped_file_via_id(id)
if fi is not None:
self.generate_sfiles_table([fi], verbose_level)
else: print("\nThere is no skipped file with the id " + str(id))