| 21 | |
| 22 | |
| 23 | class multiDeleteThread(QThread): |
| 24 | delete_process_signal = pyqtSignal(int) |
| 25 | delete_complete_signal = pyqtSignal() |
| 26 | |
| 27 | def __init__(self, fileList, dirList, share_thread_arr, direct_delete=False): |
| 28 | super(multiDeleteThread, self).__init__() |
| 29 | self.fileList = fileList |
| 30 | self.dirList = dirList |
| 31 | self.share_thread_arr = share_thread_arr |
| 32 | self.direct_delete = direct_delete |
| 33 | |
| 34 | def _delete_path(self, file_path): |
| 35 | if is_protected_file(file_path): |
| 36 | logging.info("Skip protected file: %s", file_path) |
| 37 | return |
| 38 | try: |
| 39 | if self.direct_delete: |
| 40 | if os.path.isdir(file_path): |
| 41 | shutil.rmtree(file_path) |
| 42 | else: |
| 43 | os.remove(file_path) |
| 44 | else: |
| 45 | send2trash(file_path) |
| 46 | except Exception: |
| 47 | logging.exception("Failed to delete path: %s", file_path) |
| 48 | |
| 49 | def _emit_progress(self): |
| 50 | qmut.lock() |
| 51 | try: |
| 52 | self.share_thread_arr[0] += 1 |
| 53 | self.delete_process_signal.emit(self.share_thread_arr[0]) |
| 54 | finally: |
| 55 | qmut.unlock() |
| 56 | |
| 57 | def run(self): |
| 58 | try: |
| 59 | for file_path in self.fileList: |
| 60 | self._delete_path(file_path) |
| 61 | self._emit_progress() |
| 62 | |
| 63 | for file_path in self.dirList: |
| 64 | self._delete_path(file_path) |
| 65 | self._emit_progress() |
| 66 | |
| 67 | logging.info("Delete thread finished") |
| 68 | finally: |
| 69 | self.delete_complete_signal.emit() |
no outgoing calls
no test coverage detected