1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
6 from .builders import builders
7 from .document import WLDocument
10 def main(*args, **kwargs):
11 parser = argparse.ArgumentParser(description="PARSER DESCRIPTION")
15 choices=builders.keys(),
18 parser.add_argument('input_file')
20 '-o', '--output-file', metavar='FILE',
21 help='specifies the output file'
24 '-O', '--output-dir', metavar='DIR',
25 help='specifies the directory for output'
30 '-b', '--base-url', metavar="URL",
31 help="Base for relative URLs in documents (like image sources)"
38 help='specifies an MP3 file, if needed'
41 args = parser.parse_args()
42 builder = builders[args.builder]
45 output_file_path = args.output_file
47 output_file_path = '.'.join((
48 os.path.splitext(args.input_file)[0],
49 builder.file_extension
52 output_file_path = '/'.join((
54 output_file_path.rsplit('/', 1)[-1]
57 document = WLDocument(filename=args.input_file)
59 builder = builders[args.builder]
64 output = document.build(builder, base_url=args.base_url, **kwargs)
65 with open(output_file_path, 'wb') as f:
66 f.write(output.get_bytes())