__init__.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 searx.settings_defaults import settings_set_defaults
  17. from os.path import dirname, abspath
  18. searx_dir = abspath(dirname(__file__))
  19. searx_parent_dir = abspath(dirname(dirname(__file__)))
  20. settings, settings_load_message = searx.settings_loader.load_settings()
  21. if settings is not None:
  22. settings = settings_set_defaults(settings)
  23. searx_debug = settings['general']['debug']
  24. if searx_debug:
  25. logging.basicConfig(level=logging.DEBUG)
  26. else:
  27. logging.basicConfig(level=logging.WARNING)
  28. logger = logging.getLogger('searx')
  29. logger.info(settings_load_message)
  30. # log max_request_timeout
  31. max_request_timeout = settings['outgoing']['max_request_timeout']
  32. if max_request_timeout is None:
  33. logger.info('max_request_timeout=%s', repr(max_request_timeout))
  34. else:
  35. logger.info('max_request_timeout=%i second(s)', max_request_timeout)
  36. class _brand_namespace:
  37. @classmethod
  38. def get_val(cls, group, name, default=''):
  39. return settings.get(group, {}).get(name) or default
  40. @property
  41. def SEARX_URL(self):
  42. return self.get_val('server', 'base_url')
  43. @property
  44. def CONTACT_URL(self):
  45. return self.get_val('general', 'contact_url')
  46. @property
  47. def GIT_URL(self):
  48. return self.get_val('brand', 'git_url')
  49. @property
  50. def GIT_BRANCH(self):
  51. return self.get_val('brand', 'git_branch')
  52. @property
  53. def ISSUE_URL(self):
  54. return self.get_val('brand', 'issue_url')
  55. @property
  56. def NEW_ISSUE_URL(self):
  57. return self.get_val('brand', 'new_issue_url')
  58. @property
  59. def DOCS_URL(self):
  60. return self.get_val('brand', 'docs_url')
  61. @property
  62. def PUBLIC_INSTANCES(self):
  63. return self.get_val('brand', 'public_instances')
  64. @property
  65. def WIKI_URL(self):
  66. return self.get_val('brand', 'wiki_url')
  67. @property
  68. def TWITTER_URL(self):
  69. return self.get_val('brand', 'twitter_url')
  70. brand = _brand_namespace()