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
.config
import EPUB_DIR
10 USE_CACHED_IMAGES
= True #avoid network -- will make out of date books in production!
12 BOOKI_BOOK_DIR
= 'booki-books'
13 BOOKS
= [x
[:-4] for x
in os
.listdir(BOOKI_BOOK_DIR
) if x
.endswith('.zip')]
15 def print_form(booklink
):
16 print_template('templates/epubjavi.html',
17 {'booklink': booklink
,
18 'booklist': optionise(sorted(BOOKS
))}
21 def epubjavi(book
,use_cached_images
=USE_CACHED_IMAGES
):
22 f
= open('%s/%s.zip' % (BOOKI_BOOK_DIR
, book
))
25 book
= ZipBook(zipstring
)
26 book
.make_epub(use_cache
=use_cached_images
)
27 return shift_file(book
.epubfile
, EPUB_DIR
)
30 # ARG_VALIDATORS is a mapping between the expected cgi arguments and
31 # functions to validate their values. (None means no validation).
33 "book": BOOKS
.__contains
__,
36 if __name__
== '__main__':
37 args
= parse_args(ARG_VALIDATORS
)
39 url
= epubjavi(args
['book'])
40 book_link
= '<p>Download <a href="%s">%s epub</a>.</p>' %(url
, args
['book'])