on master help sign in
[mod] get rid of searx/brand.py

Removes module searx/brand.py and creates a namespace at searx.brand. This patch is a first 'proof of concept'. Later we can decide to remove the brand namespace entirely or not. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit9e53470b4cf533b890a2f57debd2f2b4198b4dd1 authorMarkus Heiser <markus.heiser@darmarit.de> dateSun 27 Dec 2020, 14:39 (6 years ago) parent9485179
5 files changed+62−39
manage.sh+2−2 searx/__init__.py+46 searx/brand.py−9 setup.py+2−4 utils/build_env.py+12−24
manage.sh+2−2
@@ -123,9 +123,9 @@ docker_build() {
123123 SEARX_GIT_VERSION=$(git describe --match "v[0-9]*\.[0-9]*\.[0-9]*" HEAD 2>/dev/null | awk -F'-' '{OFS="-"; $1=substr($1, 2); if ($3) { $3=substr($3, 2); } print}')
124124
125125 # add the suffix "-dirty" if the repository has uncommited change
126− # /!\ HACK for searx/searx: ignore searx/brand.py and utils/brand.env
126+ # /!\ HACK for searx/searx: ignore utils/brand.env
127127 git update-index -q --refresh
128− if [ ! -z "$(git diff-index --name-only HEAD -- | grep -v 'searx/brand.py' | grep -v 'utils/brand.env')" ]; then
128+ if [ ! -z "$(git diff-index --name-only HEAD -- | grep -v 'utils/brand.env')" ]; then
129129 SEARX_GIT_VERSION="${SEARX_GIT_VERSION}-dirty"
130130 fi
131131
searx/__init__.py+46
@@ -60,3 +60,49 @@ if 'SEARX_SECRET' in environ:
6060 settings['server']['secret_key'] = environ['SEARX_SECRET']
6161if 'SEARX_BIND_ADDRESS' in environ:
6262 settings['server']['bind_address'] = environ['SEARX_BIND_ADDRESS']
63+
64+
65+class _brand_namespace:
66+
67+ @classmethod
68+ def get_val(cls, group, name, default=''):
69+ return settings[group].get(name, False) or ''
70+
71+ @property
72+ def SEARX_URL(self):
73+ return self.get_val('server', 'base_url')
74+
75+ @property
76+ def GIT_URL(self):
77+ return self.get_val('general', 'git_url')
78+
79+ @property
80+ def GIT_BRANCH(self):
81+ return self.get_val('general', 'git_branch')
82+
83+ @property
84+ def ISSUE_URL(self):
85+ return self.get_val('general', 'issue_url')
86+
87+ @property
88+ def DOCS_URL(self):
89+ return self.get_val('general', 'docs_url')
90+
91+ @property
92+ def PUBLIC_INSTANCES(self):
93+ return self.get_val('general', 'public_instances')
94+
95+ @property
96+ def CONTACT_URL(self):
97+ return self.get_val('general', 'contact_url')
98+
99+ @property
100+ def WIKI_URL(self):
101+ return self.get_val('general', 'wiki_url')
102+
103+ @property
104+ def TWITTER_URL(self):
105+ return self.get_val('general', 'twitter_url')
106+
107+
108+brand = _brand_namespace()
searx/brand.pydeleted−9
@@ -1,9 +0,0 @@
1−SEARX_URL = ''
2−GIT_URL = 'https://github.com/searx/searx'
3−GIT_BRANCH = 'master'
4−ISSUE_URL = 'https://github.com/searx/searx/issues'
5−DOCS_URL = 'https://searx.github.io/searx'
6−PUBLIC_INSTANCES = 'https://searx.space'
7−CONTACT_URL = ''
8−WIKI_URL = 'https://github.com/searx/searx/wiki'
9−TWITTER_URL = 'https://twitter.com/Searx_engine'
setup.py+2−4
@@ -7,10 +7,8 @@ from setuptools import find_packages
77import os
88import sys
99
10−# required to load VERSION_STRING constant
11−sys.path.insert(0, './searx')
12−from version import VERSION_STRING
13−import brand
10+from searx.version import VERSION_STRING
11+from searx import brand
1412
1513with open('README.rst', encoding='utf-8') as f:
1614 long_description = f.read()
utils/build_env.py+12−24
@@ -8,35 +8,23 @@ from os.path import realpath, dirname, join, sep
88repo_root = realpath(dirname(realpath(__file__)) + sep + '..')
99sys.path.insert(0, repo_root)
1010
11−from searx.settings_loader import load_settings
12−
13−settings, settings_load_message = load_settings()
14−print(settings_load_message)
15−
16−brand_env = 'utils' + sep + 'brand.env'
17−brand_py = 'searx' + sep + 'brand.py'
18−
19−def get_val(group, name, default=''):
20− return settings[group].get(name, False) or ''
11+from searx import brand
2112
2213name_val = [
23− ('SEARX_URL' , get_val('server', 'base_url')),
24− ('GIT_URL' , get_val('general','git_url')),
25− ('GIT_BRANCH' , get_val('general','git_branch')),
26− ('ISSUE_URL' , get_val('general','issue_url')),
27− ('DOCS_URL' , get_val('general','docs_url')),
28− ('PUBLIC_INSTANCES' , get_val('general','public_instances')),
29− ('CONTACT_URL' , get_val('general','contact_url')),
30− ('WIKI_URL' , get_val('general','wiki_url')),
31− ('TWITTER_URL' , get_val('general','twitter_url')),
14+ ('SEARX_URL' , brand.SEARX_URL),
15+ ('GIT_URL' , brand.GIT_URL),
16+ ('GIT_BRANCH' , brand.GIT_BRANCH),
17+ ('ISSUE_URL' , brand.ISSUE_URL),
18+ ('DOCS_URL' , brand.DOCS_URL),
19+ ('PUBLIC_INSTANCES' , brand.PUBLIC_INSTANCES),
20+ ('CONTACT_URL' , brand.CONTACT_URL),
21+ ('WIKI_URL' , brand.WIKI_URL),
22+ ('TWITTER_URL' , brand.TWITTER_URL),
3223]
3324
25+brand_env = 'utils' + sep + 'brand.env'
26+
3427print('build %s' % brand_env)
3528with open(repo_root + sep + brand_env, 'w', encoding='utf-8') as f:
3629 for name, val in name_val:
3730 print("export %s='%s'" % (name, val), file=f)
38−
39−print('build %s' % brand_py)
40−with open(repo_root + sep + brand_py, 'w', encoding='utf-8') as f:
41− for name, val in name_val:
42− print("%s = '%s'" % (name, val), file=f)