mirror of
https://github.com/ciromattia/kcc
synced 2026-05-31 19:53:10 +00:00
Improved KindleGen detection
This commit is contained in:
+45
-30
@@ -931,15 +931,19 @@ class KCCGUI(KCC_ui.Ui_KCC):
|
|||||||
self.addMessage('Target resolution is not set!', 'error')
|
self.addMessage('Target resolution is not set!', 'error')
|
||||||
self.needClean = True
|
self.needClean = True
|
||||||
return
|
return
|
||||||
if str(GUI.FormatBox.currentText()) == 'MOBI' and not GUI.KindleGen:
|
if str(GUI.FormatBox.currentText()) == 'MOBI' and not self.KindleGen:
|
||||||
self.addMessage('Cannot find <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211">'
|
self.detectKindleGen()
|
||||||
'<b>KindleGen</b></a>! MOBI conversion is not possible!', 'error')
|
if not self.KindleGen:
|
||||||
if sys.platform.startswith('win'):
|
GUI.JobList.clear()
|
||||||
self.addMessage('Download it and place EXE in KCC directory.', 'error')
|
self.addMessage('Cannot find <a href="http://www.amazon.com/gp/feature.html'
|
||||||
else:
|
'?ie=UTF8&docId=1000765211"><b>KindleGen</b></a>!'
|
||||||
self.addMessage('Download it, and place executable in /usr/local/bin directory.', 'error')
|
' MOBI conversion is unavailable!', 'error')
|
||||||
self.needClean = True
|
if sys.platform.startswith('win'):
|
||||||
return
|
self.addMessage('Download it and place EXE in KCC directory.', 'error')
|
||||||
|
else:
|
||||||
|
self.addMessage('Download it and place executable in /usr/local/bin directory.', 'error')
|
||||||
|
self.needClean = True
|
||||||
|
return
|
||||||
self.worker.start()
|
self.worker.start()
|
||||||
|
|
||||||
def hideProgressBar(self):
|
def hideProgressBar(self):
|
||||||
@@ -1027,6 +1031,36 @@ class KCCGUI(KCC_ui.Ui_KCC):
|
|||||||
self.saveSettings(None)
|
self.saveSettings(None)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
def detectKindleGen(self, startup=False):
|
||||||
|
if not sys.platform.startswith('win'):
|
||||||
|
try:
|
||||||
|
os.chmod('/usr/local/bin/kindlegen', 0o755)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
kindleGenExitCode = Popen('kindlegen -locale en', stdout=PIPE, stderr=STDOUT, shell=True)
|
||||||
|
if kindleGenExitCode.wait() == 0:
|
||||||
|
self.KindleGen = True
|
||||||
|
versionCheck = Popen('kindlegen -locale en', stdout=PIPE, stderr=STDOUT, shell=True)
|
||||||
|
for line in versionCheck.stdout:
|
||||||
|
line = line.decode("utf-8")
|
||||||
|
if 'Amazon kindlegen' in line:
|
||||||
|
versionCheck = line.split('V')[1].split(' ')[0]
|
||||||
|
if tuple(map(int, (versionCheck.split(".")))) < tuple(map(int, ('2.9'.split(".")))):
|
||||||
|
self.addMessage('Your <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&docId='
|
||||||
|
'1000765211">KindleGen</a> is outdated! Creating MOBI might fail.'
|
||||||
|
' Please update <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&docId='
|
||||||
|
'1000765211">KindleGen</a> from Amazon\'s website.', 'warning')
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.KindleGen = False
|
||||||
|
if startup:
|
||||||
|
self.addMessage('Cannot find <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211">'
|
||||||
|
'<b>KindleGen</b></a>! MOBI conversion will be unavailable!', 'error')
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
self.addMessage('Download it and place EXE in KCC directory.', 'error')
|
||||||
|
else:
|
||||||
|
self.addMessage('Download it and place executable in /usr/local/bin directory.', 'error')
|
||||||
|
|
||||||
# noinspection PyArgumentList
|
# noinspection PyArgumentList
|
||||||
def __init__(self, KCCAplication, KCCWindow):
|
def __init__(self, KCCAplication, KCCWindow):
|
||||||
global APP, MW, GUI
|
global APP, MW, GUI
|
||||||
@@ -1057,6 +1091,7 @@ class KCCGUI(KCC_ui.Ui_KCC):
|
|||||||
self.tray = SystemTrayIcon()
|
self.tray = SystemTrayIcon()
|
||||||
self.conversionAlive = False
|
self.conversionAlive = False
|
||||||
self.needClean = True
|
self.needClean = True
|
||||||
|
self.KindleGen = False
|
||||||
self.GammaValue = 1.0
|
self.GammaValue = 1.0
|
||||||
self.completedWork = {}
|
self.completedWork = {}
|
||||||
self.targetDirectory = ''
|
self.targetDirectory = ''
|
||||||
@@ -1158,27 +1193,6 @@ class KCCGUI(KCC_ui.Ui_KCC):
|
|||||||
self.addMessage('Since you are new user of <b>KCC</b> please see few '
|
self.addMessage('Since you are new user of <b>KCC</b> please see few '
|
||||||
'<a href="https://github.com/ciromattia/kcc/wiki/Important-tips">important tips</a>.',
|
'<a href="https://github.com/ciromattia/kcc/wiki/Important-tips">important tips</a>.',
|
||||||
'info')
|
'info')
|
||||||
if not sys.platform.startswith('win'):
|
|
||||||
try:
|
|
||||||
os.chmod('/usr/local/bin/kindlegen', 0o755)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
kindleGenExitCode = Popen('kindlegen -locale en', stdout=PIPE, stderr=STDOUT, shell=True)
|
|
||||||
if kindleGenExitCode.wait() == 0:
|
|
||||||
self.KindleGen = True
|
|
||||||
versionCheck = Popen('kindlegen -locale en', stdout=PIPE, stderr=STDOUT, shell=True)
|
|
||||||
for line in versionCheck.stdout:
|
|
||||||
line = line.decode("utf-8")
|
|
||||||
if 'Amazon kindlegen' in line:
|
|
||||||
versionCheck = line.split('V')[1].split(' ')[0]
|
|
||||||
if tuple(map(int, (versionCheck.split(".")))) < tuple(map(int, ('2.9'.split(".")))):
|
|
||||||
self.addMessage('Your <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&docId='
|
|
||||||
'1000765211">kindlegen</a> is outdated! Creating MOBI might fail.'
|
|
||||||
' Please update <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&docId='
|
|
||||||
'1000765211">kindlegen</a> from Amazon\'s website.', 'warning')
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
self.KindleGen = False
|
|
||||||
rarExitCode = Popen('unrar', stdout=PIPE, stderr=STDOUT, shell=True)
|
rarExitCode = Popen('unrar', stdout=PIPE, stderr=STDOUT, shell=True)
|
||||||
rarExitCode = rarExitCode.wait()
|
rarExitCode = rarExitCode.wait()
|
||||||
if rarExitCode == 0 or rarExitCode == 7:
|
if rarExitCode == 0 or rarExitCode == 7:
|
||||||
@@ -1195,6 +1209,7 @@ class KCCGUI(KCC_ui.Ui_KCC):
|
|||||||
self.sevenza = False
|
self.sevenza = False
|
||||||
self.addMessage('Cannot find <a href="http://www.7-zip.org/download.html">7za</a>!'
|
self.addMessage('Cannot find <a href="http://www.7-zip.org/download.html">7za</a>!'
|
||||||
' Processing of CB7/7Z files will be disabled.', 'warning')
|
' Processing of CB7/7Z files will be disabled.', 'warning')
|
||||||
|
self.detectKindleGen(True)
|
||||||
|
|
||||||
APP.messageFromOtherInstance.connect(self.handleMessage)
|
APP.messageFromOtherInstance.connect(self.handleMessage)
|
||||||
GUI.BasicModeButton.clicked.connect(self.modeBasic)
|
GUI.BasicModeButton.clicked.connect(self.modeBasic)
|
||||||
|
|||||||
Reference in New Issue
Block a user