Skip to content

Commit

Permalink
[mod] Custom searx_version display
Browse files Browse the repository at this point in the history
searx_version is replaced by searx_version_custom and displays the latest upstream commit with the latest fork commit.
  • Loading branch information
tiekoetter committed Aug 17, 2024
1 parent f96b76e commit 851473f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
4 changes: 2 additions & 2 deletions searx/templates/simple/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="description" content="SearXNG — a privacy-respecting, open metasearch engine">
<meta name="keywords" content="SearXNG, search, search engine, metasearch, meta search">
<meta name="generator" content="searxng/{{ searx_version }}">
<meta name="generator" content="searxng/{{ searx_version_custom }}">
<meta name="referrer" content="no-referrer">
<meta name="robots" content="noarchive">
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down Expand Up @@ -65,7 +65,7 @@
</main>
<footer>
<p>
{{ _('Powered by') }} <a href="{{ url_for('info', pagename='about') }}">searxng</a> - {{ searx_version }} — {{ _('a privacy-respecting, open metasearch engine') }}<br/>
{{ _('Powered by') }} <a href="{{ url_for('info', pagename='about') }}">searxng</a> - {{ searx_version_custom }} — {{ _('a privacy-respecting, open metasearch engine') }}<br/>
<a href="{{ searx_git_url }}">{{ _('Source code') }}</a>
| <a href="{{ get_setting('brand.issue_url') }}">{{ _('Issue tracker') }}</a>
{% if enable_metrics %}| <a href="{{ url_for('stats') }}">{{ _('Engine stats') }}</a>{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion searx/templates/simple/new_issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% if searx_git_url and searx_git_url != 'unknow' %}
Repository: {{ searx_git_url }}
Branch: {{ searx_git_branch }}
Version: {{ searx_version }}
Version: {{ searx_version_custom }}
<!-- Check if these values are correct -->

{% else %}
Expand Down
30 changes: 30 additions & 0 deletions searx/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ def get_git_version():
return git_version, tag_version, docker_tag


def get_git_version_upstream():
try:
git_commit_date_hash = subprocess_run(r"git show -s --date='format:%-Y.%-m.%-d' --format='%cd+%h' origin/pull")
git_version = git_commit_date_hash
except subprocess.CalledProcessError:
git_commit_date_hash = subprocess_run(r"git show -s --date='format:%-Y.%-m.%-d' --format='%cd+%h'")
git_version = git_commit_date_hash
# add "+dirty" suffix if there are uncommited changes except searx/settings.yml
try:
subprocess_run("git diff --quiet -- . ':!searx/settings.yml' ':!utils/brand.env'")
except subprocess.CalledProcessError as e:
if e.returncode == 1:
git_version += "+dirty"
else:
logger.warning('"%s" returns an unexpected return code %i', e.returncode, e.cmd)
return git_version


def get_git_fork_commit():
git_commit_date_hash = subprocess_run(r"git show -s --format='%h'")
return git_commit_date_hash


try:
vf = importlib.import_module('searx.version_frozen')
VERSION_STRING, VERSION_TAG, DOCKER_TAG, GIT_URL, GIT_BRANCH = (
Expand All @@ -99,6 +122,9 @@ def get_git_version():
logger.error("%s is not found, fallback to the default version", ex.filename)


VERSION_STRING_UPSTREAM = get_git_version_upstream()
FORK_COMMIT = get_git_fork_commit()

logger.info("version: %s", VERSION_STRING)

if __name__ == "__main__":
Expand All @@ -113,6 +139,8 @@ def get_git_version():
VERSION_STRING = "{VERSION_STRING}"
VERSION_TAG = "{VERSION_TAG}"
DOCKER_TAG = "{DOCKER_TAG}"
VERSION_STRING_UPSTREAM = "{VERSION_STRING_UPSTREAM}"
FORK_COMMIT = "{FORK_COMMIT}"
GIT_URL = "{GIT_URL}"
GIT_BRANCH = "{GIT_BRANCH}"
"""
Expand All @@ -126,6 +154,8 @@ def get_git_version():
VERSION_STRING="{VERSION_STRING}"
VERSION_TAG="{VERSION_TAG}"
DOCKER_TAG="{DOCKER_TAG}"
VERSION_STRING_UPSTREAM = "{VERSION_STRING_UPSTREAM}"
FORK_COMMIT = "{FORK_COMMIT}"
GIT_URL="{GIT_URL}"
GIT_BRANCH="{GIT_BRANCH}"
"""
Expand Down
5 changes: 3 additions & 2 deletions searx/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
gen_useragent,
dict_subset,
)
from searx.version import VERSION_STRING, GIT_URL, GIT_BRANCH
from searx.version import VERSION_STRING, VERSION_STRING_UPSTREAM, FORK_COMMIT, GIT_URL, GIT_BRANCH
from searx.query import RawTextQuery
from searx.plugins import Plugin, plugins, initialize as plugin_initialize
from searx.plugins.oa_doi_rewrite import get_doi_resolver
Expand Down Expand Up @@ -417,6 +417,7 @@ def render(template_name: str, **kwargs):
kwargs['search_formats'] = [x for x in settings['search']['formats'] if x != 'html']
kwargs['instance_name'] = get_setting('general.instance_name')
kwargs['searx_version'] = VERSION_STRING
kwargs['searx_version_custom'] = str(VERSION_STRING_UPSTREAM) + " (" + str(FORK_COMMIT) + ")"
kwargs['searx_git_url'] = GIT_URL
kwargs['enable_metrics'] = get_setting('general.enable_metrics')
kwargs['get_setting'] = get_setting
Expand Down Expand Up @@ -1294,7 +1295,7 @@ def config():
'autocomplete': settings['search']['autocomplete'],
'safe_search': settings['search']['safe_search'],
'default_theme': settings['ui']['default_theme'],
'version': VERSION_STRING,
'version': str(VERSION_STRING_UPSTREAM) + " (" + str(FORK_COMMIT) + ")",
'brand': {
'PRIVACYPOLICY_URL': get_setting('general.privacypolicy_url'),
'CONTACT_URL': get_setting('general.contact_url'),
Expand Down

0 comments on commit 851473f

Please sign in to comment.