From 461282b46657e519d8fbcacebbb015d213f16102 Mon Sep 17 00:00:00 2001 From: chibidev Date: Sat, 14 Apr 2012 13:01:28 +0200 Subject: [PATCH] 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()