__init__.py 3.2 KB

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