X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/dfab836a2bcb5a8e4787e960c14f3790f7773e8d..0c0fdd2db2c1277108b03a1acf88ad63d140451a:/librarian/packagers.py?ds=inline diff --git a/librarian/packagers.py b/librarian/packagers.py index a32a2a0..f57a983 100644 --- a/librarian/packagers.py +++ b/librarian/packagers.py @@ -4,9 +4,11 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # import os -from librarian import pdf, epub, mobi, DirDocProvider, ParseError, cover +from librarian import pdf, epub, mobi, DirDocProvider, ParseError from librarian.parser import WLDocument +from util import makedirs + class Packager(object): cover = None @@ -23,20 +25,15 @@ class Packager(object): slug, ext = os.path.splitext(fname) if output_dir != '': - try: - os.makedirs(output_dir) - except: - pass + makedirs(output_dir) outfile = os.path.join(output_dir, slug + '.' + cls.ext) if os.path.exists(outfile) and not overwrite: return doc = WLDocument.from_file(main_input, provider=provider) - output_file = cls.transform(doc, - cover=cls.cover, flags=cls.flags) + output_file = cls.transform(doc, cover=cls.cover, flags=cls.flags) doc.save_output_file(output_file, output_path=outfile) - @classmethod def prepare(cls, input_filenames, output_dir='', verbose=False, overwrite=False): try: @@ -56,10 +53,12 @@ class EpubPackager(Packager): converter = epub ext = 'epub' + class MobiPackager(Packager): converter = mobi ext = 'mobi' + class PdfPackager(Packager): converter = pdf ext = 'pdf'