Help cleanup

This commit is contained in:
Paweł Jastrzębski
2013-08-09 15:25:00 +02:00
parent 92e2a8913b
commit 61206b2169
2 changed files with 75 additions and 55 deletions
+55 -45
View File
@@ -29,7 +29,7 @@ import re
import stat import stat
import string import string
from shutil import move, copyfile, copytree, rmtree, make_archive from shutil import move, copyfile, copytree, rmtree, make_archive
from optparse import OptionParser from optparse import OptionParser, OptionGroup
from multiprocessing import Pool, Queue, freeze_support from multiprocessing import Pool, Queue, freeze_support
try: try:
from PyQt4 import QtCore from PyQt4 import QtCore
@@ -818,50 +818,60 @@ def Usage():
def main(argv=None, qtGUI=None): def main(argv=None, qtGUI=None):
global parser, options, epub_path, splitCount, GUI global parser, options, epub_path, splitCount, GUI
usage = "Usage: %prog [options] comic_file|comic_folder" parser = OptionParser(usage="Usage: %prog [options] comic_file|comic_folder", add_help_option=False)
parser = OptionParser(usage=usage, version=__version__) mainOptions = OptionGroup(parser, "MAIN")
parser.add_option("-p", "--profile", action="store", dest="profile", default="KHD", processingOptions = OptionGroup(parser, "PROCESSING")
help="Device profile (Choose one among K1, K2, K3, K4NT, K4T, KDX, KDXG, KHD, KF, KFHD, KFHD8," outputOptions = OptionGroup(parser, "OUTPUT SETTINGS")
" KFA) [Default=KHD]") customProfileOptions = OptionGroup(parser, "CUSTOM PROFILE")
parser.add_option("-t", "--title", action="store", dest="title", default="defaulttitle", otherOptions = OptionGroup(parser, "OTHER")
help="Comic title [Default=filename]") mainOptions.add_option("-p", "--profile", action="store", dest="profile", default="KHD",
parser.add_option("-m", "--manga-style", action="store_true", dest="righttoleft", default=False, help="Device profile (Choose one among K1, K2, K3, K4NT, K4T, KDX, KDXG, KHD, KF, KFHD,"
help="Manga style (Right-to-left reading and splitting) [Default=False]") " KFHD8, KFA) [Default=KHD]")
parser.add_option("--quality", type="int", dest="quality", default="0", mainOptions.add_option("-q", "--quality", type="int", dest="quality", default="0",
help="Output quality. 0 - Normal 1 - High 2 - Ultra [Default=0]") help="Quality of Panel View. 0 - Normal 1 - High 2 - Ultra [Default=0]")
parser.add_option("-c", "--cbz-output", action="store_true", dest="cbzoutput", default=False, mainOptions.add_option("-m", "--manga-style", action="store_true", dest="righttoleft", default=False,
help="Outputs a CBZ archive and does not generate EPUB") help="Manga style (Right-to-left reading and splitting)")
parser.add_option("--noprocessing", action="store_false", dest="imgproc", default=True, outputOptions.add_option("-o", "--output", action="store", dest="output", default=None,
help="Don't apply image preprocessing (Page splitting and optimizations) [Default=True]") help="Output generated file to specified directory or file")
parser.add_option("--forcepng", action="store_true", dest="forcepng", default=False, outputOptions.add_option("-t", "--title", action="store", dest="title", default="defaulttitle",
help="Create PNG files instead JPEG (For non-Kindle devices) [Default=False]") help="Comic title [Default=filename or directory name]")
parser.add_option("--gamma", type="float", dest="gamma", default="0.0", outputOptions.add_option("--cbz-output", action="store_true", dest="cbzoutput", default=False,
help="Apply gamma correction to linearize the image [Default=Auto]") help="Outputs a CBZ archive and does not generate EPUB")
parser.add_option("--upscale", action="store_true", dest="upscale", default=False, outputOptions.add_option("--batchsplit", action="store_true", dest="batchsplit", default=False,
help="Resize images smaller than device's resolution [Default=False]") help="Split output into multiple files"),
parser.add_option("--stretch", action="store_true", dest="stretch", default=False, processingOptions.add_option("--blackborders", action="store_true", dest="black_borders", default=False,
help="Stretch images to device's resolution [Default=False]") help="Use black borders instead of white ones")
parser.add_option("--blackborders", action="store_true", dest="black_borders", default=False, processingOptions.add_option("--forcecolor", action="store_true", dest="forcecolor", default=False,
help="Use black borders instead of white ones when not stretching and ratio " help="Don't convert images to grayscale")
+ "is not like the device's one [Default=False]") processingOptions.add_option("--forcepng", action="store_true", dest="forcepng", default=False,
parser.add_option("--rotate", action="store_true", dest="rotate", default=False, help="Create PNG files instead JPEG (For non-Kindle devices)")
help="Rotate landscape pages instead of splitting them [Default=False]") processingOptions.add_option("--gamma", type="float", dest="gamma", default="0.0",
parser.add_option("--nosplitrotate", action="store_true", dest="nosplitrotate", default=False, help="Apply gamma correction to linearize the image [Default=Auto]")
help="Disable splitting and rotation [Default=False]") processingOptions.add_option("--nocutpagenumbers", action="store_false", dest="cutpagenumbers", default=True,
parser.add_option("--nocutpagenumbers", action="store_false", dest="cutpagenumbers", default=True, help="Don't try to cut page numbering on images")
help="Don't try to cut page numbering on images [Default=True]") processingOptions.add_option("--noprocessing", action="store_false", dest="imgproc", default=True,
parser.add_option("--forcecolor", action="store_true", dest="forcecolor", default=False, help="Don't apply image preprocessing")
help="Don't convert images to grayscale [Default=False]") processingOptions.add_option("--nosplitrotate", action="store_true", dest="nosplitrotate", default=False,
parser.add_option("--batchsplit", action="store_true", dest="batchsplit", default=False, help="Disable splitting and rotation")
help="Split output into multiple files [Default=False]"), processingOptions.add_option("--rotate", action="store_true", dest="rotate", default=False,
parser.add_option("--customwidth", type="int", dest="customwidth", default=0, help="Rotate landscape pages instead of splitting them")
help="Replace screen width provided by device profile [Default=0]") processingOptions.add_option("--stretch", action="store_true", dest="stretch", default=False,
parser.add_option("--customheight", type="int", dest="customheight", default=0, help="Stretch images to device's resolution")
help="Replace screen height provided by device profile [Default=0]") processingOptions.add_option("--upscale", action="store_true", dest="upscale", default=False,
parser.add_option("-o", "--output", action="store", dest="output", default=None, help="Resize images smaller than device's resolution")
help="Output generated file (EPUB or CBZ) to specified directory or file") customProfileOptions.add_option("--customwidth", type="int", dest="customwidth", default=0,
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Replace screen width provided by device profile")
help="Verbose output [Default=False]") customProfileOptions.add_option("--customheight", type="int", dest="customheight", default=0,
help="Replace screen height provided by device profile")
otherOptions.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
help="Verbose output")
otherOptions.add_option("-h", "--help", action="help",
help="Show this help message and exit")
parser.add_option_group(mainOptions)
parser.add_option_group(outputOptions)
parser.add_option_group(processingOptions)
parser.add_option_group(customProfileOptions)
parser.add_option_group(otherOptions)
options, args = parser.parse_args(argv) options, args = parser.parse_args(argv)
checkOptions() checkOptions()
if qtGUI: if qtGUI:
+20 -10
View File
@@ -25,9 +25,14 @@ __docformat__ = 'restructuredtext en'
import sys import sys
import os import os
from shutil import rmtree, copytree from shutil import rmtree, copytree
from optparse import OptionParser from optparse import OptionParser, OptionGroup
from multiprocessing import Pool, freeze_support from multiprocessing import Pool, freeze_support
from PIL import Image, ImageStat try:
# noinspection PyUnresolvedReferences
from PIL import Image, ImageStat
except ImportError:
print "ERROR: Pillow is not installed!"
exit(1)
def getImageFileName(imgfile): def getImageFileName(imgfile):
@@ -157,12 +162,17 @@ def Copyright():
# noinspection PyBroadException # noinspection PyBroadException
def main(argv=None): def main(argv=None):
global options global options
usage = "Usage: %prog [options] comic_folder" parser = OptionParser(usage="Usage: %prog [options] comic_folder", add_help_option=False)
parser = OptionParser(usage=usage, version=__version__) mainOptions = OptionGroup(parser, "MANDATORY")
parser.add_option("-y", "--height", type="int", dest="height", default=0, otherOptions = OptionGroup(parser, "OTHER")
help="Target device screen height [Default=0]") mainOptions.add_option("-y", "--height", type="int", dest="height", default=0,
parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Height of the target device screen")
help="Create debug file for every splitted image [Default=False]") otherOptions.add_option("-d", "--debug", action="store_true", dest="debug", default=False,
help="Create debug file for every splitted image")
otherOptions.add_option("-h", "--help", action="help",
help="Show this help message and exit")
parser.add_option_group(mainOptions)
parser.add_option_group(otherOptions)
options, args = parser.parse_args(argv) options, args = parser.parse_args(argv)
if len(args) != 1: if len(args) != 1:
parser.print_help() parser.print_help()
@@ -194,13 +204,13 @@ def main(argv=None):
sys.exit(1) sys.exit(1)
else: else:
rmtree(options.targetDir) rmtree(options.targetDir)
print "ERROR: Source directory is empty!!" print "ERROR: Source directory is empty!"
sys.exit(1) sys.exit(1)
else: else:
print "ERROR: Provided path is not a directory!" print "ERROR: Provided path is not a directory!"
sys.exit(1) sys.exit(1)
else: else:
print "ERROR: Target height was not provided!" print "ERROR: Target height is not set!"
sys.exit(1) sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":