Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
f48eeb6f
Commit
f48eeb6f
authored
Feb 05, 2015
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDF: use cache conversion to cache PDF content information
parent
5875c450
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
12 deletions
+8
-12
product/ERP5/Document/PDFDocument.py
product/ERP5/Document/PDFDocument.py
+8
-12
No files found.
product/ERP5/Document/PDFDocument.py
View file @
f48eeb6f
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
##############################################################################
##############################################################################
import
tempfile
,
os
,
pickle
import
tempfile
,
os
,
pickle
import
json
import
zope.interface
import
zope.interface
from
AccessControl
import
ClassSecurityInfo
from
AccessControl
import
ClassSecurityInfo
...
@@ -278,18 +279,19 @@ class PDFDocument(Image):
...
@@ -278,18 +279,19 @@ class PDFDocument(Image):
def
getContentInformation
(
self
):
def
getContentInformation
(
self
):
"""Returns the information about the PDF document with pdfinfo.
"""Returns the information about the PDF document with pdfinfo.
"""
"""
content_information_pseudo_format
=
'content_information_pseudo_format'
if
not
self
.
hasData
():
if
not
self
.
hasData
():
return
{}
return
{}
try
:
# XXX we reuse the conversion infrastructure for cache
return
self
.
_content_information
.
copy
()
if
self
.
hasConversion
(
format
=
content_information_pseudo_format
):
except
AttributeError
:
mime
,
data
=
self
.
getConversion
(
format
=
content_information_pseudo_format
)
pass
return
json
.
loads
(
data
)
tmp
=
tempfile
.
NamedTemporaryFile
()
tmp
=
tempfile
.
NamedTemporaryFile
()
tmp
.
write
(
self
.
getData
())
tmp
.
write
(
self
.
getData
())
tmp
.
seek
(
0
)
tmp
.
seek
(
0
)
command_result
=
None
command_result
=
None
try
:
try
:
# First, we use pdfinfo to get standard metadata
# First, we use pdfinfo to get standard metadata
command
=
[
'pdfinfo'
,
'-meta'
,
'-box'
,
tmp
.
name
]
command
=
[
'pdfinfo'
,
'-meta'
,
'-box'
,
tmp
.
name
]
try
:
try
:
...
@@ -341,16 +343,10 @@ class PDFDocument(Image):
...
@@ -341,16 +343,10 @@ class PDFDocument(Image):
finally
:
finally
:
tmp
.
close
()
tmp
.
close
()
# Store cache as an instance of document. FIXME: we usually try to avoid this
self
.
setConversion
(
json
.
dumps
(
result
),
format
=
content_information_pseudo_format
)
# pattern and cache the result of methods using content md5 as a cache key.
self
.
_content_information
=
result
return
result
.
copy
()
return
result
.
copy
()
def
_setFile
(
self
,
data
,
precondition
=
None
):
def
_setFile
(
self
,
data
,
precondition
=
None
):
try
:
del
self
.
_content_information
except
(
AttributeError
,
KeyError
):
pass
# Use File._setFile because Image._setFile will guess image size & content
# Use File._setFile because Image._setFile will guess image size & content
# type
# type
File
.
_setFile
(
self
,
data
,
precondition
=
precondition
)
File
.
_setFile
(
self
,
data
,
precondition
=
precondition
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment