on master help sign in
[fix] resolve minor review issues
dff879dAdam Tauber
searx/__init__.py+3
@@ -56,6 +56,9 @@ if not settings_path:
56with open(settings_path, 'r', encoding='utf-8') as settings_yaml:
56with open(settings_path, 'r', encoding='utf-8') as settings_yaml:
57 settings = safe_load(settings_yaml)
57 settings = safe_load(settings_yaml)
58
58
59+if settings['ui']['static_path']:
60+ static_path = settings['ui']['static_path']
61+
59'''
62'''
60enable debug if
63enable debug if
61the environnement variable SEARX_DEBUG is 1 or true
64the 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/ >.
17
17
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):
99
99
100 pkg.__base_path = dirname(abspath(pkg.__file__))
100 pkg.__base_path = dirname(abspath(pkg.__file__))
101
101
102− fix_package_resources(pkg, name)
102+ prepare_package_resources(pkg, name)
103
103
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
107
107
108
108
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):
114− try:
114+ try:
115− copyfile(dep_path, resource_path)
115+ copyfile(dep_path, resource_path)
116− except:
116+ except:
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))
118− exit(3)
118+ exit(3)
119
119
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)
122
122
123
123
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):
128− try:
127+ try:
129− mkdir(target_dir)
128+ makedirs(target_dir, exist_ok=True)
130− except:
129+ except:
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))
132− exit(3)
131+ exit(3)
133
132
134 resources = []
133 resources = []
135
134
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
141 ])
140 ])
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
147 ])
146 ])
148
147