1 # Part of Objavi2, which makes pdf versions of FLOSSManuals books.
2 # This python module contains or encapsulates configuration and
5 # Copyright (C) 2009 Douglas Bagnall
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 """This module contains constant values used to produce books.
23 #XXX eventually, read in a real config file.
24 #XXX Some of these values should be editable via an admin cgi script
26 #cgi scripts chdir here to escape htdocs
29 #Not really configurable (72 pt per inch / 25.4 mm per inch)
30 POINT_2_MM
= 25.4 / 72.0
31 MM_2_POINT
= 72.0 / 25.4
34 KEEP_TEMP_FILES
= True
39 LOG_ROTATE_SIZE
= 1000000
42 BOOKI_BOOK_DIR
= 'htdocs/booki-books'
43 BOOKI_BOOK_URL
= '/booki-books'
46 WKHTMLTOPDF
= '/usr/local/bin/wkhtmltopdf-static'
47 WKHTMLTOPDF_EXTRA_COMMANDS
= []
49 #use hacked version of wkhtmltopdf that writes outline to a file
50 USE_DUMP_OUTLINE
= True
53 HTML2ODT
= 'bin/html2odt'
55 #CGITB_DOMAINS = ('203.97.236.46', '202.78.240.7')
58 #bookland is used to make isbn barcodes
59 BOOKLAND
= 'bookland/bookland'
61 # how many pages to number in one pdfedit process (which has
62 # exponential memory leak)
63 PDFEDIT_MAX_PAGES
= 40
65 #keep book lists around for this time without refetching
66 BOOK_LIST_CACHE
= 3600 * 2
70 TOC_URL
= "http://%s/pub/%s/_index/TOC.txt"
71 CHAPTER_URL
= "http://%s/bin/view/%s/%s?skin=text"
73 PUBLISH_DIR
= 'htdocs/books'
75 POLL_NOTIFY_PATH
= 'htdocs/progress/%s.txt'
76 #POLL_NOTIFY_URL = 'http://%(HTTP_HOST)s/progress/%(bookname)s.txt'
79 'TWiki': 'http://%(HTTP_HOST)s/booki-twiki-gateway.cgi?server=%(server)s&book=%(book)s&mode=zip',
80 'Booki': 'http://%(server)s/export/%(book)s/export',
81 'Archive': 'http://%(HTTP_HOST)s/espri.cgi?mode=zip&book=%(book)s',
84 DEFAULT_SERVER
= 'en.flossmanuals.net'
85 DEFAULT_SIZE
= 'COMICBOOK'
86 DEFAULT_ENGINE
= 'webkit'
88 BOOKIZIP_MIMETYPE
= "application/x-booki+zip"
90 RTL_SCRIPTS
= ['persian', 'arabic', 'hebrew', 'urdu']
92 USE_CACHED_IMAGES
= False
94 #Normally, Book objects try to shutdown subprocesses and clean up temp
95 #files when they __exit__. This flag makes them try when they __del__
96 #too (i.e. when they are garbage collected).
97 TRY_BOOK_CLEANUP_ON_DEL
= False
99 LOCALHOST
= 'localhost'
102 'en': {None: 'static/en.flossmanuals.net.css',
103 'web': 'static/en.flossmanuals.net-web.css',
104 'newspaper': 'static/en.flossmanuals.net-newspaper.css',
105 'openoffice': 'static/en.flossmanuals.net-openoffice.css',
107 'my': {None: 'static/my.flossmanuals.net.css',}
111 'booki.flossmanuals.net': {
112 'css-book': 'static/en.flossmanuals.net.css',
113 'css-web': 'static/en.flossmanuals.net-web.css',
114 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
115 'css-openoffice': 'static/en.flossmanuals.net-openoffice.css',
118 'toc-encoding': None,
120 'interface': 'Booki',
121 'toc_header': 'Table of Contents',
124 'css-book': 'static/en.flossmanuals.net.css',
125 'css-web': 'static/en.flossmanuals.net-web.css',
126 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
127 'css-openoffice': 'static/en.flossmanuals.net-openoffice.css',
130 'toc-encoding': None,
132 'interface': 'Booki',
133 'toc_header': 'Table of Contents',
136 'css-book': 'static/en.flossmanuals.net.css',
137 'css-web': 'static/en.flossmanuals.net-web.css',
138 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
139 'css-openoffice': 'static/en.flossmanuals.net-openoffice.css',
142 'toc-encoding': None,
144 'interface': 'Archive',
145 'toc_header': 'Table of Contents',
148 'css-book': 'static/en.flossmanuals.net.css',
149 'css-web': 'static/en.flossmanuals.net-web.css',
150 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
151 'css-openoffice': 'static/en.flossmanuals.net-openoffice.css',
154 'toc-encoding': 'iso-8859-1',
156 'interface': 'local',
157 'toc_header': 'Table of Contents',
159 'en.flossmanuals.net': {
160 'css-book': 'static/en.flossmanuals.net.css',
161 'css-web': 'static/en.flossmanuals.net-web.css',
162 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
163 'css-openoffice': 'static/en.flossmanuals.net-openoffice.css',
166 'toc-encoding': None,
168 'interface': 'TWiki',
169 'toc_header': 'Table of Contents',
171 'fr.flossmanuals.net': {
172 'css-book': 'static/fr.flossmanuals.net.css',
173 'css-web': 'static/fr.flossmanuals.net-web.css',
174 'css-newspaper': 'static/fr.flossmanuals.net-newspaper.css',
175 'css': 'static/fr.flossmanuals.net.css',
176 'css-openoffice': 'static/fr.flossmanuals.net-openoffice.css',
179 'toc-encoding': 'iso-8859-1',
181 'interface': 'TWiki',
182 'toc_header': 'Table of Contents',
184 'translate.flossmanuals.net': {
185 'css-book': None, #'static/translate.flossmanuals.net.css',
186 'css-web': None, #'static/translate.flossmanuals.net-web.css',
187 'css-newspaper': None, #'static/translate.flossmanuals.net-newspaper.css',
188 'css': None, #'static/translate.flossmanuals.net.css',
189 'css-openoffice': None, #'static/translate.flossmanuals.net-openoffice.css',
192 'toc-encoding': 'iso-8859-1',
194 'interface': 'TWiki',
195 'toc_header': 'Table of Contents',
197 'nl.flossmanuals.net': {
198 'css-book': 'static/nl.flossmanuals.net.css',
199 'css-web': 'static/nl.flossmanuals.net-web.css',
200 'css-newspaper': 'static/nl.flossmanuals.net-newspaper.css',
201 'css': 'static/nl.flossmanuals.net.css',
202 'css-openoffice': 'static/nl.flossmanuals.net-openoffice.css',
205 'toc-encoding': 'iso-8859-1',
207 'interface': 'TWiki',
208 'toc_header': 'Table of Contents',
210 'bn.flossmanuals.net': {
211 'css-book': 'static/bn.flossmanuals.net.css',
212 'css-web': 'static/bn.flossmanuals.net-web.css',
213 'css-newspaper': 'static/bn.flossmanuals.net-newspaper.css',
214 'css': 'static/bn.flossmanuals.net.css',
215 'css-openoffice': 'static/bn.flossmanuals.net-openoffice.css',
218 'toc-encoding': 'iso-8859-1',
220 'interface': 'TWiki',
221 'toc_header': 'Table of Contents',
223 'fa.flossmanuals.net': {
224 'css-book': 'static/fa.flossmanuals.net.css',
225 'css-web': 'static/fa.flossmanuals.net-web.css',
226 'css-newspaper': 'static/fa.flossmanuals.net-newspaper.css',
227 'css': 'static/fa.flossmanuals.net.css',
228 'css-openoffice': 'static/fa.flossmanuals.net-openoffice.css',
231 'toc-encoding': 'iso-8859-1',
233 'interface': 'TWiki',
234 'toc_header': 'Table of Contents',
238 if 'booki.cc' in SERVER_DEFAULTS
:
239 SERVER_DEFAULTS
['www.booki.cc'] = SERVER_DEFAULTS
['booki.cc']
243 "ar": 'RTL', # arabic (many variants)
244 "dv": 'RTL', # dhivehi, maldives islands
246 #"ha": 'RTL', # hausa, west africa, particularly niger and nigeria
247 "he": 'RTL', # hebrew
248 "ps": 'RTL', # pashto
249 "ur": 'RTL', # urdu, pakistan
250 "yi": 'RTL', # yiddish, israel
253 # uncomment a debug mode to get messages about that topic.
263 #convert all sizes to points
264 PAPER_SIZES
= [(s
, x
* MM_2_POINT
, y
* MM_2_POINT
) for s
, x
, y
in (
279 # margins are BASE_MARGIN + PROPORTIONAL_MARGIN * min(width, height)
281 PROPORTIONAL_MARGIN
= 0.04
282 # gutter is BASE_GUTTER + PROPORTIONAL_GUTTER * width
284 PROPORTIONAL_GUTTER
= 0.011
287 'page_width': (1, 1000, MM_2_POINT
),
288 'page_height': (1, 1414, MM_2_POINT
), #can't be bigger than biggest PAPER_SIZE
289 'gutter': (-1000, 1000, MM_2_POINT
),
290 'top_margin': (0, 1500, MM_2_POINT
),
291 'side_margin': (0, 1500, MM_2_POINT
),
292 'bottom_margin': (0, 1500, MM_2_POINT
),
293 "columns": (1, 12, 1),
294 "column_margin": (0, 1000, MM_2_POINT
),
297 PAGE_NUMBER_SIZE
= 11 #XXX this is not used by pdfedit! (ie, it is a guess)
300 'COMICBOOK': {'pointsize': ((6.625 * 72), (10.25 * 72)), 'class': "lulu"},
301 "POCKET": {'pointsize': (4.25 * 72, 6.875 * 72), 'class': "lulu"},
303 "USLETTER": {'pointsize': (8.5 * 72, 11 * 72), 'class': "lulu"},
304 "USTRADE": {'pointsize': (6 * 72, 9 * 72), 'class': "lulu"},
305 "LANDSCAPE9x7": {'pointsize': (9 * 72, 7 * 72), 'class': "lulu"},
306 "SQUARE7.5": {'pointsize': (7.5 * 72, 7.5 * 72), 'class': "lulu"},
307 "ROYAL": {'pointsize': (6.139 * 72, 9.21 * 72), 'class': "lulu"},
308 "CROWNQUARTO": {'pointsize': (7.444 * 72, 9.681 * 72), 'class': "lulu"},
309 "SQUARE8.5": {'pointsize': (8.5 * 72, 8.5 * 72), 'class': "lulu"},
311 "A5": {'pointsize': (148 * MM_2_POINT
, 210 * MM_2_POINT
), 'class': "lulu iso"},
312 "A4": {'pointsize': (210 * MM_2_POINT
, 297 * MM_2_POINT
), 'class': "lulu iso"},
313 "A3 (NZ Tabloid)": {'pointsize': (297 * MM_2_POINT
, 420 * MM_2_POINT
), 'class': 'iso newspaper'},
314 "A2 (NZ Broadsheet)": {'pointsize': (420 * MM_2_POINT
, 594 * MM_2_POINT
), 'class': 'iso newspaper'},
315 "A1": {'pointsize': (594 * MM_2_POINT
, 841 * MM_2_POINT
), 'class': 'iso'},
316 "B4": {'pointsize': (250 * MM_2_POINT
, 353 * MM_2_POINT
), 'class': 'iso'},
317 "B3": {'pointsize': (353 * MM_2_POINT
, 500 * MM_2_POINT
), 'class': 'iso'},
318 "B2": {'pointsize': (500 * MM_2_POINT
, 707 * MM_2_POINT
), 'class': 'iso'},
319 "B1": {'pointsize': (707 * MM_2_POINT
, 1000 * MM_2_POINT
), 'class': 'iso'},
321 "UK Tabloid": {'pointsize': (11 * INCH_2_POINT
, 17 * INCH_2_POINT
), 'class': 'newspaper'},
322 "UK Broadsheet": {'pointsize': (18 * INCH_2_POINT
, 24 * INCH_2_POINT
), 'class': 'newspaper'},
323 "US Broadsheet": {'pointsize': (15 * INCH_2_POINT
, 22.75 * INCH_2_POINT
), 'class': 'newspaper'},
324 "Berliner" : {'pointsize': (315 * MM_2_POINT
, 470 * MM_2_POINT
), 'class': 'newspaper'},
325 "Foolscap (F4)": {'pointsize': (210 * MM_2_POINT
, 330 * MM_2_POINT
)},
327 "Oamaru Broadsheet":{'pointsize': (382 * MM_2_POINT
, 540 * MM_2_POINT
), 'class': 'newspaper'},
328 "Oamaru Tabloid": {'pointsize': (265 * MM_2_POINT
, 380 * MM_2_POINT
), 'class': 'newspaper'},
330 #ODT printable 380x560
334 "custom": {'class': "custom"},
337 MIN_COLUMN_WIDTH
= (110 * MM_2_POINT
)
344 INSIDE_FRONT_COVER_TEMPLATE
= 'templates/inside-front-cover.%s.html'
345 END_MATTER_TEMPLATE
= 'templates/end_matter.%s.html'
347 FONT_LIST_INCLUDE
= 'cache/font-list.inc'
348 FONT_LIST_URL
= '/font-list.cgi.pdf'
349 FONT_EXAMPLE_SCRIPT_DIR
= 'templates/font-list'
351 # for the license field, with a view to making it a drop down.
353 'GPL': 'http://www.gnu.org/licenses/gpl.txt',
354 'GPLv2': 'http://www.gnu.org/licenses/gpl-2.0.txt',
355 'GPLv2+': 'http://www.gnu.org/licenses/gpl-2.0.txt',
356 'GPLv3': 'http://www.gnu.org/licenses/gpl-3.0.txt',
357 'GPLv3+': 'http://www.gnu.org/licenses/gpl-3.0.txt',
358 'LGPL': 'http://www.gnu.org/licenses/lgpl.txt',
359 'LGPLv2.1': 'http://www.gnu.org/licenses/lgpl-2.1.txt',
360 'LGPLv3': 'http://www.gnu.org/licenses/lgpl-3.0.txt',
361 'BSD': 'http://www.debian.org/misc/bsd.license',
362 'public domain': None,
363 'MIT': 'http://www.opensource.org/licenses/mit-license.html',
364 'Artistic': 'http://dev.perl.org/licenses/artistic.html',
365 'CC-BY': 'http://creativecommons.org/licenses/by/3.0/',
366 'CC-BY-SA': 'http://creativecommons.org/licenses/by-sa/3.0/',
369 DEFAULT_LICENSE
= 'GPLv2+'
371 CGI_MODES
= { # arguments are: (publication, extension, mimetype)
372 'book': (True, '.pdf', "application/pdf"),
373 'newspaper': (True, '.pdf', "application/pdf"),
374 'web': (True, '.pdf', "application/pdf"),
375 'openoffice': (True, '.odt', "application/vnd.oasis.opendocument.text"),
376 'booklist': (False, None, None),
377 'css': (False, None, None),
378 'form': (False, None, None),
379 'epub':(True, '.epub', "application/epub+zip"),
380 'bookizip':(True, '.zip', BOOKIZIP_MIMETYPE
),
383 PUBLIC_CGI_MODES
= tuple(k
for k
, v
in CGI_MODES
.items() if v
[0])
385 FORM_TEMPLATE
= 'templates/form.html'
386 PROGRESS_ASYNC_TEMPLATE
= 'templates/progress-async.html'
387 PROGRESS_TEMPLATE
= 'templates/progress.html'
388 ASYNC_TEMPLATE
= 'templates/async.txt'
389 ARCHIVE_TEMPLATE
= 'templates/archive.txt'
390 NOWHERE_TEMPLATE
= 'templates/nowhere.txt'
392 CGI_METHODS
= ('sync', 'async', 'poll')
394 #used by objavi-async
396 'archive.org': {'sync': (ARCHIVE_TEMPLATE
, 'text/plain; charset=utf-8'),
397 'async': (ARCHIVE_TEMPLATE
, 'text/plain; charset=utf-8'),
398 'poll': (None, None),
401 'download': {'sync': (None, None),
402 'async': (ASYNC_TEMPLATE
, 'text/plain; charset=utf-8'),
403 'poll': (None, None),
406 'html': {'sync': (PROGRESS_TEMPLATE
, 'text/html; charset=utf-8'),
407 'async': (ASYNC_TEMPLATE
, 'text/plain; charset=utf-8'),
408 'poll': (PROGRESS_ASYNC_TEMPLATE
, 'text/html; charset=utf-8'),
411 'nowhere': {'sync': (NOWHERE_TEMPLATE
, 'text/plain; charset=utf-8'),
412 'async': (NOWHERE_TEMPLATE
, 'text/plain; charset=utf-8'),
413 'poll': (ASYNC_TEMPLATE
, 'text/plain; charset=utf-8'),
418 DEFAULT_CGI_DESTINATION
= 'html'
422 # input, name, input type, contents key, CSS classes, extra text
423 ("server", "FLOSS Manuals server", "select", "server_options", "", ""),
424 ("book", "Manual", "select", "book_options", "", ""),
425 ("title", "Book title", "input[type=text]", None, "", ""),
426 ("license", "License", "select", "licenses", "", ""),
428 ("mode", "Document type", "select", "pdf_types", "advanced openoffice", ""),
429 ("isbn", "ISBN", "input[type=text]", None, "advanced", "(13 digits)"),
430 ("toc_header", "Table of Contents header", "input[type=text]", None, "advanced", ""),
432 ("booksize", "Page size", "select", "size_options", "advanced", '(Size compatibility: <span class="lulu">Lulu</span>, <span class="newspaper">newspapers</span>, <span class="iso">ISO standards</span>)'),
433 ("page_width", "Page width", "input[type=text]", None, "advanced booksize numeric-field", ""),
434 ("page_height", "Page height", "input[type=text]", None, "advanced booksize numeric-field", ""),
436 ("top_margin", "Top margin", "input[type=text]", None, "advanced margins numeric-field", ""),
437 ("side_margin", "Side margin", "input[type=text]", None, "advanced margins numeric-field", ""),
438 ("bottom_margin", "Bottom margin", "input[type=text]", None, "advanced margins numeric-field", ""),
439 ("gutter", "Gutter", "input[type=text]", None, "advanced margins numeric-field", ""),
441 ("columns", "Columns", "input[type=text]", None, "advanced columns numeric-field", ""),
442 ("column_margin", "Column margin", "input[type=text]", None, "advanced columns numeric-field", ""),
444 ("grey_scale", "Grey-scale", "input[type=checkbox]", 'yes', "advanced", "(for black and white printing)"),
446 #("css_customise", "Customise CSS", "input[type=checkbox]", None, "advanced", "Enter a URL or "),
447 ("css-url", "CSS URL", "input[type=text][disabled]", "css_url", "advanced css-url openoffice", ""),
448 ("font_list", "Available fonts", "ul", "font_list", "advanced css-custom openoffice", ""),
449 ("font_links", "Font examples", "ul", "font_links", "advanced css-custom openoffice", ""),
450 ("css", "CSS", "textarea", "css", "advanced css-custom openoffice", ""),
452 ("rotate", "Rotate pages for binding", "input[type=checkbox]", 'yes', "advanced", "(for RTL books on LTR printing presses, and vice versa)."),
453 #("engine", "Layout engine", "select", "engines", "advanced", ""),
454 #("header", "Header Text", "input[type=text]", None, "advanced", ""),
455 ("max-age", "Use cached data", "input[type=text]", None, "advanced numeric-field", "(younger than this many minutes)."),
456 #("destination", "Use cached data", "input[type=text]", None, "advanced", "(younger than this many minutes)."),
459 FORM_ELEMENT_TYPES
= {
460 'input[type=text]' : '<input type="text" id="%(id)s" name="%(id)s" value="%(val)s" />',
461 'input[type=text][disabled]' : '<input type="text" disabled="disabled" id="%(id)s" name="%(id)s" value="%(val)s" />',
462 'input[type=checkbox]' : '<input type="checkbox" id="%(id)s" name="%(id)s" value="%(val)s" />',
463 'textarea' : '<textarea id="%(id)s" name="%(id)s">%(val)s</textarea>',
464 'select': '<select id="%(id)s" name="%(id)s">%(val)s</select>',
465 'ul': '<ul id="%(id)s">%(val)s</ul>',
468 FINISHED_MESSAGE
= 'FINISHED'
471 ("start", "wake up", PUBLIC_CGI_MODES
),
472 ("fetch_zip", "Load data", PUBLIC_CGI_MODES
),
473 ("__init__", "Initialise the book", PUBLIC_CGI_MODES
),
474 ("load_book", "Fetch the book", ('book', 'newspaper', 'web', 'openoffice')),
475 ("add_css", "Add css", ('book', 'newspaper', 'web', 'openoffice')),
476 ("add_section_titles", "Add section titles", ('book', 'newspaper', 'web', 'openoffice')),
477 ("make_epub", "Make the epub file", ('epub',)),
478 ("make_oo_doc", "Make the OpenOffice document", ('openoffice',)),
479 ("generate_pdf", "Generate the main pdf", ('book', 'newspaper', 'web')),
480 ("extract_pdf_outline", "Find page numbers", ('book',)),
481 ("reshape_pdf", "Cut pages to size", ('book', 'newspaper',)),
482 #('make_body_pdf', "Generate the main pdf", ('book', 'newspaper', 'web')),
483 ("number_pdf", "Number pages", ('book', 'newspaper',)),
484 ("make_contents", "Calculate Table of Contents", ('book',)),
485 ("make_preamble_pdf", "Generate preamble pdf", ('book',)),
486 ('make_end_matter_pdf', "Generate end matter pdf", ('book',)),
487 ("concatenated_pdfs", "concatenate the pdfs", ('book',)),
488 #("publish_pdf", "Publish the pdf", ('book', 'newspaper', 'web')),
489 (FINISHED_MESSAGE
, "Finished!", PUBLIC_CGI_MODES
),
493 DCNS
= "{http://purl.org/dc/elements/1.1/}"
494 DC
= "http://purl.org/dc/elements/1.1/"
495 FM
= "http://booki.cc/"
496 XHTMLNS
= '{http://www.w3.org/1999/xhtml}'
497 XHTML
= 'http://www.w3.org/1999/xhtml'
499 S3_SECRET
= '/home/douglas/s3.archive.org-secret'
500 S3_ACCESSKEY
= '/home/douglas/s3.archive.org-accesskey'
502 #When it is necessary to creat a navpoint ID, use this string.
503 NAVPOINT_ID_TEMPLATE
= 'chapter%s'
505 CLAIM_UNAUTHORED
= False
507 IMG_CACHE
= 'cache/images/'
509 USE_IMG_CACHE_ALWAYS_HOSTS
= ['objavi.halo.gen.nz']
510 USE_ZIP_CACHE_ALWAYS_HOSTS
= ['objavi.halo.gen.nz']
512 IGNORABLE_TWIKI_BOOKS
= ('Main', 'TWiki', 'PR', 'Trash', 'Sandbox')
514 WHITESPACE_AND_NULL
= ''.join(chr(_x
) for _x
in range(33))
516 #how big to let epub chapters get before splitting?
517 #sony reader has 100k compressed/300k uncompressed limit, but lets leave room to move.
518 EPUB_COMPRESSED_SIZE_MAX
= 70000
519 EPUB_FILE_SIZE_MAX
= 200000
521 #used to identify marker tags in html
522 MARKER_CLASS_SPLIT
= "espri-marker-name-clash-with-no-one--split"
523 MARKER_CLASS_INFO
= "espri-marker-name-clash-with-no-one--info"
525 if __name__
== '__main__':
526 print ', '.join(x
for x
in globals().keys() if not x
.startswith('_'))