2022-12-10 22:19:57 +01:00
|
|
|
from .Paths import Paths
|
2022-12-10 22:03:29 +01:00
|
|
|
|
2022-12-10 22:19:57 +01:00
|
|
|
class Cleanup():
|
|
|
|
def __init__(self,cli,paths):
|
2022-12-10 22:03:29 +01:00
|
|
|
self.cli = cli
|
2022-12-10 22:19:57 +01:00
|
|
|
self.paths = paths
|
2022-12-09 20:10:12 +01:00
|
|
|
|
|
|
|
def getAllFilePaths(self,file_type):
|
2022-12-10 21:20:26 +01:00
|
|
|
all_file_paths = [
|
2022-12-10 22:19:57 +01:00
|
|
|
self.paths.getGroupFilesFolderPath(file_type),
|
2022-12-11 14:55:17 +01:00
|
|
|
self.paths.getUserFilesPath(file_type),
|
2022-12-10 22:19:57 +01:00
|
|
|
self.paths.getAccumulatedFilePath(file_type)
|
2022-12-09 20:10:12 +01:00
|
|
|
]
|
2022-12-10 22:19:57 +01:00
|
|
|
if file_type == Paths.TYPE_DECRYPTED:
|
|
|
|
all_file_paths.append(self.paths.getDecryptedMainDataStandartFolder())
|
2022-12-10 21:20:26 +01:00
|
|
|
return all_file_paths
|
2022-12-09 17:32:02 +01:00
|
|
|
|
|
|
|
def deleteAllFilesInFolder(self,folder_path):
|
|
|
|
try:
|
2022-12-10 22:03:29 +01:00
|
|
|
self.cli.executeCommand('rm -r ' + folder_path + '*')
|
2022-12-10 21:20:26 +01:00
|
|
|
except Exception as error:
|
2022-12-11 18:46:32 +01:00
|
|
|
pass
|
2022-12-09 17:32:02 +01:00
|
|
|
|
2022-12-10 13:22:09 +01:00
|
|
|
def cleanupFiles(self,file_type):
|
2022-12-09 20:10:12 +01:00
|
|
|
for folder_path in self.getAllFilePaths(file_type):
|
2022-12-09 17:32:02 +01:00
|
|
|
self.deleteAllFilesInFolder(folder_path)
|
2022-12-09 18:16:31 +01:00
|
|
|
|
|
|
|
def cleanupForUser(self,user):
|
2022-12-09 23:43:28 +01:00
|
|
|
try:
|
2022-12-10 22:19:57 +01:00
|
|
|
self.cli.executeCommand('find "' + self.paths.getDataFolderPath(Paths.TYPE_ENCRYPTED) + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v')
|
2022-12-10 21:20:26 +01:00
|
|
|
except Exception as error:
|
2022-12-11 18:46:32 +01:00
|
|
|
pass
|
2022-12-10 22:19:57 +01:00
|
|
|
self.cleanupFiles(Paths.TYPE_DECRYPTED)
|
2022-12-09 17:32:02 +01:00
|
|
|
|
2022-12-09 13:08:07 +01:00
|
|
|
def deleteAll(self):
|
2022-12-10 22:19:57 +01:00
|
|
|
self.cleanupFiles(Paths.TYPE_ENCRYPTED)
|
|
|
|
self.cleanupFiles(Paths.TYPE_DECRYPTED)
|