Basic command line interface for mangle.

This commit is contained in:
chibidev 2012-04-14 13:01:28 +02:00
parent a71ff52e22
commit 461282b466
2 changed files with 54 additions and 0 deletions

1
README
View File

@ -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.

53
mangle-cli.py Executable file
View File

@ -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()