from calibre.ebooks.epub.fix.container import Container
def option_parser():
parser = OptionParser(usage = _('%prog [options] file.epub\n\nFix common problems in EPUB files that can cause them to be rejected by poorly designed publishing services.\n\nBy default, no fixing is done and messages are printed out for each error detected. Use the options to control which errors are automatically fixed.'))
for fixer in epub_fixers():
fixer.add_options_to_parser(parser)
return parser
def run(epub, opts, log):
try:
tdir = _[1]
CurrentDir(tdir).__enter__()
try:
zf = ZipFile(epub)
zf.extractall()
zf.close()
container = Container(tdir, log)
for fixer in epub_fixers():
fix = getattr(opts, fixer.fix_name, False)
fixer.run(container, opts, log, fix = fix)
container.write(epub)
finally:
pass
finally:
pass
def main(args = sys.argv):
parser = option_parser()
(opts, args) = parser.parse_args(args)
if len(args) != 2:
parser.print_help()
print
default_log.error(_('You must specify an epub file'))