From 461282b46657e519d8fbcacebbb015d213f16102 Mon Sep 17 00:00:00 2001 From: chibidev Date: Sat, 14 Apr 2012 13:01:28 +0200 Subject: [PATCH 1/4] Basic command line interface for mangle. --- README | 1 + mangle-cli.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 mangle-cli.py diff --git a/README b/README index e69de29..73c5c99 100644 --- a/README +++ b/README @@ -0,0 +1 @@ +A simple python script, that accepts a bunch of image files, and optimizes for an ebook reader device, than zipping it into a cbz archive. diff --git a/mangle-cli.py b/mangle-cli.py new file mode 100755 index 0000000..71c1f54 --- /dev/null +++ b/mangle-cli.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python2 + +import shutil +import sys +import os +import getopt + +from mangle.book import Book +import mangle.cbz +import mangle.image + +try: + opts, args = getopt.getopt(sys.argv[1:], 'd:t:o:') +except getopt.GetoptError, err: + print str(err) + sys.exit(2) + +directory = '.' + +book = Book() +book.device = 'Kindle 3' +book.outputFormat = 'CBZ only' +book.title = 'Unknown' + + +for o,a in opts: + if o == '-d': + directory = a + elif o == '-t': + book.title = a + elif o == '-o': + book.outputFormat = a + + +bookPath = os.path.join(directory, book.title) + +archive = mangle.cbz.Archive(bookPath) + +if not os.path.isdir(bookPath): + os.makedirs(bookPath) + + +for index in range(1, len(args)): + target = os.path.join(bookPath, '%05d.png' % index) + + mangle.image.convertImage(args[index], target, str(book.device), book.imageFlags) + archive.addFile(target); + + +if 'Image' not in book.outputFormat: + shutil.rmtree(bookPath) + +archive.close() From a4f98e99e53ac46f75d8d90a3ee02e9f6de63d22 Mon Sep 17 00:00:00 2001 From: chibidev Date: Sat, 14 Apr 2012 15:13:29 +0200 Subject: [PATCH 2/4] Fixing typo in README. --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 73c5c99..22526e3 100644 --- a/README +++ b/README @@ -1 +1 @@ -A simple python script, that accepts a bunch of image files, and optimizes for an ebook reader device, than zipping it into a cbz archive. +A simple python script, that accepts a bunch of image files, and optimizes for an ebook reader device, then zipping it into a cbz archive. From fec243c4d4bcdd5572a848c2b281a42736360fd4 Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 16 Jul 2021 20:34:32 -0700 Subject: [PATCH 3/4] Working commandline without PyQt * Show simple usage in doc comments * python3 ready print() calls * add note on format and image filename preservation * display progress * remove Qt dependency for mangle-cli.py --- mangle-cli.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/mangle-cli.py b/mangle-cli.py index 71c1f54..6176d8a 100755 --- a/mangle-cli.py +++ b/mangle-cli.py @@ -1,24 +1,40 @@ #!/usr/bin/env python2 +"""python mangle-cli.py extracted_cbz_folder/* + -d directory_name defaults to ./ + -t title defaults 'Unknown' + -o book.outputFormat defaults to 'CBZ only' + +NOTE order of arguments for image files is significant. +""" import shutil import sys import os import getopt -from mangle.book import Book import mangle.cbz import mangle.image +from mangle.image import ImageFlags + + +class FakeBook: + device = 'Kindle 2/3/Touch' # See mangle/image.py KindleData.Profiles + outputFormat = 'CBZ only' + title = 'Unknown' + imageFlags = ImageFlags.Orient | ImageFlags.Resize | ImageFlags.Quantize + try: opts, args = getopt.getopt(sys.argv[1:], 'd:t:o:') except getopt.GetoptError, err: - print str(err) + print(str(err)) sys.exit(2) directory = '.' -book = Book() -book.device = 'Kindle 3' +book = FakeBook() +book.device = 'Kindle 2/3/Touch' +#book.device = 'Kindle Paperwhite 1 & 2' book.outputFormat = 'CBZ only' book.title = 'Unknown' @@ -40,9 +56,10 @@ if not os.path.isdir(bookPath): os.makedirs(bookPath) -for index in range(1, len(args)): - target = os.path.join(bookPath, '%05d.png' % index) +for index in range(0, len(args)): + target = os.path.join(bookPath, '%05d.png' % index) # FIXME preserve original; format and name? + print(index, args[index], target) # cheap display progress mangle.image.convertImage(args[index], target, str(book.device), book.imageFlags) archive.addFile(target); @@ -51,3 +68,4 @@ if 'Image' not in book.outputFormat: shutil.rmtree(bookPath) archive.close() + From 50bea904a44c621b5093644ef77af56145b1c598 Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 16 Jul 2021 20:51:32 -0700 Subject: [PATCH 4/4] Doc comments of example --- mangle-cli.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mangle-cli.py b/mangle-cli.py index 6176d8a..9c8e2b1 100755 --- a/mangle-cli.py +++ b/mangle-cli.py @@ -5,6 +5,15 @@ -o book.outputFormat defaults to 'CBZ only' NOTE order of arguments for image files is significant. + +Example: + + mkdir my_comic + cd my_comic + 7z x /full/path/my/comic.cbz + cd .. + python mangle-cli.py -tmy_comic my_comic/* + """ import shutil