4 from getopt
import gnu_getopt
6 from objavi
.fmbook
import log
, ZipBook
, make_book_name
7 from objavi
.cgi_utils
import shift_file
, parse_args
, optionise
, print_template
8 from objavi
import config
10 USE_CACHED_IMAGES
= True #avoid network -- will make out of date books in production!
12 BOOKS
= [x
[:-4] for x
in os
.listdir(config
.BOOKI_BOOK_DIR
) if x
.endswith('.zip')]
14 def print_form(booklink
):
15 print_template('templates/epubjavi.html',
16 {'booklink': booklink
,
17 'booklist': optionise(sorted(BOOKS
))}
20 def epubjavi(book
, use_cached_images
=USE_CACHED_IMAGES
):
21 book
= ZipBook(config
.LOCALHOST
, book
)
22 book
.make_epub(use_cache
=use_cached_images
)
23 return shift_file(book
.epubfile
, config
.EPUB_DIR
)
26 # ARG_VALIDATORS is a mapping between the expected cgi arguments and
27 # functions to validate their values. (None means no validation).
29 "book": BOOKS
.__contains
__,
32 if __name__
== '__main__':
33 args
= parse_args(ARG_VALIDATORS
)
35 url
= epubjavi(args
['book'])
36 book_link
= '<p>Download <a href="%s">%s epub</a>.</p>' %(url
, args
['book'])