-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_remover.py
More file actions
35 lines (28 loc) · 1.06 KB
/
file_remover.py
File metadata and controls
35 lines (28 loc) · 1.06 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
import logging
from PySide6.QtCore import Signal
from send2trash import send2trash
from interruptible_class import InterruptibleClass
class FileRemover(InterruptibleClass):
file_removed = Signal(str)
def __init__(self):
# QObject.__init__(self)
InterruptibleClass.__init__(self, parent=self)
def remove_files(self, files):
if logging.getLogger().isEnabledFor(logging.DEBUG):
logging.debug(f"Removing files: {files}")
else:
logging.info("Removing files")
for file in files:
if self.need_to_interrupt():
return
try:
send2trash(file)
logging.debug(f"File removed: {file}")
except Exception as e:
logging.error(f"Failed to remove file: {file}, Error: {e}")
finally:
self.file_removed.emit(file)
if logging.getLogger().isEnabledFor(logging.DEBUG):
logging.debug(f"Removing files {files} done")
else:
logging.info("Removing files done")