Index: trunk/extensions/Collection/Collection.body.php |
— | — | @@ -518,10 +518,12 @@ |
519 | 519 | global $wgServer; |
520 | 520 | global $wgScriptPath; |
521 | 521 | |
522 | | - $response = self::pdfServerCommand( 'pdf_generate', array( |
| 522 | + $response = self::pdfServerCommand( 'render', array( |
523 | 523 | 'metabook' => $this->buildJSONCollection( $collection ), |
524 | 524 | 'base_url' => $wgServer . $wgScriptPath, |
525 | 525 | 'template_blacklist' => $wgPDFTemplateBlacklist, |
| 526 | + 'writer' => 'rl', |
| 527 | + 'content_type' => 'application/pdf', |
526 | 528 | ) ); |
527 | 529 | |
528 | 530 | if ( !$response ) { |
— | — | @@ -544,7 +546,7 @@ |
545 | 547 | $collection_id = $wgRequest->getVal( 'collection_id' ); |
546 | 548 | $return_to = $wgRequest->getVal( 'return_to' ); |
547 | 549 | |
548 | | - $response = self::pdfServerCommand( 'pdf_status', array( |
| 550 | + $response = self::pdfServerCommand( 'render_status', array( |
549 | 551 | 'collection_id' => $collection_id, |
550 | 552 | ) ); |
551 | 553 | if ( !$response ) { |
— | — | @@ -563,7 +565,7 @@ |
564 | 566 | ); |
565 | 567 | $wgOut->addMeta( 'http:refresh', '2; URL=' . $url ); |
566 | 568 | $wgOut->setPageTitle( wfMsg( 'coll-generating_pdf_title' ) ); |
567 | | - $wgOut->addWikiText( wfMsgNoTrans( 'coll-generating_pdf_text', $response->progress ) ); |
| 569 | + $wgOut->addWikiText( wfMsgNoTrans( 'coll-generating_pdf_text', $response->status->progress ) ); |
568 | 570 | break; |
569 | 571 | case 'finished': |
570 | 572 | $wgOut->setPageTitle( wfMsg( 'coll-pdf_finished_title' ) ); |
— | — | @@ -592,7 +594,7 @@ |
593 | 595 | global $wgOut; |
594 | 596 | global $wgRequest; |
595 | 597 | |
596 | | - $response = self::pdfServerCommand( 'pdf_download', array( |
| 598 | + $response = self::pdfServerCommand( 'download', array( |
597 | 599 | 'collection_id' => $wgRequest->getVal( 'collection_id' ), |
598 | 600 | ), $decode=false ); |
599 | 601 | |
Index: trunk/extensions/Collection/pdf-server/pdfserver.py |
— | — | @@ -14,11 +14,11 @@ |
15 | 15 | # accompanied script clean-cache.py. |
16 | 16 | cache_dir = '/var/cache/pdfserver/' |
17 | 17 | |
18 | | -# (Path to) mw-pdf executable. |
19 | | -mwpdf_cmd = 'mw-pdf' |
| 18 | +# (Path to) mw-render executable. |
| 19 | +mwrender_cmd = 'mw-render' |
20 | 20 | |
21 | | -# Logfile for mw-pdf. |
22 | | -mwpdf_logfile = '/var/log/mw-pdf.log' |
| 21 | +# Logfile for mw-render. |
| 22 | +mwrender_logfile = '/var/log/mw-render.log' |
23 | 23 | |
24 | 24 | # (Path to) mw-zip executable. |
25 | 25 | mwzip_cmd = 'mw-zip' |
— | — | @@ -48,7 +48,6 @@ |
49 | 49 | import StringIO |
50 | 50 | import subprocess |
51 | 51 | import time |
52 | | -import urllib |
53 | 52 | |
54 | 53 | def uid(max_length=10): |
55 | 54 | f = StringIO.StringIO() |
— | — | @@ -60,9 +59,10 @@ |
61 | 60 | |
62 | 61 | class PDFServer(object): |
63 | 62 | metabook_filename = 'metabook.json' |
64 | | - pdf_filename = 'collection.pdf' |
| 63 | + contenttype_filename = 'content_type.txt' |
65 | 64 | error_filename = 'errors.txt' |
66 | | - progress_filename = 'progress.txt' |
| 65 | + status_filename = 'status.txt' |
| 66 | + output_filename = 'output' |
67 | 67 | |
68 | 68 | def __init__(self, form): |
69 | 69 | self.form = form |
— | — | @@ -133,14 +133,20 @@ |
134 | 134 | print # end of headers |
135 | 135 | print content, |
136 | 136 | |
137 | | - def do_pdf_generate(self): |
| 137 | + def do_render(self): |
138 | 138 | metabook_data = self.form.getvalue('metabook') |
139 | 139 | if not metabook_data: |
140 | 140 | return self.error_response('metabook argument required') |
141 | 141 | base_url = self.form.getvalue('base_url') |
142 | 142 | if not base_url: |
143 | 143 | return self.error_response('base_url argument required') |
144 | | - |
| 144 | + writer = self.form.getvalue('writer') |
| 145 | + if not writer: |
| 146 | + return self.error_response('writer argument required') |
| 147 | + content_type = self.form.getvalue('content_type') |
| 148 | + if not content_type: |
| 149 | + return self.error_response('content_type argument required') |
| 150 | + writer_options = self.form.getvalue('writer_options') |
145 | 151 | template_blacklist = self.form.getvalue('template_blacklist') |
146 | 152 | |
147 | 153 | collection_id = self.new_collection() |
— | — | @@ -150,34 +156,42 @@ |
151 | 157 | f.write(metabook_data) |
152 | 158 | f.close() |
153 | 159 | |
| 160 | + contenttype_path = self.get_path(collection_id, self.contenttype_filename) |
| 161 | + f = open(contenttype_path, 'wb') |
| 162 | + f.write(content_type) |
| 163 | + f.close() |
| 164 | + |
154 | 165 | args=[ |
155 | | - mwpdf_cmd, |
| 166 | + mwrender_cmd, |
156 | 167 | '--daemonize', |
157 | | - '--logfile', mwpdf_logfile, |
158 | | - '--errorfile', self.get_path(collection_id, self.error_filename), |
| 168 | + '--logfile', mwrender_logfile, |
| 169 | + '--error-file', self.get_path(collection_id, self.error_filename), |
| 170 | + '--status-file', self.get_path(collection_id, self.status_filename), |
159 | 171 | '--metabook', metabook_path, |
160 | 172 | '--conf', base_url, |
161 | | - '--progress', self.get_path(collection_id, self.progress_filename), |
162 | | - '--output', self.get_path(collection_id, self.pdf_filename), |
| 173 | + '--writer', writer, |
| 174 | + '--output', self.get_path(collection_id, self.output_filename), |
163 | 175 | ] |
| 176 | + if writer_options: |
| 177 | + args.extend(['--writer-options', writer_options]) |
164 | 178 | if template_blacklist: |
165 | 179 | args.extend(['--template-blacklist', template_blacklist]) |
166 | 180 | |
167 | 181 | try: |
168 | | - rc = subprocess.call(executable=mwpdf_cmd, args=args) |
169 | | - except IOError, e: |
170 | | - raise RuntimeError('Could not execute command %r: %s' % (mwpdf_cmd, e)) |
| 182 | + rc = subprocess.call(executable=mwrender_cmd, args=args) |
| 183 | + except OSError, e: |
| 184 | + raise RuntimeError('Could not execute command %r: %s' % (mwrender_cmd, e)) |
171 | 185 | if rc != 0: |
172 | | - return self.error_response('command %r failed: rc = %d' % (mwpdf_cmd, rc)) |
| 186 | + return self.error_response('command %r failed: rc = %d' % (mwrender_cmd, rc)) |
173 | 187 | |
174 | 188 | return self.json_response({ |
175 | 189 | 'collection_id': collection_id, |
176 | 190 | }) |
177 | 191 | |
178 | | - def do_pdf_status(self): |
| 192 | + def do_render_status(self): |
179 | 193 | collection_id = self.get_collection() |
180 | 194 | |
181 | | - if os.path.exists(self.get_path(collection_id, self.pdf_filename)): |
| 195 | + if os.path.exists(self.get_path(collection_id, self.output_filename)): |
182 | 196 | return self.json_response({ |
183 | 197 | 'collection_id': collection_id, |
184 | 198 | 'state': 'finished', |
— | — | @@ -193,19 +207,24 @@ |
194 | 208 | }) |
195 | 209 | |
196 | 210 | try: |
197 | | - progress = int(open(self.get_path(collection_id, self.progress_filename), 'rb').read()) |
198 | | - except IOError: |
199 | | - progress = 0 |
| 211 | + f = open(self.get_path(collection_id, self.status_filename), 'rb') |
| 212 | + status = simplejson.loads(f.read()) |
| 213 | + f.close() |
| 214 | + except (IOError, ValueError): |
| 215 | + status = {'progress': 0} |
200 | 216 | return self.json_response({ |
201 | 217 | 'collection_id': collection_id, |
202 | 218 | 'state': 'progress', |
203 | | - 'progress': progress, |
| 219 | + 'status': status, |
204 | 220 | }) |
205 | 221 | |
206 | | - def do_pdf_download(self): |
| 222 | + def do_download(self): |
| 223 | + collection_id = self.get_collection() |
| 224 | + content_type = open(self.get_path(collection_id, self.contenttype_filename), 'rb').read() |
| 225 | + content = open(self.get_path(collection_id, self.output_filename), 'rb').read() |
207 | 226 | return { |
208 | | - 'content_type': 'application/pdf', |
209 | | - 'content': open(self.get_path(self.get_collection(), self.pdf_filename)).read() |
| 227 | + 'content_type': content_type, |
| 228 | + 'content': content, |
210 | 229 | } |
211 | 230 | |
212 | 231 | def do_zip_post(self): |
— | — | @@ -237,7 +256,7 @@ |
238 | 257 | args.extend(['--template-blacklist', template_blacklist]) |
239 | 258 | try: |
240 | 259 | rc = subprocess.call(executable=mwzip_cmd, args=args) |
241 | | - except IOError, e: |
| 260 | + except OSError, e: |
242 | 261 | raise RuntimeError('Could not execute command %r: %s' % (mwzip_cmd, e)) |
243 | 262 | if rc != 0: |
244 | 263 | return self.error_response('command %r failed: rc = %d' % (mwzip_cmd, rc)) |
Index: trunk/extensions/Collection/pdf-server/README.txt |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | cd reportlab/reportlab |
39 | 39 | python setup.py install |
40 | 40 | |
41 | | -*mwlib* |
| 41 | +*mwlib, version >= 0.7* |
42 | 42 | You need to have setuptools/easy_install installed. |
43 | 43 | Installation should be as easy as typing:: |
44 | 44 | |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | |
50 | 50 | python setup.py install |
51 | 51 | |
52 | | -*mwlib.rl* |
| 52 | +*mwlib.rl, version >= 0.7* |
53 | 53 | Install *mwlib.rl* with ``easy_install``:: |
54 | 54 | |
55 | 55 | easy_install mwlib.rl |