__init__.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. '''
  2. searx is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU Affero General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. searx is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU Affero General Public License for more details.
  10. You should have received a copy of the GNU Affero General Public License
  11. along with searx. If not, see < http://www.gnu.org/licenses/ >.
  12. (C) 2013- by Adam Tauber, <asciimoo@gmail.com>
  13. '''
  14. import logging
  15. from os import environ
  16. from os.path import realpath, dirname, join, abspath
  17. try:
  18. from yaml import load
  19. except:
  20. from sys import exit, stderr
  21. stderr.write('[E] install pyyaml\n')
  22. exit(2)
  23. searx_dir = abspath(dirname(__file__))
  24. engine_dir = dirname(realpath(__file__))
  25. # if possible set path to settings using the
  26. # enviroment variable SEARX_SETTINGS_PATH
  27. if 'SEARX_SETTINGS_PATH' in environ:
  28. settings_path = environ['SEARX_SETTINGS_PATH']
  29. # otherwise using default path
  30. else:
  31. settings_path = join(searx_dir, 'settings.yml')
  32. if 'SEARX_HTTPS_REWRITE_PATH' in environ:
  33. https_rewrite_path = environ['SEARX_HTTPS_REWRITE_PATH']
  34. else:
  35. https_rewrite_path = join(searx_dir, 'https_rules')
  36. # load settings
  37. with open(settings_path) as settings_yaml:
  38. settings = load(settings_yaml)
  39. if settings.get('server', {}).get('debug'):
  40. logging.basicConfig(level=logging.DEBUG)
  41. else:
  42. logging.basicConfig(level=logging.WARNING)
  43. logger = logging.getLogger('searx')
  44. # load https rules only if https rewrite is enabled
  45. if settings.get('server', {}).get('https_rewrite'):
  46. # loade https rules
  47. from searx.https_rewrite import load_https_rules
  48. load_https_rules(https_rewrite_path)
  49. logger.info('Initialisation done')