build_env.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """build environment used by shell scripts
  3. """
  4. # set path
  5. import sys
  6. import os
  7. from os.path import realpath, dirname, join, sep, abspath
  8. repo_root = realpath(dirname(realpath(__file__)) + sep + '..')
  9. sys.path.insert(0, repo_root)
  10. os.environ['SEARX_SETTINGS_PATH'] = abspath(dirname(__file__) + '/settings.yml')
  11. # Under the assumption that a brand is always a fork assure that the settings
  12. # file from reposetorie's working tree is used to generate the build_env, not
  13. # from /etc/searx/settings.yml.
  14. os.environ['SEARX_SETTINGS_PATH'] = abspath(dirname(__file__) + sep + 'settings.yml')
  15. from searx import get_setting
  16. def _env(*arg, **kwargs):
  17. val = get_setting(*arg, **kwargs)
  18. if val is True:
  19. val = '1'
  20. elif val is False:
  21. val = ''
  22. return val
  23. name_val = [
  24. ('SEARX_URL' , _env('server.base_url','')),
  25. ('GIT_URL' , _env('brand.git_url', '')),
  26. ('GIT_BRANCH' , _env('brand.git_branch', '')),
  27. ('ISSUE_URL' , _env('brand.issue_url', '')),
  28. ('DOCS_URL' , _env('brand.docs_url', '')),
  29. ('PUBLIC_INSTANCES' , _env('brand.public_instances', '')),
  30. ('CONTACT_URL' , _env('general.contact_url', '')),
  31. ('WIKI_URL' , _env('brand.wiki_url', '')),
  32. ]
  33. brand_env = 'utils' + sep + 'brand.env'
  34. print('build %s' % brand_env)
  35. with open(repo_root + sep + brand_env, 'w', encoding='utf-8') as f:
  36. for name, val in name_val:
  37. print("export %s='%s'" % (name, val), file=f)