1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-21 05:31:49 +00:00

Improved cleanup (close #58)

This commit is contained in:
Paweł Jastrzębski
2013-08-15 10:05:03 +02:00
parent 6b002a8475
commit e32018e8f6
3 changed files with 16 additions and 7 deletions

View File

@@ -228,7 +228,9 @@ class WorkerThread(QtCore.QThread):
continue continue
if not self.conversionAlive: if not self.conversionAlive:
for item in outputPath: for item in outputPath:
if os.path.exists(item):
os.remove(item) os.remove(item)
if os.path.exists(item.replace('.epub', '.mobi')):
os.remove(item.replace('.epub', '.mobi')) os.remove(item.replace('.epub', '.mobi'))
self.clean() self.clean()
return return
@@ -532,8 +534,15 @@ class Ui_KCC(object):
def hideProgressBar(self): def hideProgressBar(self):
GUI.ProgressBar.hide() GUI.ProgressBar.hide()
# noinspection PyUnusedLocal
def saveSettings(self, event): def saveSettings(self, event):
if self.conversionAlive:
GUI.ConvertButton.setEnabled(False)
self.addMessage('Process will be interrupted. Please wait.', 'warning')
self.conversionAlive = False
self.worker.sync()
event.ignore()
if not GUI.ConvertButton.isEnabled():
event.ignore()
self.settings.setValue('lastPath', self.lastPath) self.settings.setValue('lastPath', self.lastPath)
self.settings.setValue('lastDevice', GUI.DeviceBox.currentIndex()) self.settings.setValue('lastDevice', GUI.DeviceBox.currentIndex())
self.settings.setValue('currentFormat', GUI.FormatBox.currentIndex()) self.settings.setValue('currentFormat', GUI.FormatBox.currentIndex())

View File

@@ -364,7 +364,7 @@ def dirImgProcess(path):
pass pass
if not GUI.conversionAlive: if not GUI.conversionAlive:
pool.terminate() pool.terminate()
rmtree(path) rmtree(os.path.join(path, '..', '..'))
raise UserWarning("Conversion interrupted.") raise UserWarning("Conversion interrupted.")
GUI.emit(QtCore.SIGNAL("progressBarTick")) GUI.emit(QtCore.SIGNAL("progressBarTick"))
pool.join() pool.join()
@@ -372,7 +372,7 @@ def dirImgProcess(path):
try: try:
splitpages = splitpages.get() splitpages = splitpages.get()
except: except:
rmtree(path) rmtree(os.path.join(path, '..', '..'))
raise RuntimeError("One of workers crashed. Cause: " + str(sys.exc_info()[1])) raise RuntimeError("One of workers crashed. Cause: " + str(sys.exc_info()[1]))
splitpages = filter(None, splitpages) splitpages = filter(None, splitpages)
splitpages.sort() splitpages.sort()
@@ -382,7 +382,7 @@ def dirImgProcess(path):
pagenumbermodifier += 1 pagenumbermodifier += 1
pagenumbermodifier += 1 pagenumbermodifier += 1
else: else:
rmtree(path) rmtree(os.path.join(path, '..', '..'))
raise UserWarning("Source directory is empty.") raise UserWarning("Source directory is empty.")

View File

@@ -255,7 +255,7 @@ def main(argv=None, qtGUI=None):
try: try:
workers.get() workers.get()
except: except:
rmtree(options.targetDir) rmtree(options.targetDir, True)
raise RuntimeError("One of workers crashed. Cause: " + str(sys.exc_info()[1])) raise RuntimeError("One of workers crashed. Cause: " + str(sys.exc_info()[1]))
if GUI: if GUI:
GUI.emit(QtCore.SIGNAL("progressBarTick"), 1) GUI.emit(QtCore.SIGNAL("progressBarTick"), 1)