From dd90ab590831f3c609957fcf5d55e0fa2fc85205 Mon Sep 17 00:00:00 2001 From: Ciro Mattia Gonano Date: Mon, 17 Dec 2012 10:45:24 +0100 Subject: [PATCH] Start to work on py2exe/py2app ready code. --- .../Contents/Resources/Scripts/main.scpt | Bin 29152 -> 29074 bytes README.md | 17 ++- kcc.py | 44 +++++++ kcc/comic2ebook.py | 107 ++++++++++-------- setup.py | 25 ++-- 5 files changed, 123 insertions(+), 70 deletions(-) create mode 100644 kcc.py diff --git a/KindleComicConverter.app/Contents/Resources/Scripts/main.scpt b/KindleComicConverter.app/Contents/Resources/Scripts/main.scpt index 48dfd962d76bedba7ebbb5d29b46de0f222253ca..ac3bb4171f25af2881fb44be92755f6bfbc49056 100644 GIT binary patch delta 55 zcmaFxm~ql$#tpv<7!xL66qB4RT4*cJP{NSPPz)rk_?QkeFm7aeAjtH9fdeKyd4HiI E04-J#zW@LL delta 133 zcmbRAnDN15#tpv<7{exC6qB4RT4 **WARNING:** at the moment the droplet *ALWAYS* uses the **KHD** profile (*Kindle Paperwhite*). @@ -52,12 +51,12 @@ and installed in `/usr/local/bin/` - 1.20 - Comic optimizations! Split pages not target-oriented (landscape with portrait target or portrait with landscape target), add palette and other image optimizations from Mangle. WARNING: PIL is required for all image mangling! + - 2.00 - GUI! AppleScript is gone and Tk is used to provide cross-platform GUI support. ## TODO - Add gracefully exit for CBR if no rarfile.py and no unrar executable are found - Improve error reporting - Recurse into dirtree for multiple comics - - Create a GUI to allow user control more options - Support pages extraction from PDF files ## COPYRIGHT diff --git a/kcc.py b/kcc.py new file mode 100644 index 0000000..5837651 --- /dev/null +++ b/kcc.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# +# Copyright (c) 2012 Ciro Mattia Gonano +# +# Permission to use, copy, modify, and/or distribute this software for +# any purpose with or without fee is hereby granted, provided that the +# above copyright notice and this permission notice appear in all +# copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA +# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +# Changelog +# 1.00 - Initial version +# 1.10 - Added support for CBZ/CBR files +# 1.11 - Added support for ZIP/RAR extensions +# 1.20 - Comic optimizations! Split pages not target-oriented (landscape +# with portrait target or portrait with landscape target), add palette +# and other image optimizations from Mangle. +# WARNING: PIL is required for all image mangling! +# +# Todo: +# - Add gracefully exit for CBR if no rarfile.py and no unrar +# executable are found +# - Improve error reporting +# - recurse into dirtree for multiple comics + +__version__ = '1.30' + +import sys +from kcc import comic2ebook + +if __name__ == "__main__": + print ('kcc v%(__version__)s. ' + 'Written 2012 by Ciro Mattia Gonano.' % globals()) + for arg in sys.argv[1:]: + comic2ebook.main(['','KHD',arg]) + sys.exit(0) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 655f06a..432812c 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -130,56 +130,67 @@ def isInFilelist(file,list): seen = True return seen -if __name__ == "__main__": +def Copyright(): print ('comic2ebook v%(__version__)s. ' - 'Written 2012 by Ciro Mattia Gonano.' % globals()) + 'Written 2012 by Ciro Mattia Gonano.' % globals()) + +def Usage(): + print "Generates HTML, NCX and OPF for a Comic ebook from a bunch of images" + print "Optimized for creating Mobipockets to be read into Kindle Paperwhite" + print "Usage:" + print " %s " % sys.argv[0] + print " <title> is optional" + +def main(argv=None): + if argv is None: + argv = sys.argv + profile = argv[1] + dir = argv[2] + cbx = cbxarchive.CBxArchive(dir) + if cbx.isCbxFile(): + cbx.extract() + dir = cbx.getPath() + if len(argv)==4: + title = argv[3] + else: + title = "comic" + filelist = [] + try: + print "Splitting double pages..." + for file in os.listdir(dir): + if (getImageFileName(file) != None): + img = image.ComicPage(dir+'/'+file, profile) + img.splitPage(dir) + for file in os.listdir(dir): + if (getImageFileName(file) != None): + print "Optimizing " + file + " for " + profile + img = image.ComicPage(dir+'/'+file, profile) + img.resizeImage() + #img.frameImage() + img.quantizeImage() + img.saveToDir(dir) + except ImportError: + print "Could not load PIL, not optimizing image" + + for file in os.listdir(dir): + if (getImageFileName(file) != None and isInFilelist(file,filelist) == False): + # put credits at the end + if "credits" in file.lower(): + os.rename(dir+'/'+file, dir+'/ZZZ999_'+file) + file = 'ZZZ999_'+file + filename = HTMLbuilder(dir,file).getResult() + if (filename != None): + filelist.append(filename) + NCXbuilder(dir,title) + # ensure we're sorting files alphabetically + filelist = sorted(filelist, key=lambda name: name[0]) + OPFBuilder(dir,title,filelist) + +if __name__ == "__main__": + Copyright() if len(sys.argv)<3 or len(sys.argv)>4: - print "Generates HTML, NCX and OPF for a Comic ebook from a bunch of images" - print "Optimized for creating Mobipockets to be read into Kindle Paperwhite" - print "Usage:" - print " %s <profile> <dir> <title>" % sys.argv[0] - print " <title> is optional" + Usage() sys.exit(1) else: - profile = sys.argv[1] - dir = sys.argv[2] - cbx = cbxarchive.CBxArchive(dir) - if cbx.isCbxFile(): - cbx.extract() - dir = cbx.getPath() - if len(sys.argv)==4: - title = sys.argv[3] - else: - title = "comic" - filelist = [] - try: - print "Splitting double pages..." - for file in os.listdir(dir): - if (getImageFileName(file) != None): - img = image.ComicPage(dir+'/'+file, profile) - img.splitPage(dir) - for file in os.listdir(dir): - if (getImageFileName(file) != None): - print "Optimizing " + file + " for " + profile - img = image.ComicPage(dir+'/'+file, profile) - img.resizeImage() - #img.frameImage() - img.quantizeImage() - img.saveToDir(dir) - except ImportError: - print "Could not load PIL, not optimizing image" - - for file in os.listdir(dir): - if (getImageFileName(file) != None and isInFilelist(file,filelist) == False): - # put credits at the end - if "credits" in file.lower(): - os.rename(dir+'/'+file, dir+'/ZZZ999_'+file) - file = 'ZZZ999_'+file - filename = HTMLbuilder(dir,file).getResult() - if (filename != None): - filelist.append(filename) - NCXbuilder(dir,title) - # ensure we're sorting files alphabetically - filelist = sorted(filelist, key=lambda name: name[0]) - OPFBuilder(dir,title,filelist) + main() sys.exit(0) diff --git a/setup.py b/setup.py index f2628e9..f03adf2 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ VERSION="1.2.0" IDENTIFIER="com.github.ciromattia.kcc" EXENAME="KindleComicConverter" -APP = ['kcc/comic2ebook.py'] +APP = ['kcc.py'] DATA_FILES = [] OPTIONS = { 'argv_emulation': True, 'iconfile': 'resources/comic2ebook.icns', @@ -36,20 +36,10 @@ if sys.platform == 'darwin': plist=dict( CFBundleName = NAME, CFBundleShortVersionString = VERSION, - CFBundleGetInfoString = NAME + " " + VERSION, + CFBundleGetInfoString = NAME + " " + VERSION + ", written 2012 by Ciro Mattia Gonano", CFBundleExecutable = EXENAME, CFBundleIdentifier = IDENTIFIER, - CFBundleDocumentTypes = dict( - CFBundleTypeExtensions=["zip","rar","cbz","cbr"], - CFBundleTypeName="Comics", - CFBundleTypeRole="Editor", - LSItemContentTypes = [ - "public.plain-text", - "public.text", - "public.data", - "com.apple.application-bundle" - ] - ) + CFBundleSignature = 'dplt' ) ) ) @@ -69,5 +59,14 @@ setup( name=NAME, app=APP, data_files=DATA_FILES, + classifiers=[ + # make sure to use :: Python *and* :: Python :: 3 so + # that pypi can list the package on the python 3 page + 'Programming Language :: Python', + 'Programming Language :: Python :: 3' + ], + packages=['kcc'], + # make sure to add custom_fixers to the MANIFEST.in + include_package_data=True, **extra_options )