@@ -17,7 +17,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
18from hashlib import sha256
18from hashlib import sha256
19from importlib import import_module
19from importlib import import_module
20−from os import listdir, mkdir, remove
20+from os import makedirs, remove
21from os.path import abspath, basename, dirname, exists, isdir, join
21from os.path import abspath, basename, dirname, exists, isdir, join
22from shutil import copyfile
22from shutil import copyfile
23from sys import exit, version_info
23from sys import exit, version_info
@@ -99,50 +99,49 @@ def load_external_plugins(plugin_names):
100 pkg.__base_path = dirname(abspath(pkg.__file__))
100 pkg.__base_path = dirname(abspath(pkg.__file__))
102− fix_package_resources(pkg, name)
102+ prepare_package_resources(pkg, name)
104 plugins.append(pkg)
104 plugins.append(pkg)
105 logger.debug('plugin "{0}" loaded'.format(name))
105 logger.debug('plugin "{0}" loaded'.format(name))
106 return plugins
106 return plugins
109−def check_resource(base_path, resource_path, name, target_dir, plugin_dir):
109+def sync_resource(base_path, resource_path, name, target_dir, plugin_dir):
110− dep_path = join(base_path, resource_path)
110+ dep_path = join(base_path, resource_path)
111− file_name = basename(dep_path)
111+ file_name = basename(dep_path)
112− resource_path = join(target_dir, file_name)
112+ resource_path = join(target_dir, file_name)
113− if not exists(resource_path) or sha_sum(dep_path) != sha_sum(resource_path):
113+ if not exists(resource_path) or sha_sum(dep_path) != sha_sum(resource_path):
115− copyfile(dep_path, resource_path)
115+ copyfile(dep_path, resource_path)
117− logger.critical('failed to copy plugin resource {0} for plugin {1}'.format(file_name, name))
117+ logger.critical('failed to copy plugin resource {0} for plugin {1}'.format(file_name, name))
120− # returning with the web path of the resource
120+ # returning with the web path of the resource
121− return join('plugins', plugin_dir, file_name)
121+ return join('plugins', plugin_dir, file_name)
124−def fix_package_resources(pkg, name):
124+def prepare_package_resources(pkg, name):
125 plugin_dir = 'plugin_' + name
125 plugin_dir = 'plugin_' + name
126 target_dir = join(static_path, 'plugins', plugin_dir)
126 target_dir = join(static_path, 'plugins', plugin_dir)
127− if not isdir(target_dir):
129− mkdir(target_dir)
128+ makedirs(target_dir, exist_ok=True)
131− logger.critical('failed to create resource directory {0} for plugin {1}'.format(target_dir, name))
130+ logger.critical('failed to create resource directory {0} for plugin {1}'.format(target_dir, name))
134 resources = []
133 resources = []
136 if hasattr(pkg, 'js_dependencies'):
135 if hasattr(pkg, 'js_dependencies'):
137 resources.extend(map(basename, pkg.js_dependencies))
136 resources.extend(map(basename, pkg.js_dependencies))
138 pkg.js_dependencies = tuple([
137 pkg.js_dependencies = tuple([
139− check_resource(pkg.__base_path, x, name, target_dir, plugin_dir)
138+ sync_resource(pkg.__base_path, x, name, target_dir, plugin_dir)
140 for x in pkg.js_dependencies
139 for x in pkg.js_dependencies
142 if hasattr(pkg, 'css_dependencies'):
141 if hasattr(pkg, 'css_dependencies'):
143 resources.extend(map(basename, pkg.css_dependencies))
142 resources.extend(map(basename, pkg.css_dependencies))
144 pkg.css_dependencies = tuple([
143 pkg.css_dependencies = tuple([
145− check_resource(pkg.__base_path, x, name, target_dir, plugin_dir)
144+ sync_resource(pkg.__base_path, x, name, target_dir, plugin_dir)
146 for x in pkg.css_dependencies
145 for x in pkg.css_dependencies