diff options
author | Alexandre Flament <alex@al-f.net> | 2017-01-06 13:23:30 +0100 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2017-05-15 21:23:13 +0200 |
commit | ee080feaed838da423d390d2e7b3828149df6589 (patch) | |
tree | ad23783066a3cc01c350d3fa68cf113864cc212f /searx/utils.py | |
parent | c233bf0df9e1eda57a21dc507fded636f1e772d0 (diff) | |
download | searxng-ee080feaed838da423d390d2e7b3828149df6589.tar.gz searxng-ee080feaed838da423d390d2e7b3828149df6589.zip |
[mod] the static and templates directories can be defined in the settings.yml
Diffstat (limited to 'searx/utils.py')
-rw-r--r-- | searx/utils.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/searx/utils.py b/searx/utils.py index f24c57afa..9a08197cc 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -178,37 +178,39 @@ class UnicodeWriter: self.writerow(row) -def get_themes(root): - """Returns available themes list.""" +def get_resources_directory(searx_directory, subdirectory, resources_directory): + if not resources_directory: + resources_directory = os.path.join(searx_directory, subdirectory) + if not os.path.isdir(resources_directory): + raise Exception(directory + " is not a directory") + return resources_directory - static_path = os.path.join(root, 'static') - templates_path = os.path.join(root, 'templates') +def get_themes(static_path): + """Returns available themes list.""" themes = os.listdir(os.path.join(static_path, 'themes')) if '__common__' in themes: themes.remove('__common__') - return static_path, templates_path, themes + return themes -def get_static_files(base_path): - base_path = os.path.join(base_path, 'static') +def get_static_files(static_path): static_files = set() - base_path_length = len(base_path) + 1 - for directory, _, files in os.walk(base_path): + static_path_length = len(static_path) + 1 + for directory, _, files in os.walk(static_path): for filename in files: - f = os.path.join(directory[base_path_length:], filename) + f = os.path.join(directory[static_path_length:], filename) static_files.add(f) return static_files -def get_result_templates(base_path): - base_path = os.path.join(base_path, 'templates') +def get_result_templates(templates_path): result_templates = set() - base_path_length = len(base_path) + 1 - for directory, _, files in os.walk(base_path): + templates_path_length = len(templates_path) + 1 + for directory, _, files in os.walk(templates_path): if directory.endswith('result_templates'): for filename in files: - f = os.path.join(directory[base_path_length:], filename) + f = os.path.join(directory[templates_path_length:], filename) result_templates.add(f) return result_templates |