annotate data/plugin/macro/PdfList.py @ 654:8c828d7b6cd4 tip

PDFList: check for pyPdf.utils.PdfReadError
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 07 Dec 2016 14:27:25 +0100
parents 127da830be6c
children
rev   line source
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 """
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 MoinMoin - PdfList Macro
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4 A macro to produce a list of attached pdf by reading meta data
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 Usage: <<PdfList([pagename])>>
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 If pagename isn't set, the current pagename is used.
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
9
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 @copyright: 2004 Jacob Cohen, Nigel Metheringham,
653
127da830be6c updated copyright
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 651
diff changeset
12 2006-2016 MoinMoin:ReimarBauer
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13 @license: GNU GPL, see COPYING for details.
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14 """
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
15
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 import os
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 import re
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18 import mimetypes
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 from MoinMoin.action.AttachFile import getAttachDir, getAttachUrl, _get_files
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20 from MoinMoin import wikiutil
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21 from MoinMoin import config
654
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
22 from pyPdf.utils import PdfReadError
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 # ToDo change to pyPDF2
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
25 try:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26 from pyPdf import PdfFileReader
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 except ImportError:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28 try:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 from MoinMoin.support.pyPdf import PdfFileReader
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30 except ImportError:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31 PdfFileReader = None
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33 def _build_filelist(request, pagename, showheader, readonly, mime_type='application/pdf', filterfn=None):
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
35 _ = request.getText
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
36
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
37 fmt = request.html_formatter
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
38
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 # access directory
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40 attach_dir = getAttachDir(request, pagename)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41 files = _get_files(request, pagename)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 if mime_type != '*':
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44 files = [fname for fname in files if mime_type == mimetypes.guess_type(fname)[0]]
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45 if filterfn is not None:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46 files = [fname for fname in files if filterfn(fname)]
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48 html = []
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49 if files:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
50 if showheader:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 html.append(fmt.rawHTML(_(
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
52 "To refer to attachments on a page, use '''{{{attachment:filename}}}''', \n"
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53 "as shown below in the list of files. \n"
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54 "Do '''NOT''' use the URL of the {{{[get]}}} link, \n"
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
55 "since this is subject to change and can break easily.",
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
56 wiki=True
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57 )))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 label_get = _("get")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60 label_edit = _("edit")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
61 label_view = _("view")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
62 may_write = request.user.may.write(pagename)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
63
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
64
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
65 html.append(u"""\
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
66 <script>
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
67 function checkAll(bx, targets_name) {
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
68 var cbs = document.getElementsByTagName('input');
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
69 for(var i=0; i < cbs.length; i++) {
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
70 if(cbs[i].type == 'checkbox' && cbs[i].name == targets_name) {
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
71 cbs[i].checked = bx.checked;
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
72 }
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73 }
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
74 }
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
75 </script>
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
76 <form method="POST">
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
77 <input type="hidden" name="action" value="AttachFile">
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
78 <input type="hidden" name="do" value="multifile">
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
79 """)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
80
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
81
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
82 # ToDo use to DataBrowserWidget
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
83 html.append('<table>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
84 html.append('<tr><td><b>Author</b></td><td><b>Title</b></td><td></td><td></td></tr>')
654
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
85 for fn in files:
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
86 html.append('<tr>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
87 html.append('<td>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
88
654
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
89 pdf_meta = {"/Author": "file access problem", "/Title": fn}
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
90
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
91 fullpath = os.path.join(attach_dir, fn).encode(config.charset)
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
92 try:
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
93 pdf = PdfFileReader(open(fullpath, 'rb'))
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
94 except PdfReadError:
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
95 pdf = None
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
96 if pdf:
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
97 pdf_meta = pdf.documentInfo
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
98 xmp_meta = pdf.xmpMetadata
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
99 try:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
100 pdf_meta = {"/Title": wikiutil.escape(xmp_meta.dc_title['x-default']),
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
101 "/Author": wikiutil.escape(pdf_meta['/Author'])}
651
8abf42ff06e3 macro: PdfList typo fixed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 650
diff changeset
102 except (AttributeError, KeyError):
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
103 pass
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
104
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
105
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
106 links = []
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
107
654
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
108 links.append(fmt.url(1, getAttachUrl(pagename, fn, request)) +
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
109 fmt.text(label_get) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
110 fmt.url(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
111
654
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
112 links.append(fmt.url(1, getAttachUrl(pagename, fn, request, do='view')) +
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
113 fmt.text(label_view) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
114 fmt.url(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
115
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
116 if may_write and not readonly:
654
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
117 edit_url = getAttachUrl(pagename, fn, request, do='modify')
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
118 if edit_url:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
119 links.append(fmt.url(1, edit_url) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
120 fmt.text(label_edit) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
121 fmt.url(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
122
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
123
650
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
124 title = None
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
125 author = None
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
126 if pdf_meta.has_key('/Title'):
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
127 title = pdf_meta['/Title']
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
128 if pdf_meta.has_key('/Author'):
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
129 author = pdf_meta['/Author']
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
130
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
131
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
132 if author or title:
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
133 html.append("%(/Author)s</td><td>%(/Title)s</td><td>" % {"/Title": wikiutil.escape(title),
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
134 "/Author": wikiutil.escape(author)})
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
135
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
136 else:
654
8c828d7b6cd4 PDFList: check for pyPdf.utils.PdfReadError
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 653
diff changeset
137 html.append('</td><td>%(filename)s</td><td>' % {"filename": fn})
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
138
650
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
139
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
140 html.append("%s" % "&nbsp;</td><td> ".join(links))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
141 html.append('</td>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
142 html.append('</tr>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
143
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
144
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
145 html.append('</table>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
146 html.append("</form>")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
147 html.append("...based on PDF Meta information")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
148
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
149 else:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
150 if showheader:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
151 html.append(fmt.paragraph(1))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
152 html.append(fmt.text(_("No attachments stored for %(pagename)s") % {
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
153 'pagename': pagename}))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
154 html.append(fmt.paragraph(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
155
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
156 html.append(fmt.table(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
157 return ''.join(html)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
158
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
159 def macro_PdfList(macro, pagename=None, mime_type=u'*', search_term=u'.+'):
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
160 # defaults if we don't get anything better
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
161 if PdfFileReader is None:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
162 return u"please install pyPdf"
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
163 if not pagename:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
164 pagename = macro.formatter.page.page_name
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
165 filterfn = re.compile(search_term, re.U).search
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
166 return _build_filelist(macro.request, pagename, 0, 1, mime_type='application/pdf', filterfn=filterfn)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
167
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
168