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 #Not really configurable (72 pt per inch / 25.4 mm per inch)
27 POINT_2_MM
= 25.4 / 72.0
28 MM_2_POINT
= 72.0 / 25.4
35 BOOKI_BOOK_DIR
= 'booki-books'
38 WKHTMLTOPDF
= '/usr/local/bin/wkhtmltopdf-static'
39 WKHTMLTOPDF_EXTRA_COMMANDS
= []
40 #WKHTMLTOPDF_EXTRA_COMMANDS = ['--outline', '-t']
41 HTML2ODT
= './html2odt'
44 #CGITB_DOMAINS = ('203.97.236.46', '202.78.240.7')
47 #bookland is used to make isbn barcodes
48 BOOKLAND
= 'bookland/bookland'
50 # how many pages to number in one pdfedit process (which has
51 # exponential memory leak)
52 PDFEDIT_MAX_PAGES
= 40
54 #keep book lists around for this time without refetching
55 BOOK_LIST_CACHE
= 3600 * 2
56 BOOK_LIST_CACHE_DIR
= 'cache'
58 TOC_URL
= "http://%s/pub/%s/_index/TOC.txt"
59 BOOK_URL
= "http://%s/bin/view/%s/_all?skin=text"
60 CHAPTER_URL
= "http://%s/bin/view/%s/%s?skin=text"
61 PUBLISH_URL
= "/books/"
63 TWIKI_GATEWAY_URL
= 'http://%s/booki-twiki-gateway.cgi?server=%s&book=%s&mode=zip'
64 BOOKI_ZIP_URL
= 'http://%(server)s/%(project)s/%(book)s/export'
66 #leave out vowels so as to avoid accidental words, and punctuation for bidi consistency
67 CHAPTER_COOKIE_CHARS
= 'BCDFGHJKLMNPQRSTVWXYZ'
69 DEFAULT_SERVER
= 'en.flossmanuals.net'
70 BOOKI_SERVER
= 'booki.flossmanuals.net'
71 DEFAULT_SIZE
= 'COMICBOOK'
72 DEFAULT_ENGINE
= 'webkit'
75 RTL_SCRIPTS
= ['persian', 'arabic', 'hebrew', 'urdu']
77 USE_CACHED_IMAGES
= False
79 #Normally, Book objects try to shutdown subprocesses and clean up temp
80 #files when they __exit__. This flag makes them try when they __del__
81 #too (i.e. when they are garbage collected).
82 TRY_BOOK_CLEANUP_ON_DEL
= False
84 LOCALHOST
= 'localhost'
87 'booki.flossmanuals.net': {
88 'css-book': 'static/en.flossmanuals.net.css',
89 'css-web': 'static/en.flossmanuals.net-web.css',
90 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
91 'css-openoffice': 'static/en.flossmanuals.net-openoffice.css',
94 'toc-encoding': 'iso-8859-1',
99 'css-book': 'static/en.flossmanuals.net.css',
100 'css-web': 'static/en.flossmanuals.net-web.css',
101 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
102 'css-openoffice': 'static/en.flossmanuals.net-openoffice.css',
105 'toc-encoding': 'iso-8859-1',
107 'interface': 'local',
109 'en.flossmanuals.net': {
110 'css-book': 'static/en.flossmanuals.net.css',
111 'css-web': 'static/en.flossmanuals.net-web.css',
112 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
113 'css-openoffice': 'static/en.flossmanuals.net-openoffice.css',
116 'toc-encoding': None,
118 'interface': 'TWiki',
120 'fr.flossmanuals.net': {
121 'css-book': 'static/fr.flossmanuals.net.css',
122 'css-web': 'static/fr.flossmanuals.net-web.css',
123 'css-newspaper': 'static/fr.flossmanuals.net-newspaper.css',
124 'css': 'static/fr.flossmanuals.net.css',
125 'css-openoffice': 'static/fr.flossmanuals.net-openoffice.css',
128 'toc-encoding': 'iso-8859-1',
130 'interface': 'TWiki',
132 'translate.flossmanuals.net': {
133 'css-book': 'static/translate.flossmanuals.net.css',
134 'css-web': 'static/translate.flossmanuals.net-web.css',
135 'css-newspaper': 'static/translate.flossmanuals.net-newspaper.css',
136 'css': 'static/translate.flossmanuals.net.css',
137 'css-openoffice': 'static/translate.flossmanuals.net-openoffice.css',
140 'toc-encoding': 'iso-8859-1',
142 'interface': 'TWiki',
144 'nl.flossmanuals.net': {
145 'css-book': 'static/nl.flossmanuals.net.css',
146 'css-web': 'static/nl.flossmanuals.net-web.css',
147 'css-newspaper': 'static/nl.flossmanuals.net-newspaper.css',
148 'css': 'static/nl.flossmanuals.net.css',
149 'css-openoffice': 'static/nl.flossmanuals.net-openoffice.css',
152 'toc-encoding': 'iso-8859-1',
154 'interface': 'TWiki',
156 'bn.flossmanuals.net': {
157 'css-book': 'static/bn.flossmanuals.net.css',
158 'css-web': 'static/bn.flossmanuals.net-web.css',
159 'css-newspaper': 'static/bn.flossmanuals.net-newspaper.css',
160 'css': 'static/bn.flossmanuals.net.css',
161 'css-openoffice': 'static/bn.flossmanuals.net-openoffice.css',
164 'toc-encoding': 'iso-8859-1',
166 'interface': 'TWiki',
168 'fa.flossmanuals.net': {
169 'css-book': 'static/fa.flossmanuals.net.css',
170 'css-web': 'static/fa.flossmanuals.net-web.css',
171 'css-newspaper': 'static/fa.flossmanuals.net-newspaper.css',
172 'css': 'static/fa.flossmanuals.net.css',
173 'css-openoffice': 'static/fa.flossmanuals.net-openoffice.css',
176 'toc-encoding': 'iso-8859-1',
178 'interface': 'TWiki',
182 # uncomment a debug mode to get messages about that topic.
192 #convert all sizes to points
193 PAPER_SIZES
= [(s
, x
* MM_2_POINT
, y
* MM_2_POINT
) for s
, x
, y
in (
208 # margins are BASE_MARGIN + PROPORTIONAL_MARGIN * min(width, height)
210 PROPORTIONAL_MARGIN
= 0.04
211 # gutter is BASE_GUTTER + PROPORTIONAL_GUTTER * width
213 PROPORTIONAL_GUTTER
= 0.011
216 'page_width': (1, 1000, MM_2_POINT
),
217 'page_height': (1, 1414, MM_2_POINT
), #can't be bigger than biggest PAPER_SIZE
218 'gutter': (-1000, 1000, MM_2_POINT
),
219 'top_margin': (0, 1500, MM_2_POINT
),
220 'side_margin': (0, 1500, MM_2_POINT
),
221 'bottom_margin': (0, 1500, MM_2_POINT
),
222 "columns": (1, 12, 1),
223 "column_margin": (0, 1000, MM_2_POINT
),
226 PAGE_NUMBER_SIZE
= 11 #XXX this is not used by pdfedit! (ie, it is a guess)
229 'COMICBOOK': {'pointsize': ((6.625 * 72), (10.25 * 72)), 'class': "lulu"},
230 "POCKET": {'pointsize': (4.25 * 72, 6.875 * 72), 'class': "lulu"},
232 "USLETTER": {'pointsize': (8.5 * 72, 11 * 72), 'class': "lulu"},
233 "USTRADE": {'pointsize': (6 * 72, 9 * 72), 'class': "lulu"},
234 "LANDSCAPE9x7": {'pointsize': (9 * 72, 7 * 72), 'class': "lulu"},
235 "SQUARE7.5": {'pointsize': (7.5 * 72, 7.5 * 72), 'class': "lulu"},
236 "ROYAL": {'pointsize': (6.139 * 72, 9.21 * 72), 'class': "lulu"},
237 "CROWNQUARTO": {'pointsize': (7.444 * 72, 9.681 * 72), 'class': "lulu"},
238 "SQUARE8.5": {'pointsize': (8.5 * 72, 8.5 * 72), 'class': "lulu"},
240 "A5": {'pointsize': (148 * MM_2_POINT
, 210 * MM_2_POINT
), 'class': "lulu iso"},
241 "A4": {'pointsize': (210 * MM_2_POINT
, 297 * MM_2_POINT
), 'class': "lulu iso"},
242 "A3 (NZ Tabloid)": {'pointsize': (297 * MM_2_POINT
, 420 * MM_2_POINT
), 'class': 'iso newspaper'},
243 "A2 (NZ Broadsheet)": {'pointsize': (420 * MM_2_POINT
, 594 * MM_2_POINT
), 'class': 'iso newspaper'},
244 "A1": {'pointsize': (594 * MM_2_POINT
, 841 * MM_2_POINT
), 'class': 'iso'},
245 "B4": {'pointsize': (250 * MM_2_POINT
, 353 * MM_2_POINT
), 'class': 'iso'},
246 "B3": {'pointsize': (353 * MM_2_POINT
, 500 * MM_2_POINT
), 'class': 'iso'},
247 "B2": {'pointsize': (500 * MM_2_POINT
, 707 * MM_2_POINT
), 'class': 'iso'},
248 "B1": {'pointsize': (707 * MM_2_POINT
, 1000 * MM_2_POINT
), 'class': 'iso'},
250 "UK Tabloid": {'pointsize': (11 * INCH_2_POINT
, 17 * INCH_2_POINT
), 'class': 'newspaper'},
251 "UK Broadsheet": {'pointsize': (18 * INCH_2_POINT
, 24 * INCH_2_POINT
), 'class': 'newspaper'},
252 "US Broadsheet": {'pointsize': (15 * INCH_2_POINT
, 22.75 * INCH_2_POINT
), 'class': 'newspaper'},
253 "Berliner" : {'pointsize': (315 * MM_2_POINT
, 470 * MM_2_POINT
), 'class': 'newspaper'},
254 "Foolscap (F4)": {'pointsize': (210 * MM_2_POINT
, 330 * MM_2_POINT
)},
256 "Oamaru Broadsheet":{'pointsize': (382 * MM_2_POINT
, 540 * MM_2_POINT
), 'class': 'newspaper'},
257 "Oamaru Tabloid": {'pointsize': (265 * MM_2_POINT
, 380 * MM_2_POINT
), 'class': 'newspaper'},
259 #ODT printable 380x560
263 "custom": {'class': "custom"},
266 PAGE_MIN_SIZE
= (1.0, 1.0)
267 PAGE_MAX_SIZE
= (3000.0, 3000.0)
269 MIN_COLUMN_WIDTH
= (110 * MM_2_POINT
)
276 INSIDE_FRONT_COVER_TEMPLATE
= 'templates/inside-front-cover.%s.html'
277 END_MATTER_TEMPLATE
= 'templates/end_matter.%s.html'
279 FONT_LIST_INCLUDE
= 'cache/font-list.inc'
280 FONT_LIST_URL
= '/font-list.cgi.pdf'
281 FONT_EXAMPLE_SCRIPT_DIR
= 'templates/font-list'
283 # for the license field, with a view to making it a drop down.
285 'GPL': 'http://www.gnu.org/licenses/gpl.txt',
286 'GPLv2': 'http://www.gnu.org/licenses/gpl-2.0.txt',
287 'GPLv2+': 'http://www.gnu.org/licenses/gpl-2.0.txt',
288 'GPLv3': 'http://www.gnu.org/licenses/gpl-3.0.txt',
289 'GPLv3+': 'http://www.gnu.org/licenses/gpl-3.0.txt',
290 'LGPL': 'http://www.gnu.org/licenses/lgpl.txt',
291 'LGPLv2.1': 'http://www.gnu.org/licenses/lgpl-2.1.txt',
292 'LGPLv3': 'http://www.gnu.org/licenses/lgpl-3.0.txt',
293 'BSD': 'http://www.debian.org/misc/bsd.license',
294 'public domain': None,
295 'MIT': 'http://www.opensource.org/licenses/mit-license.html',
296 'Artistic': 'http://dev.perl.org/licenses/artistic.html',
297 'CC-BY': 'http://creativecommons.org/licenses/by/3.0/',
298 'CC-BY-SA': 'http://creativecommons.org/licenses/by-sa/3.0/',
301 DEFAULT_LICENSE
= 'GPLv2+'
303 CGI_MODES
= { # arguments are: (publication, )
305 'newspaper': (True,),
307 'openoffice': (True,),
308 'booklist': (False,),
313 DEFAULT_MODE
= 'book'
315 EPUB_DESTINATIONS
= {
320 DEFAULT_EPUB_DESTINATION
= 'html'
324 # input, name, input type, contents key, CSS classes, extra text
325 ("server", "FLOSS Manuals server", "select", "server_options", "", ""),
326 ("book", "Manual", "select", "book_options", "", ""),
327 ("title", "Book title", "input[type=text]", None, "", ""),
328 ("license", "License", "select", "licenses", "", ""),
330 ("mode", "Document type", "select", "pdf_types", "advanced openoffice", ""),
331 ("isbn", "ISBN", "input[type=text]", None, "advanced", "(13 digits)"),
333 ("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>)'),
334 ("page_width", "Page width", "input[type=text]", None, "advanced booksize numeric-field", ""),
335 ("page_height", "Page height", "input[type=text]", None, "advanced booksize numeric-field", ""),
337 ("top_margin", "Top margin", "input[type=text]", None, "advanced margins numeric-field", ""),
338 ("side_margin", "Side margin", "input[type=text]", None, "advanced margins numeric-field", ""),
339 ("bottom_margin", "Bottom margin", "input[type=text]", None, "advanced margins numeric-field", ""),
340 ("gutter", "Gutter", "input[type=text]", None, "advanced margins numeric-field", ""),
342 ("columns", "Columns", "input[type=text]", None, "advanced columns numeric-field", ""),
343 ("column_margin", "Column margin", "input[type=text]", None, "advanced columns numeric-field", ""),
345 ("grey_scale", "Grey-scale", "input[type=checkbox]", 'yes', "advanced", "(for black and white printing)"),
347 #("css_customise", "Customise CSS", "input[type=checkbox]", None, "advanced", "Enter a URL or "),
348 ("css-url", "CSS URL", "input[type=text][disabled]", "css_url", "advanced css-url openoffice", ""),
349 ("font_list", "Available fonts", "ul", "font_list", "advanced css-custom openoffice", ""),
350 ("font_links", "Font examples", "ul", "font_links", "advanced css-custom openoffice", ""),
351 ("css", "CSS", "textarea", "css", "advanced css-custom openoffice", ""),
353 ("rotate", "Rotate pages for binding", "input[type=checkbox]", 'yes', "advanced", "(for RTL books on LTR printing presses, and vice versa)."),
354 #("engine", "Layout engine", "select", "engines", "advanced", ""),
355 #("header", "Header Text", "input[type=text]", None, "advanced", ""),
358 FORM_ELEMENT_TYPES
= {
359 'input[type=text]' : '<input type="text" id="%(id)s" name="%(id)s" value="%(val)s" />',
360 'input[type=text][disabled]' : '<input type="text" disabled="disabled" id="%(id)s" name="%(id)s" value="%(val)s" />',
361 'input[type=checkbox]' : '<input type="checkbox" id="%(id)s" name="%(id)s" value="%(val)s" />',
362 'textarea' : '<textarea id="%(id)s" name="%(id)s">%(val)s</textarea>',
363 'select': '<select id="%(id)s" name="%(id)s">%(val)s</select>',
364 'ul': '<ul id="%(id)s">%(val)s</ul>',
368 ("__init__", "Initialise the book", ('book', 'newspaper', 'web', 'openoffice', 'epub')),
369 ("load_book", "Fetch the book", ('book', 'newspaper', 'web', 'openoffice')),
370 ("load_toc", "Fetch TOC metadata", ('book', 'newspaper', 'web', 'openoffice')),
371 ("add_css", "Add css", ('book', 'newspaper', 'web', 'openoffice')),
372 ("add_section_titles", "Add section titles", ('book', 'newspaper', 'web', 'openoffice')),
373 ("make_epub", "Make the epub file", ('epub',)),
374 ("make_oo_doc", "Make the OpenOffice document", ('openoffice',)),
375 ("generate_pdf", "Generate the main pdf", ('book', 'newspaper', 'web')),
376 ("extract_pdf_outline", "Find page numbers", ('book',)),
377 ("reshape_pdf", "Cut pages to size", ('book', 'newspaper',)),
378 #('make_body_pdf', "Generate the main pdf", ('book', 'newspaper', 'web')),
379 ("number_pdf", "Number pages", ('book', 'newspaper',)),
380 ("make_contents", "Calculate Table of Contents", ('book',)),
381 ("make_preamble_pdf", "Generate preamble pdf", ('book',)),
382 ('make_end_matter_pdf', "Generate end matter pdf", ('book',)),
383 ("concatenated_pdfs", "concatenate the pdfs", ('book',)),
384 #("publish_pdf", "Publish the pdf", ('book', 'newspaper', 'web')),
385 ("finished", "Finished!", ('book', 'newspaper', 'web', 'openoffice', 'epub')),
389 DCNS
= "{http://purl.org/dc/elements/1.1/}"
390 DC
= "http://purl.org/dc/elements/1.1/"
391 XHTMLNS
= '{http://www.w3.org/1999/xhtml}'
392 XHTML
= 'http://www.w3.org/1999/xhtml'
394 S3_SECRET
= '/home/douglas/s3.archive.org-secret'
395 S3_ACCESSKEY
= '/home/douglas/s3.archive.org-accesskey'
397 #When it is necessary to creat a navpoint ID, use this string.
398 NAVPOINT_ID_TEMPLATE
= 'chapter%s'
400 CLAIM_UNAUTHORED
= False
402 USE_CACHE_ALWAYS_HOSTS
= ['objavi.halo.gen.nz']
404 IGNORABLE_TWIKI_BOOKS
= ('Main', 'TWiki', 'PR', 'Trash', 'Sandbox')
406 if __name__
== '__main__':
407 print ', '.join(x
for x
in globals().keys() if not x
.startswith('_'))