Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ckanext-odsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Transparenzportal
ckanext-odsh
Commits
6b714820
Commit
6b714820
authored
5 years ago
by
Daniel Neuwirth
Browse files
Options
Downloads
Patches
Plain Diff
removed pdftotext
parent
0c7e6d6c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ckanext/odsh/pdf_to_thumbnail/thumbnail.py
+9
-3
9 additions, 3 deletions
ckanext/odsh/pdf_to_thumbnail/thumbnail.py
with
9 additions
and
3 deletions
ckanext/odsh/pdf_to_thumbnail/thumbnail.py
+
9
−
3
View file @
6b714820
...
@@ -10,26 +10,30 @@ import hashlib
...
@@ -10,26 +10,30 @@ import hashlib
import
binascii
import
binascii
import
ckan.plugins.toolkit
as
toolkit
import
ckan.plugins.toolkit
as
toolkit
import
ckan.logic
as
logic
import
ckan.logic
as
logic
#from extension
import
pdftotext
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
def
get_filename_from_context
(
context
):
def
get_filename_from_context
(
context
):
package
=
context
.
get
(
'
package
'
)
package
=
context
.
get
(
'
package
'
)
package_id
=
package
.
id
package_id
=
package
.
id
return
thumbnail
return
thumbnail
def
get_filepath_for_thumbnail
(
filename
):
def
get_filepath_for_thumbnail
(
filename
):
if
filename
:
if
filename
:
return
config
.
get
(
'
ckan.storage_path
'
)
+
"
/thumbnail/
"
+
filename
return
config
.
get
(
'
ckan.storage_path
'
)
+
"
/thumbnail/
"
+
filename
return
config
.
get
(
'
ckan.storage_path
'
)
+
"
/thumbnail/
"
return
config
.
get
(
'
ckan.storage_path
'
)
+
"
/thumbnail/
"
def
concatenate_filename
(
filename
):
def
concatenate_filename
(
filename
):
return
filename
+
"
.jpg
"
return
filename
+
"
.jpg
"
def
get_filepath_to_resource
(
resource
):
def
get_filepath_to_resource
(
resource
):
resource_id
=
resource
.
get
(
'
id
'
)
resource_id
=
resource
.
get
(
'
id
'
)
directory
=
config
.
get
(
'
ckan.storage_path
'
)
+
'
/resources/
'
directory
=
config
.
get
(
'
ckan.storage_path
'
)
+
'
/resources/
'
...
@@ -37,6 +41,7 @@ def get_filepath_to_resource(resource):
...
@@ -37,6 +41,7 @@ def get_filepath_to_resource(resource):
path
=
directory
+
resource_id
[
0
:
3
]
+
'
/
'
+
resource_id
[
3
:
6
]
+
'
/
'
+
resource_id
[
6
:]
path
=
directory
+
resource_id
[
0
:
3
]
+
'
/
'
+
resource_id
[
3
:
6
]
+
'
/
'
+
resource_id
[
6
:]
return
path
return
path
def
hash_filename
(
package_id
,
private
):
def
hash_filename
(
package_id
,
private
):
hash
=
hashlib
.
sha256
(
str
(
private
)
+
'
ajsdpfawdgfacasdfvffffas
'
+
package_id
).
hexdigest
()
hash
=
hashlib
.
sha256
(
str
(
private
)
+
'
ajsdpfawdgfacasdfvffffas
'
+
package_id
).
hexdigest
()
filename
=
'
thumbnail_picture_
'
+
hash
filename
=
'
thumbnail_picture_
'
+
hash
...
@@ -76,7 +81,6 @@ def create_thumbnail_from_file(file, package_id, private):
...
@@ -76,7 +81,6 @@ def create_thumbnail_from_file(file, package_id, private):
)
)
def
create_thumbnail_from_memory
(
resource
,
private
):
def
create_thumbnail_from_memory
(
resource
,
private
):
log
.
debug
(
'
create_thumbnail_from_memory
'
)
log
.
debug
(
'
create_thumbnail_from_memory
'
)
path
=
get_filepath_to_resource
(
resource
)
path
=
get_filepath_to_resource
(
resource
)
...
@@ -91,12 +95,14 @@ def create_thumbnail_from_memory(resource, private):
...
@@ -91,12 +95,14 @@ def create_thumbnail_from_memory(resource, private):
is_PDF
=
False
is_PDF
=
False
return
is_PDF
return
is_PDF
def
remove_thumbnail
(
package_id
,
private
):
def
remove_thumbnail
(
package_id
,
private
):
filename
=
hash_filename
(
package_id
,
private
)
+
'
.jpg
'
filename
=
hash_filename
(
package_id
,
private
)
+
'
.jpg
'
filepath
=
get_filepath_for_thumbnail
(
filename
)
filepath
=
get_filepath_for_thumbnail
(
filename
)
if
os
.
path
.
exists
(
filepath
):
if
os
.
path
.
exists
(
filepath
):
os
.
remove
(
filepath
)
os
.
remove
(
filepath
)
def
create_thumbnail
(
resource
,
private
):
def
create_thumbnail
(
resource
,
private
):
log
.
debug
(
'
create_thumbnail
'
)
log
.
debug
(
'
create_thumbnail
'
)
resource_path
=
get_filepath_to_resource
(
resource
)
resource_path
=
get_filepath_to_resource
(
resource
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment