diff --git a/ckanext/odsh/pdf_to_thumbnail/thumbnail.py b/ckanext/odsh/pdf_to_thumbnail/thumbnail.py index c60cf0ae7392261a00cfc148ed64b805b5917726..6f0c920933a3b03908a37a4f819e7c486ce098bb 100644 --- a/ckanext/odsh/pdf_to_thumbnail/thumbnail.py +++ b/ckanext/odsh/pdf_to_thumbnail/thumbnail.py @@ -10,26 +10,30 @@ import hashlib import binascii import ckan.plugins.toolkit as toolkit import ckan.logic as logic -#from extension -import pdftotext log = logging.getLogger(__name__) + + + def get_filename_from_context(context): package = context.get('package') package_id = package.id return thumbnail + def get_filepath_for_thumbnail(filename): if filename: return config.get('ckan.storage_path') + "/thumbnail/" + filename return config.get('ckan.storage_path') + "/thumbnail/" + def concatenate_filename(filename): return filename + ".jpg" + def get_filepath_to_resource(resource): resource_id = resource.get('id') directory = config.get('ckan.storage_path') + '/resources/' @@ -37,6 +41,7 @@ def get_filepath_to_resource(resource): path = directory + resource_id[0:3] + '/' + resource_id[3:6] + '/' + resource_id[6:] return path + def hash_filename(package_id, private): hash = hashlib.sha256(str(private) + 'ajsdpfawdgfacasdfvffffas' + package_id).hexdigest() filename = 'thumbnail_picture_' + hash @@ -76,7 +81,6 @@ def create_thumbnail_from_file(file, package_id, private): ) - def create_thumbnail_from_memory(resource, private): log.debug('create_thumbnail_from_memory') path = get_filepath_to_resource(resource) @@ -91,12 +95,14 @@ def create_thumbnail_from_memory(resource, private): is_PDF = False return is_PDF + def remove_thumbnail(package_id, private): filename = hash_filename(package_id, private) + '.jpg' filepath = get_filepath_for_thumbnail(filename) if os.path.exists(filepath): os.remove(filepath) + def create_thumbnail(resource, private): log.debug('create_thumbnail') resource_path = get_filepath_to_resource(resource)