Less strange line wrapping in form
[objavi2.git] / config.py
blob51ddf655a17593db18adff1e2eeec2dfef0238cc
1 # Part of Objavi2, which makes pdf versions of FLOSSManuals books.
2 # This python module contains or encapsulates configuration and
3 # constant data.
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.
22 """
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
29 INCH_2_POINT = 72
31 KEEP_TEMP_FILES=True
32 TMPDIR = 'tmp'
34 FIREFOX = 'firefox'
35 WKHTMLTOPDF = '/usr/local/bin/wkhtmltopdf-static'
36 WKHTMLTOPDF_EXTRA_COMMANDS = []
37 #WKHTMLTOPDF_EXTRA_COMMANDS = ['--outline', '-t']
38 HTML2ODT = './html2odt'
41 #CGITB_DOMAINS = ('203.97.236.46', '202.78.240.7')
42 CGITB_DOMAINS = False
44 #bookland is used to make isbn barcodes
45 BOOKLAND = 'bookland/bookland'
47 # how many pages to number in one pdfedit process (which has
48 # exponential memory leak)
49 PDFEDIT_MAX_PAGES = 40
51 #keep book lists around for this time without refetching
52 BOOK_LIST_CACHE = 3600 * 2
53 BOOK_LIST_CACHE_DIR = 'cache'
55 TOC_URL = "http://%s/pub/%s/_index/TOC.txt"
56 BOOK_URL = "http://%s/bin/view/%s/_all?skin=text"
57 PUBLISH_URL = "/books/"
59 #leave out vowels so as to avoid accidental words, and punctuation for bidi consistency
60 CHAPTER_COOKIE_CHARS = 'BCDFGHJKLMNPQRSTVWXYZ'
62 DEFAULT_SERVER = 'en.flossmanuals.net'
63 DEFAULT_SIZE = 'COMICBOOK'
64 DEFAULT_ENGINE = 'webkit'
65 #DEFAULT_MODE = None
67 RTL_SCRIPTS = ['persian', 'arabic', 'hebrew', 'urdu']
69 USE_TAGS_FOR_CONTENTS = False
71 TRY_BOOK_CLEANUP_ON_DEL = False
73 SERVER_DEFAULTS = {
74 'en.flossmanuals.net': {
75 'css-book': 'static/en.flossmanuals.net.css',
76 'css-web': 'static/en.flossmanuals.net-web.css',
77 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
78 'css-openoffice': 'static/en.flossmanuals.net-openoffice.css',
79 'lang': 'en',
80 'dir': 'LTR',
82 'fr.flossmanuals.net': {
83 'css-book': 'static/fr.flossmanuals.net.css',
84 'css-web': 'static/fr.flossmanuals.net-web.css',
85 'css-newspaper': 'static/fr.flossmanuals.net-newspaper.css',
86 'css': 'static/fr.flossmanuals.net.css',
87 'css-openoffice': 'static/fr.flossmanuals.net-openoffice.css',
88 'lang': 'fr',
89 'dir': 'LTR',
91 'translate.flossmanuals.net': {
92 'css-book': 'static/translate.flossmanuals.net.css',
93 'css-web': 'static/translate.flossmanuals.net-web.css',
94 'css-newspaper': 'static/translate.flossmanuals.net-newspaper.css',
95 'css': 'static/translate.flossmanuals.net.css',
96 'css-openoffice': 'static/translate.flossmanuals.net-openoffice.css',
97 'lang': 'translate',
98 'dir': 'LTR',
100 'nl.flossmanuals.net': {
101 'css-book': 'static/nl.flossmanuals.net.css',
102 'css-web': 'static/nl.flossmanuals.net-web.css',
103 'css-newspaper': 'static/nl.flossmanuals.net-newspaper.css',
104 'css': 'static/nl.flossmanuals.net.css',
105 'css-openoffice': 'static/nl.flossmanuals.net-openoffice.css',
106 'lang': 'nl',
107 'dir': 'LTR',
109 'bn.flossmanuals.net': {
110 'css-book': 'static/bn.flossmanuals.net.css',
111 'css-web': 'static/bn.flossmanuals.net-web.css',
112 'css-newspaper': 'static/bn.flossmanuals.net-newspaper.css',
113 'css': 'static/bn.flossmanuals.net.css',
114 'css-openoffice': 'static/bn.flossmanuals.net-openoffice.css',
115 'lang': 'bn',
116 'dir': 'LTR',
118 'fa.flossmanuals.net': {
119 'css-book': 'static/fa.flossmanuals.net.css',
120 'css-web': 'static/fa.flossmanuals.net-web.css',
121 'css-newspaper': 'static/fa.flossmanuals.net-newspaper.css',
122 'css': 'static/fa.flossmanuals.net.css',
123 'css-openoffice': 'static/fa.flossmanuals.net-openoffice.css',
124 'lang': 'fa',
125 'dir': 'RTL',
129 # uncomment a debug mode to get messages about that topic.
130 DEBUG_MODES = (
131 #'STARTUP',
132 #'INDEX',
133 #'PDFEDIT',
134 #'PDFGEN',
135 #'HTMLGEN',
137 DEBUG_ALL = False
139 #convert all sizes to points
140 PAPER_SIZES = [(s, x * MM_2_POINT, y * MM_2_POINT) for s, x, y in (
141 ("A5", 148, 210),
142 #("B5", 176, 250),
143 ("A4", 210, 297),
144 #("B4", 250, 353),
145 ("A3", 297, 420),
146 #("B3", 353, 500),
147 ("A2", 420, 594),
148 #("B2", 500, 707),
149 ("A1", 594, 841),
150 #("B1", 707, 1000),
151 ("A0", 841, 1189),
152 ("B0", 1000, 1414),
155 # margins are BASE_MARGIN + PROPORTIONAL_MARGIN * min(width, height)
156 BASE_MARGIN = 22
157 PROPORTIONAL_MARGIN = 0.04
158 # gutter is BASE_GUTTER + PROPORTIONAL_GUTTER * width
159 BASE_GUTTER = 15
160 PROPORTIONAL_GUTTER = 0.011
162 PAGE_EXTREMA = {
163 'page_width': (1, 1000, MM_2_POINT),
164 'page_height': (1, 1414, MM_2_POINT), #can't be bigger than biggest PAPER_SIZE
165 'gutter': (-1000, 1000, MM_2_POINT),
166 'top_margin': (0, 1500, MM_2_POINT),
167 'side_margin': (0, 1500, MM_2_POINT),
168 'bottom_margin': (0, 1500, MM_2_POINT),
169 "columns": (1, 12, 1),
170 "column_margin": (0, 1000, MM_2_POINT),
173 PAGE_NUMBER_SIZE = 11 #XXX this is not used by pdfedit! (ie, it is a guess)
175 PAGE_SIZE_DATA = {
176 'COMICBOOK': {'pointsize': ((6.625 * 72), (10.25 * 72)), 'class': "lulu"},
177 "POCKET": {'pointsize': (4.25 * 72, 6.875 * 72), 'class': "lulu"},
179 "USLETTER": {'pointsize': (8.5 * 72, 11 * 72), 'class': "lulu"},
180 "USTRADE": {'pointsize': (6 * 72, 9 * 72), 'class': "lulu"},
181 "LANDSCAPE9x7": {'pointsize': (9 * 72, 7 * 72), 'class': "lulu"},
182 "SQUARE7.5": {'pointsize': (7.5 * 72, 7.5 * 72), 'class': "lulu"},
183 "ROYAL": {'pointsize': (6.139 * 72, 9.21 * 72), 'class': "lulu"},
184 "CROWNQUARTO": {'pointsize': (7.444 * 72, 9.681 * 72), 'class': "lulu"},
185 "SQUARE8.5": {'pointsize': (8.5 * 72, 8.5 * 72), 'class': "lulu"},
187 "A5": {'pointsize': (148 * MM_2_POINT, 210 * MM_2_POINT), 'class': "lulu iso"},
188 "A4": {'pointsize': (210 * MM_2_POINT, 297 * MM_2_POINT), 'class': "lulu iso"},
189 "A3 (NZ Tabloid)": {'pointsize': (297 * MM_2_POINT, 420 * MM_2_POINT), 'class': 'iso newspaper'},
190 "A2 (NZ Broadsheet)": {'pointsize': (420 * MM_2_POINT, 594 * MM_2_POINT), 'class': 'iso newspaper'},
191 "A1": {'pointsize': (594 * MM_2_POINT, 841 * MM_2_POINT), 'class': 'iso'},
192 "B4": {'pointsize': (250 * MM_2_POINT, 353 * MM_2_POINT), 'class': 'iso'},
193 "B3": {'pointsize': (353 * MM_2_POINT, 500 * MM_2_POINT), 'class': 'iso'},
194 "B2": {'pointsize': (500 * MM_2_POINT, 707 * MM_2_POINT), 'class': 'iso'},
195 "B1": {'pointsize': (707 * MM_2_POINT, 1000 * MM_2_POINT), 'class': 'iso'},
197 "UK Tabloid": {'pointsize': (11 * INCH_2_POINT, 17 * INCH_2_POINT), 'class': 'newspaper'},
198 "UK Broadsheet": {'pointsize': (18 * INCH_2_POINT, 24 * INCH_2_POINT), 'class': 'newspaper'},
199 "US Broadsheet": {'pointsize': (15 * INCH_2_POINT, 22.75 * INCH_2_POINT), 'class': 'newspaper'},
200 "Berliner" : {'pointsize': (315 * MM_2_POINT, 470 * MM_2_POINT), 'class': 'newspaper'},
201 "Foolscap (F4)": {'pointsize': (210 * MM_2_POINT, 330 * MM_2_POINT)},
202 #"Foolscap Folio": {'pointsize': (8.5 * INCH_2_POINT, 13.5 * INCH_2_POINT)},
204 "custom": {'class': "custom"},
207 PAGE_MIN_SIZE = (1.0, 1.0)
208 PAGE_MAX_SIZE = (3000.0, 3000.0)
210 MIN_COLUMN_WIDTH = (110 * MM_2_POINT)
212 ENGINES = {
213 'webkit' : [],
214 #'gecko' : [],
217 INSIDE_FRONT_COVER_TEMPLATE = 'templates/inside-front-cover.%s.html'
218 END_MATTER_TEMPLATE = 'templates/end_matter.%s.html'
220 FONT_LIST_INCLUDE = 'cache/font-list.inc'
221 FONT_LIST_URL = '/font-list.cgi.pdf'
222 FONT_EXAMPLE_SCRIPT_DIR = 'templates/font-list'
224 # for the license field, with a view to making it a drop down.
225 LICENSES = ('GPL', 'GPLv2', 'GPLv2+', 'GPLv3', 'GPLv3+', 'LGPL', 'LGPLv2.1',
226 'BSD', 'public domain', 'MIT', 'Artistic', 'CC-BY', 'CC-BY-SA')
228 DEFAULT_LICENSE = 'GPLv2+'
230 CGI_MODES = { # arguments are: (publication, )
231 'book': (True,),
232 'newspaper': (True,),
233 'web': (True,),
234 'openoffice': (True,),
235 'booklist': (False,),
236 'css': (False,),
237 'form': (False,),
240 DEFAULT_MODE = 'book'
243 FORM_INPUTS = (
244 # input, name, input type, contents key, CSS classes, extra text
245 ("server", "FLOSS Manuals server", "select", "server_options", "", ""),
246 ("book", "Manual", "select", "book_options", "", ""),
247 ("title", "Book title", "input[type=text]", None, "", ""),
248 ("license", "License", "select", "licenses", "", ""),
250 ("mode", "Document type", "select", "pdf_types", "advanced openoffice", ""),
251 ("isbn", "ISBN", "input[type=text]", None, "advanced", "(13 digits)"),
253 ("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>)'),
254 ("page_width", "Page width", "input[type=text]", None, "advanced booksize numeric-field", ""),
255 ("page_height", "Page height", "input[type=text]", None, "advanced booksize numeric-field", ""),
257 ("top_margin", "Top margin", "input[type=text]", None, "advanced margins numeric-field", ""),
258 ("side_margin", "Side margin", "input[type=text]", None, "advanced margins numeric-field", ""),
259 ("bottom_margin", "Bottom margin", "input[type=text]", None, "advanced margins numeric-field", ""),
260 ("gutter", "Gutter", "input[type=text]", None, "advanced margins numeric-field", ""),
262 ("columns", "Columns", "input[type=text]", None, "advanced columns numeric-field", ""),
263 ("column_margin", "Column margin", "input[type=text]", None, "advanced columns numeric-field", ""),
265 ("grey_scale", "Grey-scale", "input[type=checkbox]", 'yes', "advanced", "(for black and white printing)"),
267 #("css_customise", "Customise CSS", "input[type=checkbox]", None, "advanced", "Enter a URL or "),
268 ("css-url", "CSS URL", "input[type=text][disabled]", "css_url", "advanced css-url openoffice", ""),
269 ("font_list", "Available fonts", "ul", "font_list", "advanced css-custom openoffice", ""),
270 ("font_links", "Font examples", "ul", "font_links", "advanced css-custom openoffice", ""),
271 ("css", "CSS", "textarea", "css", "advanced css-custom openoffice", ""),
273 ("rotate", "Rotate pages for binding", "input[type=checkbox]", 'yes', "advanced", "(for RTL books on LTR printing presses, and vice versa)."),
274 #("engine", "Layout engine", "select", "engines", "advanced", ""),
275 #("header", "Header Text", "input[type=text]", None, "advanced", ""),
278 FORM_ELEMENT_TYPES = {
279 'input[type=text]' : '<input type="text" id="%(id)s" name="%(id)s" value="%(val)s" />',
280 'input[type=text][disabled]' : '<input type="text" disabled="disabled" id="%(id)s" name="%(id)s" value="%(val)s" />',
281 'input[type=checkbox]' : '<input type="checkbox" id="%(id)s" name="%(id)s" value="%(val)s" />',
282 'textarea' : '<textarea id="%(id)s" name="%(id)s">%(val)s</textarea>',
283 'select': '<select id="%(id)s" name="%(id)s">%(val)s</select>',
284 'ul': '<ul id="%(id)s">%(val)s</ul>',
287 PROGRESS_POINTS = (
288 ("__init__", "Initialise the book", ('book', 'newspaper', 'web', 'openoffice')),
289 ("load_book", "Fetch the book", ('book', 'newspaper', 'web', 'openoffice')),
290 ("load_toc", "Fetch TOC metadata", ('book', 'newspaper', 'web', 'openoffice')),
291 ("add_css", "Add css", ('book', 'newspaper', 'web', 'openoffice')),
292 ("add_section_titles", "Add section titles", ('book', 'newspaper', 'web', 'openoffice')),
293 ("make_oo_doc", "Make the OpenOffice document", ('openoffice',)),
294 ("generate_pdf", "Generate the main pdf", ('book', 'newspaper', 'web')),
295 ("extract_pdf_outline", "Find page numbers", ('book',)),
296 ("reshape_pdf", "Cut pages to size", ('book', 'newspaper',)),
297 #('make_body_pdf', "Generate the main pdf", ('book', 'newspaper', 'web')),
298 ("number_pdf", "Number pages", ('book', 'newspaper',)),
299 ("make_contents", "Calculate Table of Contents", ('book',)),
300 ("make_preamble_pdf", "Generate preamble pdf", ('book',)),
301 ('make_end_matter_pdf', "Generate end matter pdf", ('book',)),
302 ("concatenated_pdfs", "concatenate the pdfs", ('book',)),
303 #("publish_pdf", "Publish the pdf", ('book', 'newspaper', 'web')),
304 ("finished", "Finished!", ('book', 'newspaper', 'web', 'openoffice')),
307 if __name__ == '__main__':
308 print ', '.join(x for x in globals().keys() if not x.startswith('_'))