on master help sign in
[fix] resolve minor review issues
commitdff879d07d3cd937526804dda4f07d2e84249c59 authorAdam Tauber <asciimoo@gmail.com> dateSat 25 Jul 2020, 03:20 (6 years ago) parente45a269
2 files changed+25−23
searx/__init__.py+3 searx/plugins/__init__.py+22−23
searx/__init__.py+3
@@ -56,6 +56,9 @@ if not settings_path:
5656with open(settings_path, 'r', encoding='utf-8') as settings_yaml:
5757 settings = safe_load(settings_yaml)
5858
59+if settings['ui']['static_path']:
60+ static_path = settings['ui']['static_path']
61+
5962'''
6063enable debug if
6164the environnement variable SEARX_DEBUG is 1 or true
searx/plugins/__init__.py+22−23
@@ -17,7 +17,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
1717
1818from hashlib import sha256
1919from importlib import import_module
20−from os import listdir, mkdir, remove
20+from os import makedirs, remove
2121from os.path import abspath, basename, dirname, exists, isdir, join
2222from shutil import copyfile
2323from sys import exit, version_info
@@ -99,50 +99,49 @@ def load_external_plugins(plugin_names):
9999
100100 pkg.__base_path = dirname(abspath(pkg.__file__))
101101
102− fix_package_resources(pkg, name)
102+ prepare_package_resources(pkg, name)
103103
104104 plugins.append(pkg)
105105 logger.debug('plugin "{0}" loaded'.format(name))
106106 return plugins
107107
108108
109−def check_resource(base_path, resource_path, name, target_dir, plugin_dir):
110− dep_path = join(base_path, resource_path)
111− file_name = basename(dep_path)
112− resource_path = join(target_dir, file_name)
113− if not exists(resource_path) or sha_sum(dep_path) != sha_sum(resource_path):
114− try:
115− copyfile(dep_path, resource_path)
116− except:
117− logger.critical('failed to copy plugin resource {0} for plugin {1}'.format(file_name, name))
118− exit(3)
109+def sync_resource(base_path, resource_path, name, target_dir, plugin_dir):
110+ dep_path = join(base_path, resource_path)
111+ file_name = basename(dep_path)
112+ resource_path = join(target_dir, file_name)
113+ if not exists(resource_path) or sha_sum(dep_path) != sha_sum(resource_path):
114+ try:
115+ copyfile(dep_path, resource_path)
116+ except:
117+ logger.critical('failed to copy plugin resource {0} for plugin {1}'.format(file_name, name))
118+ exit(3)
119119
120− # returning with the web path of the resource
121− return join('plugins', plugin_dir, file_name)
120+ # returning with the web path of the resource
121+ return join('plugins', plugin_dir, file_name)
122122
123123
124−def fix_package_resources(pkg, name):
124+def prepare_package_resources(pkg, name):
125125 plugin_dir = 'plugin_' + name
126126 target_dir = join(static_path, 'plugins', plugin_dir)
127− if not isdir(target_dir):
128− try:
129− mkdir(target_dir)
130− except:
131− logger.critical('failed to create resource directory {0} for plugin {1}'.format(target_dir, name))
132− exit(3)
127+ try:
128+ makedirs(target_dir, exist_ok=True)
129+ except:
130+ logger.critical('failed to create resource directory {0} for plugin {1}'.format(target_dir, name))
131+ exit(3)
133132
134133 resources = []
135134
136135 if hasattr(pkg, 'js_dependencies'):
137136 resources.extend(map(basename, pkg.js_dependencies))
138137 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)
140139 for x in pkg.js_dependencies
141140 ])
142141 if hasattr(pkg, 'css_dependencies'):
143142 resources.extend(map(basename, pkg.css_dependencies))
144143 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)
146145 for x in pkg.css_dependencies
147146 ])
148147