__init__.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. import searx.settings_loader
  16. from os import environ
  17. from os.path import realpath, dirname, join, abspath, isfile
  18. searx_dir = abspath(dirname(__file__))
  19. engine_dir = dirname(realpath(__file__))
  20. static_path = abspath(join(dirname(__file__), 'static'))
  21. settings, settings_load_message = searx.settings_loader.load_settings()
  22. if settings['ui']['static_path']:
  23. static_path = settings['ui']['static_path']
  24. '''
  25. enable debug if
  26. the environnement variable SEARX_DEBUG is 1 or true
  27. (whatever the value in settings.yml)
  28. or general.debug=True in settings.yml
  29. disable debug if
  30. the environnement variable SEARX_DEBUG is 0 or false
  31. (whatever the value in settings.yml)
  32. or general.debug=False in settings.yml
  33. '''
  34. searx_debug_env = environ.get('SEARX_DEBUG', '').lower()
  35. if searx_debug_env == 'true' or searx_debug_env == '1':
  36. searx_debug = True
  37. elif searx_debug_env == 'false' or searx_debug_env == '0':
  38. searx_debug = False
  39. else:
  40. searx_debug = settings.get('general', {}).get('debug')
  41. if searx_debug:
  42. logging.basicConfig(level=logging.DEBUG)
  43. else:
  44. logging.basicConfig(level=logging.WARNING)
  45. logger = logging.getLogger('searx')
  46. logger.info(settings_load_message)
  47. logger.info('Initialisation done')
  48. if 'SEARX_SECRET' in environ:
  49. settings['server']['secret_key'] = environ['SEARX_SECRET']
  50. if 'SEARX_BIND_ADDRESS' in environ:
  51. settings['server']['bind_address'] = environ['SEARX_BIND_ADDRESS']
  52. class _brand_namespace:
  53. @classmethod
  54. def get_val(cls, group, name, default=''):
  55. return settings.get(group, {}).get(name) or default
  56. @property
  57. def SEARX_URL(self):
  58. return self.get_val('server', 'base_url')
  59. @property
  60. def CONTACT_URL(self):
  61. return self.get_val('general', 'contact_url')
  62. @property
  63. def GIT_URL(self):
  64. return self.get_val('brand', 'git_url')
  65. @property
  66. def GIT_BRANCH(self):
  67. return self.get_val('brand', 'git_branch')
  68. @property
  69. def ISSUE_URL(self):
  70. return self.get_val('brand', 'issue_url')
  71. @property
  72. def DOCS_URL(self):
  73. return self.get_val('brand', 'docs_url')
  74. @property
  75. def PUBLIC_INSTANCES(self):
  76. return self.get_val('brand', 'public_instances')
  77. @property
  78. def WIKI_URL(self):
  79. return self.get_val('brand', 'wiki_url')
  80. @property
  81. def TWITTER_URL(self):
  82. return self.get_val('brand', 'twitter_url')
  83. brand = _brand_namespace()