Skip to content

Commit

Permalink
Merge pull request #119 from ciromattia/4.x
Browse files Browse the repository at this point in the history
4.3.1
  • Loading branch information
AcidWeb committed Nov 24, 2014
2 parents b174534 + 94586fa commit bd665c3
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 58 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ The app relies and includes the following scripts:
* Added missing features to CLI version
* Other minor bug fixes

####4.3.1:
* Fixed Kindle Voyage profile
* Fixed some bugs in OS X release
* CLI version now support multiple input files at once
* Disabled MCB support
* Other minor tweaks

## KNOWN ISSUES
Please check [wiki page](https://github.com/ciromattia/kcc/wiki/Known-issues).

Expand Down
2 changes: 1 addition & 1 deletion kcc-c2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

__version__ = '4.3'
__version__ = '4.3.1'
__license__ = 'ISC'
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
__docformat__ = 'restructuredtext en'
Expand Down
2 changes: 1 addition & 1 deletion kcc-c2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

__version__ = '4.3'
__version__ = '4.3.1'
__license__ = 'ISC'
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
__docformat__ = 'restructuredtext en'
Expand Down
2 changes: 1 addition & 1 deletion kcc.iss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MyAppName "Kindle Comic Converter"
#define MyAppVersion "4.3"
#define MyAppVersion "4.3.1"
#define MyAppPublisher "Ciro Mattia Gonano, Paweł Jastrzębski"
#define MyAppURL "http://kcc.iosphe.re/"
#define MyAppExeName "KCC.exe"
Expand Down
9 changes: 3 additions & 6 deletions kcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

__version__ = '4.3'
__version__ = '4.3.1'
__license__ = 'ISC'
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
__docformat__ = 'restructuredtext en'
Expand Down Expand Up @@ -74,11 +74,8 @@
from kcc import KCC_gui

# OS specific PATH variable workarounds
if sys.platform.startswith('darwin'):
if 'RESOURCEPATH' in os.environ:
os.environ['PATH'] = os.environ['RESOURCEPATH'] + ':' + os.environ['PATH']
else:
os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/:' + os.environ['PATH']
if sys.platform.startswith('darwin') and 'RESOURCEPATH' not in os.environ:
os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/:' + os.environ['PATH']
elif sys.platform.startswith('win'):
if getattr(sys, 'frozen', False):
os.chdir(os.path.dirname(os.path.abspath(sys.executable)))
Expand Down
28 changes: 15 additions & 13 deletions kcc/KCC_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

__version__ = '4.3'
__version__ = '4.3.1'
__license__ = 'ISC'
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
__docformat__ = 'restructuredtext en'
Expand Down Expand Up @@ -111,24 +111,24 @@ def do_GET(self):
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes('<!DOCTYPE html>\n'
'<html lang="en">\n'
'<head><meta charset="utf-8">\n'
'<link href="' + GUI.webContent.favicon + '" rel="icon" type="image/x-icon" />\n'
'<title>Kindle Comic Converter</title>\n'
'</head>\n'
'<body>\n'
'<div style="text-align: center; font-size:25px">\n'
'<p style="font-size:50px">- <img style="vertical-align: middle" '
'alt="KCC Logo" src="' + GUI.webContent.logo + '" /> -</p>\n', 'UTF-8'))
'<html lang="en">\n'
'<head><meta charset="utf-8">\n'
'<link href="' + GUI.webContent.favicon + '" rel="icon" type="image/x-icon" />\n'
'<title>Kindle Comic Converter</title>\n'
'</head>\n'
'<body>\n'
'<div style="text-align: center; font-size:25px">\n'
'<p style="font-size:50px">- <img style="vertical-align: middle" '
'alt="KCC Logo" src="' + GUI.webContent.logo + '" /> -</p>\n', 'UTF-8'))
if len(GUI.completedWork) > 0 and not GUI.conversionAlive:
for key in sorted(GUI.completedWork.keys()):
self.wfile.write(bytes('<p><a href="' + key + '">' + key.split('.')[0] + '</a></p>\n', 'UTF-8'))
else:
self.wfile.write(bytes('<p style="font-weight: bold">No downloads are available.<br/>'
'Convert some files and refresh this page.</p>\n', 'UTF-8'))
self.wfile.write(bytes('</div>\n'
'</body>\n'
'</html>\n', 'UTF-8'))
'</body>\n'
'</html>\n', 'UTF-8'))
elif sendReply:
outputFile = GUI.completedWork[unquote(self.path[1:])]
fp = open(outputFile, 'rb')
Expand Down Expand Up @@ -1016,7 +1016,9 @@ def __init__(self, KCCAplication, KCCWindow):
self.listFontSize = 11
self.statusBarFontSize = 10
self.statusBarStyle = 'QLabel{padding-top:2px;padding-bottom:3px;}'
self.ProgressBar.setStyleSheet('QProgressBar{padding-top:5px;text-align:center;}')
self.ProgressBar.setStyleSheet('QProgressBar{font-size:13px;text-align:center;'
'border:2px solid grey;border-radius:5px;}'
'QProgressBar::chunk{background-color:steelblue;width:20px;}')
elif sys.platform.startswith('linux'):
self.listFontSize = 8
self.statusBarFontSize = 8
Expand Down
2 changes: 1 addition & 1 deletion kcc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '4.3'
__version__ = '4.3.1'
__license__ = 'ISC'
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
__docformat__ = 'restructuredtext en'
43 changes: 29 additions & 14 deletions kcc/comic2ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
# PERFORMANCE OF THIS SOFTWARE.
#

__version__ = '4.3'
__version__ = '4.3.1'
__license__ = 'ISC'
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
__docformat__ = 'restructuredtext en'

import os
import sys
from copy import copy
from glob import glob
from json import loads
from urllib.request import Request, urlopen
from re import split, sub, compile
from re import split, sub
from stat import S_IWRITE, S_IREAD, S_IEXEC
from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED
from tempfile import mkdtemp
Expand Down Expand Up @@ -55,12 +57,21 @@
def main(argv=None):
global options
parser = makeParser()
options, args = parser.parse_args(argv)
checkOptions()
if len(args) != 1:
optionstemplate, args = parser.parse_args(argv)
if len(args) == 0:
parser.print_help()
return
outputPath = makeBook(args[0])
sources = set([source for arg in args for source in glob(arg)])
outputPath = []
if len(sources) == 0:
print('No matching files found.')
return
for source in sources:
options = copy(optionstemplate)
checkOptions()
if len(sources) > 1:
print('\nWorking on ' + source)
outputPath = makeBook(source)
return outputPath


Expand Down Expand Up @@ -409,7 +420,7 @@ def buildEPUB(path, chapterNames, tomeNumber):
chapter = False
for afile in filenames:
filename = getImageFileName(afile)
if not '-kcc-hq' in filename[0]:
if '-kcc-hq' not in filename[0]:
filelist.append(buildHTML(dirpath, afile, os.path.join(dirpath, afile)))
if not chapter:
chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1]))
Expand Down Expand Up @@ -667,11 +678,12 @@ def getComicInfo(path, originalPath):
options.authors.sort()
else:
options.authors = ['KCC']
if len(xml.getElementsByTagName('ScanInformation')) != 0:
coverId = xml.getElementsByTagName('ScanInformation')[0].firstChild.nodeValue
coverId = compile('(MCD\\()(\\d+)(\\))').search(coverId)
if coverId:
options.remoteCovers = getCoversFromMCB(coverId.group(2))
# Disabled due to closure of MCD
# if len(xml.getElementsByTagName('ScanInformation')) != 0:
# coverId = xml.getElementsByTagName('ScanInformation')[0].firstChild.nodeValue
# coverId = compile('(MCD\\()(\\d+)(\\))').search(coverId)
# if coverId:
# options.remoteCovers = getCoversFromMCB(coverId.group(2))
os.remove(xmlPath)


Expand Down Expand Up @@ -1144,7 +1156,10 @@ def makeBook(source, qtGUI=None):
GUI.progressBarTick.emit('tick')
options.baseTitle = options.title
for tome in tomes:
if len(tomes) > 1:
if len(tomes) > 9:
tomeNumber += 1
options.title = options.baseTitle + ' [' + str(tomeNumber).zfill(2) + '/' + str(len(tomes)).zfill(2) + ']'
elif len(tomes) > 1:
tomeNumber += 1
options.title = options.baseTitle + ' [' + str(tomeNumber) + '/' + str(len(tomes)) + ']'
if options.format == 'CBZ':
Expand Down Expand Up @@ -1254,4 +1269,4 @@ def makeMOBI(work, qtGUI=None):
makeMOBIWorkerPool.apply_async(func=makeMOBIWorker, args=(i, ), callback=makeMOBIWorkerTick)
makeMOBIWorkerPool.close()
makeMOBIWorkerPool.join()
return makeMOBIWorkerOutput
return makeMOBIWorkerOutput
2 changes: 1 addition & 1 deletion kcc/comic2panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# PERFORMANCE OF THIS SOFTWARE.
#

__version__ = '4.3'
__version__ = '4.3.1'
__license__ = 'ISC'
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
__docformat__ = 'restructuredtext en'
Expand Down
4 changes: 2 additions & 2 deletions kcc/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__version__ = '4.3'
__version__ = '4.3.1'
__license__ = 'ISC'
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
__docformat__ = 'restructuredtext en'
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self):
'K345': ("Kindle", (600, 800), Palette16, 1.8, (900, 1200)),
'KDX': ("Kindle DX/DXG", (824, 1000), Palette16, 1.8, (1236, 1500)),
'KPW': ("Kindle Paperwhite", (758, 1024), Palette16, 1.8, (1137, 1536)),
'KV': ("Kindle Voyage", (1080, 1440), Palette16, 1.8, (1620, 2160)),
'KV': ("Kindle Voyage", (1072, 1448), Palette16, 1.8, (1608, 2172)),
'KFHD': ("K. Fire HD", (800, 1280), PalleteNull, 1.0, (1200, 1920)),
'KFHDX': ("K. Fire HDX", (1200, 1920), PalleteNull, 1.0, (1800, 2880)),
'KFHDX8': ("K. Fire HDX 8.9", (1600, 2560), PalleteNull, 1.0, (2400, 3840)),
Expand Down
79 changes: 64 additions & 15 deletions kcc/rarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ def close(self):
#: args for testrar()
TEST_ARGS = ('t', '-idq')

#
# Allow use of tool that is not compatible with unrar.
#
# By default use 'bsdtar' which is 'tar' program that
# sits on top of libarchive.
#
# Problems with libarchive RAR backend:
# - Does not support solid archives.
# - Does not support password-protected archives.
#

ALT_TOOL = 'bsdtar'
ALT_OPEN_ARGS = ('-x', '--to-stdout', '-f')
ALT_EXTRACT_ARGS = ('-x', '-f')
ALT_TEST_ARGS = ('-t', '-f')
ALT_CHECK_ARGS = ('--help',)

#: whether to speed up decompression by using tmp archive
USE_EXTRACT_HACK = 1

Expand Down Expand Up @@ -336,6 +353,8 @@ class RarUnknownError(RarExecError):
"""Unknown exit code"""
class RarSignalExit(RarExecError):
"""Unrar exited with signal"""
class RarCannotExec(RarExecError):
"""Executable not found."""


def is_rarfile(xfile):
Expand Down Expand Up @@ -693,10 +712,7 @@ def testrar(self):
"""Let 'unrar' test the archive.
"""
cmd = [UNRAR_TOOL] + list(TEST_ARGS)
if self._password is not None:
cmd.append('-p' + self._password)
else:
cmd.append('-p-')
add_password_arg(cmd, self._password)
cmd.append(self.rarfile)
p = custom_popen(cmd)
output = p.communicate()[0]
Expand Down Expand Up @@ -1172,8 +1188,7 @@ def _open_unrar(self, rarfile, inf, psw = None, tmpfile = None):
if is_filelike(rarfile):
raise ValueError("Cannot use unrar directly on memory buffer")
cmd = [UNRAR_TOOL] + list(OPEN_ARGS)
if psw is not None:
cmd.append("-p" + psw)
add_password_arg(cmd, psw)
cmd.append(rarfile)

# not giving filename avoids encoding related problems
Expand Down Expand Up @@ -1205,10 +1220,7 @@ def _extract(self, fnlist, path=None, psw=None):

# pasoword
psw = psw or self._password
if psw is not None:
cmd.append('-p' + psw)
else:
cmd.append('-p-')
add_password_arg(cmd, psw)

# rar file
cmd.append(self.rarfile)
Expand Down Expand Up @@ -1830,10 +1842,7 @@ def rar_decompress(vers, meth, data, declen=0, flags=0, crc=0, psw=None, salt=No
tmpf.close()

cmd = [UNRAR_TOOL] + list(OPEN_ARGS)
if psw is not None and (flags & RAR_FILE_PASSWORD):
cmd.append("-p" + psw)
else:
cmd.append("-p-")
add_password_arg(cmd, psw, (flags & RAR_FILE_PASSWORD))
cmd.append(tmpname)

p = custom_popen(cmd)
Expand Down Expand Up @@ -1902,10 +1911,27 @@ def custom_popen(cmd):
except OSError:
ex = sys.exc_info()[1]
if ex.errno == errno.ENOENT:
raise RarExecError("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
raise
return p

def custom_check(cmd, ignore_retcode=False):
"""Run command, collect output, raise error if needed."""
p = custom_popen(cmd)
out, err = p.communicate()
if p.returncode and not ignore_retcode:
raise RarExecError("Check-run failed")
return out

def add_password_arg(cmd, psw, required=False):
"""Append password switch to commandline."""
if UNRAR_TOOL == ALT_TOOL:
return
if psw is not None:
cmd.append('-p' + psw)
else:
cmd.append('-p-')

def check_returncode(p, out):
"""Raise exception according to unrar exit code"""

Expand All @@ -1920,6 +1946,8 @@ def check_returncode(p, out):
RarWarning, RarFatalError, RarCRCError, RarLockedArchiveError,
RarWriteError, RarOpenError, RarUserError, RarMemoryError,
RarCreateError, RarNoFilesError] # codes from rar.txt
if UNRAR_TOOL == ALT_TOOL:
errmap = [None]
if code > 0 and code < len(errmap):
exc = errmap[code]
elif code == 255:
Expand All @@ -1936,3 +1964,24 @@ def check_returncode(p, out):
msg = "%s [%d]" % (exc.__doc__, p.returncode)

raise exc(msg)

#
# Check if unrar works
#

try:
# does UNRAR_TOOL work?
custom_check([UNRAR_TOOL], True)
except RarCannotExec:
try:
# does ALT_TOOL work?
custom_check([ALT_TOOL] + list(ALT_CHECK_ARGS), True)
# replace config
UNRAR_TOOL = ALT_TOOL
OPEN_ARGS = ALT_OPEN_ARGS
EXTRACT_ARGS = ALT_EXTRACT_ARGS
TEST_ARGS = ALT_TEST_ARGS
except RarCannotExec:
# no usable tool, only uncompressed archives work
pass

Loading

0 comments on commit bd665c3

Please sign in to comment.