Commit f9e37b3d authored by Jérome Perrin's avatar Jérome Perrin

don't fail if pdftk is not found


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35515 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f1b6f273
...@@ -231,22 +231,27 @@ class PDFDocument(Image): ...@@ -231,22 +231,27 @@ class PDFDocument(Image):
result[key] = value result[key] = value
# Then we use pdftk to get extra metadata # Then we use pdftk to get extra metadata
command_result = Popen(['pdftk', tmp.name, 'dump_data', 'output'], try:
command_result = Popen(['pdftk', tmp.name, 'dump_data', 'output'],
stdout=PIPE).communicate()[0] stdout=PIPE).communicate()[0]
h = command_result except OSError:
line_list = (line for line in h.splitlines()) # pdftk not found
while True: pass
try: else:
line = line_list.next() h = command_result
except StopIteration: line_list = (line for line in h.splitlines())
break while True:
if line.startswith('InfoKey'): try:
key = line[len('InfoKey: '):] line = line_list.next()
line = line_list.next() except StopIteration:
assert line.startswith('InfoValue: '),\ break
"Wrong format returned by pdftk dump_data" if line.startswith('InfoKey'):
value = line[len('InfoValue: '):] key = line[len('InfoKey: '):]
result.setdefault(key, value) line = line_list.next()
assert line.startswith('InfoValue: '),\
"Wrong format returned by pdftk dump_data"
value = line[len('InfoValue: '):]
result.setdefault(key, value)
finally: finally:
tmp.close() tmp.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment