mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
diagnostics: Lazy format all diagnostic test strings properly
Helps: #1938. Fixed application of available translations in daemon.py and apache, diagnostics, networks, firewall and users modules. diagnostics: - __init__.py: return the app name along its results. - diagnostics.html: display the app name instead of its id. - diagnostics_results.html: - mark for translation, - apply class to results <td> HTML tag. main.css: center-align the results. Locale files excluded. Will be regenerated automatically and translations to be done via Weblate. original testing (rebased later): - Yapf applied. - Flake8 without errors or warnings for changed files. - (Unit) tests run without errors. Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com> [sunil: Translate 'None' app name] [sunil: Don't translate tests strings second time in template] [sunil: Tweak the center rule] [sunil: Don't split a translation string] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
f1f84a2509
commit
633f54b75c
@ -7,7 +7,8 @@ import socket
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.text import format_lazy
|
||||||
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
|
|
||||||
from plinth import action_utils, actions, app
|
from plinth import action_utils, actions, app
|
||||||
|
|
||||||
@ -82,10 +83,12 @@ class Daemon(app.LeaderComponent):
|
|||||||
|
|
||||||
def _diagnose_unit_is_running(self):
|
def _diagnose_unit_is_running(self):
|
||||||
"""Check if a daemon is running."""
|
"""Check if a daemon is running."""
|
||||||
message = _('Service {service_name} is running').format(
|
|
||||||
service_name=self.unit)
|
|
||||||
result = 'passed' if self.is_running() else 'failed'
|
result = 'passed' if self.is_running() else 'failed'
|
||||||
return [message, result]
|
|
||||||
|
template = ugettext_lazy('Service {service_name} is running')
|
||||||
|
testname = format_lazy(template, service_name=self.unit)
|
||||||
|
|
||||||
|
return [testname, result]
|
||||||
|
|
||||||
|
|
||||||
def app_is_running(app_):
|
def app_is_running(app_):
|
||||||
@ -108,13 +111,15 @@ def diagnose_port_listening(port, kind='tcp', listen_address=None):
|
|||||||
result = _check_port(port, kind, listen_address)
|
result = _check_port(port, kind, listen_address)
|
||||||
|
|
||||||
if listen_address:
|
if listen_address:
|
||||||
test = _('Listening on {kind} port {listen_address}:{port}') \
|
template = ugettext_lazy(
|
||||||
.format(kind=kind, listen_address=listen_address, port=port)
|
'Listening on {kind} port {listen_address}:{port}')
|
||||||
|
testname = format_lazy(template, kind=kind,
|
||||||
|
listen_address=listen_address, port=port)
|
||||||
else:
|
else:
|
||||||
test = _('Listening on {kind} port {port}') \
|
template = ugettext_lazy('Listening on {kind} port {port}')
|
||||||
.format(kind=kind, port=port)
|
testname = format_lazy(template, kind=kind, port=port)
|
||||||
|
|
||||||
return [test, 'passed' if result else 'failed']
|
return [testname, 'passed' if result else 'failed']
|
||||||
|
|
||||||
|
|
||||||
def _check_port(port, kind='tcp', listen_address=None):
|
def _check_port(port, kind='tcp', listen_address=None):
|
||||||
|
|||||||
@ -6,13 +6,15 @@ App component for other apps to use Apache configuration functionality.
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.text import format_lazy
|
||||||
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
from plinth import action_utils, actions, app
|
from plinth import action_utils, actions, app
|
||||||
|
|
||||||
|
|
||||||
class Webserver(app.LeaderComponent):
|
class Webserver(app.LeaderComponent):
|
||||||
"""Component to enable/disable Apache configuration."""
|
"""Component to enable/disable Apache configuration."""
|
||||||
|
|
||||||
def __init__(self, component_id, web_name, kind='config', urls=None):
|
def __init__(self, component_id, web_name, kind='config', urls=None):
|
||||||
"""Initialize the web server component.
|
"""Initialize the web server component.
|
||||||
|
|
||||||
@ -71,6 +73,7 @@ class Webserver(app.LeaderComponent):
|
|||||||
|
|
||||||
class Uwsgi(app.LeaderComponent):
|
class Uwsgi(app.LeaderComponent):
|
||||||
"""Component to enable/disable uWSGI configuration."""
|
"""Component to enable/disable uWSGI configuration."""
|
||||||
|
|
||||||
def __init__(self, component_id, uwsgi_name):
|
def __init__(self, component_id, uwsgi_name):
|
||||||
"""Initialize the uWSGI component.
|
"""Initialize the uWSGI component.
|
||||||
|
|
||||||
@ -116,12 +119,13 @@ def diagnose_url(url, kind=None, env=None, check_certificate=True,
|
|||||||
wrapper, expected_output)
|
wrapper, expected_output)
|
||||||
|
|
||||||
if kind:
|
if kind:
|
||||||
return [
|
template = ugettext_lazy('Access URL {url} on tcp{kind}')
|
||||||
_('Access URL {url} on tcp{kind}').format(url=url, kind=kind),
|
testname = format_lazy(template, url=url, kind=kind)
|
||||||
result
|
else:
|
||||||
]
|
template = ugettext_lazy('Access URL {url}')
|
||||||
|
testname = format_lazy(template, url=url)
|
||||||
|
|
||||||
return [_('Access URL {url}').format(url=url), result]
|
return [testname, result]
|
||||||
|
|
||||||
|
|
||||||
def diagnose_url_on_all(url, **kwargs):
|
def diagnose_url_on_all(url, **kwargs):
|
||||||
|
|||||||
@ -129,7 +129,11 @@ def run_on_all_enabled_modules():
|
|||||||
|
|
||||||
current_results['apps'] = apps
|
current_results['apps'] = apps
|
||||||
for current_index, (app_id, app) in enumerate(apps):
|
for current_index, (app_id, app) in enumerate(apps):
|
||||||
current_results['results'][app_id] = app.diagnose()
|
app_name = app.info.name or _('None')
|
||||||
|
current_results['results'][app_id] = {
|
||||||
|
'name': app_name,
|
||||||
|
'results': app.diagnose()
|
||||||
|
}
|
||||||
current_results['progress_percentage'] = \
|
current_results['progress_percentage'] = \
|
||||||
int((current_index + 1) * 100 / len(apps))
|
int((current_index + 1) * 100 / len(apps))
|
||||||
|
|
||||||
|
|||||||
@ -37,11 +37,15 @@
|
|||||||
{{ results.error }}
|
{{ results.error }}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% for app_id, app_results in results.results.items %}
|
{% for app_id, app_data in results.results.items %}
|
||||||
<h4>{% blocktrans %}App: {{ app_id }}{% endblocktrans %}</h4>
|
<h4>
|
||||||
|
{% blocktrans with app_name=app_data.name %}
|
||||||
|
App: {{app_name}}
|
||||||
|
{% endblocktrans %}
|
||||||
|
</h4>
|
||||||
|
|
||||||
{% if app_results %}
|
{% if app_data.results %}
|
||||||
{% include "diagnostics_results.html" with results=app_results %}
|
{% include "diagnostics_results.html" with results=app_data.results %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p><span class="fa fa-hourglass-o"></span></p>
|
<p><span class="fa fa-hourglass-o"></span></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
{% for test, result in results %}
|
{% for test, result in results %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ test }}</td>
|
<td>{{ test }}</td>
|
||||||
<td>
|
<td class="diagnostics-result">
|
||||||
{% if result == 'passed' %}
|
{% if result == 'passed' %}
|
||||||
<span class="label label-success">{% trans result %}</span>
|
<span class="label label-success">{% trans result %}</span>
|
||||||
{% elif result == 'failed' %}
|
{% elif result == 'failed' %}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ App component for other apps to use firewall functionality.
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from django.utils.text import format_lazy
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from plinth import app
|
from plinth import app
|
||||||
@ -129,24 +130,24 @@ class Firewall(app.FollowerComponent):
|
|||||||
|
|
||||||
# Internal zone
|
# Internal zone
|
||||||
result = 'passed' if port in internal_ports else 'failed'
|
result = 'passed' if port in internal_ports else 'failed'
|
||||||
message = _(
|
template = _(
|
||||||
'Port {name} ({details}) available for internal networks'
|
'Port {name} ({details}) available for internal networks')
|
||||||
).format(name=port, details=details)
|
testname = format_lazy(template, name=port, details=details)
|
||||||
results.append([message, result])
|
results.append([testname, result])
|
||||||
|
|
||||||
# External zone
|
# External zone
|
||||||
if self.is_external:
|
if self.is_external:
|
||||||
result = 'passed' if port in external_ports else 'failed'
|
result = 'passed' if port in external_ports else 'failed'
|
||||||
message = _(
|
template = _(
|
||||||
'Port {name} ({details}) available for external networks'
|
'Port {name} ({details}) available for external networks')
|
||||||
).format(name=port, details=details)
|
testname = format_lazy(template, name=port, details=details)
|
||||||
else:
|
else:
|
||||||
result = 'passed' if port not in external_ports else 'failed'
|
result = 'passed' if port not in external_ports else 'failed'
|
||||||
message = _(
|
template = _(
|
||||||
'Port {name} ({details}) unavailable for external networks'
|
'Port {name} ({details}) unavailable for external networks'
|
||||||
).format(name=port, details=details)
|
)
|
||||||
|
testname = format_lazy(template, name=port, details=details)
|
||||||
results.append([message, result])
|
results.append([testname, result])
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ FreedomBox app to interface with network-manager.
|
|||||||
import subprocess
|
import subprocess
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
|
|
||||||
|
from django.utils.text import format_lazy
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
@ -175,4 +176,7 @@ def _diagnose_dnssec(kind='4'):
|
|||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return [_('Using DNSSEC on IPv{kind}').format(kind=kind), result]
|
template = _('Using DNSSEC on IPv{kind}')
|
||||||
|
testname = format_lazy(template, kind=kind)
|
||||||
|
|
||||||
|
return [testname, result]
|
||||||
|
|||||||
@ -6,13 +6,12 @@ FreedomBox app to manage users.
|
|||||||
import grp
|
import grp
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth import app as app_module
|
from plinth import app as app_module
|
||||||
from plinth import cfg, menu
|
from plinth import cfg, menu
|
||||||
from plinth.daemon import Daemon
|
from plinth.daemon import Daemon
|
||||||
from plinth.utils import format_lazy
|
from django.utils.text import format_lazy
|
||||||
|
from django.utils.translation import ugettext_lazy as _, ugettext_lazy
|
||||||
|
|
||||||
from .components import UsersAndGroups
|
from .components import UsersAndGroups
|
||||||
|
|
||||||
@ -111,10 +110,10 @@ def _diagnose_ldap_entry(search_item):
|
|||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return [
|
template = ugettext_lazy('Check LDAP entry "{search_item}"')
|
||||||
_('Check LDAP entry "{search_item}"').format(search_item=search_item),
|
testname = format_lazy(template, search_item=search_item)
|
||||||
result
|
|
||||||
]
|
return [testname, result]
|
||||||
|
|
||||||
|
|
||||||
def create_group(group):
|
def create_group(group):
|
||||||
|
|||||||
@ -177,6 +177,7 @@ body {
|
|||||||
|
|
||||||
.diagnostics-results .diagnostics-result {
|
.diagnostics-results .diagnostics-result {
|
||||||
width: 60px;
|
width: 60px;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sticky footer styles
|
/* Sticky footer styles
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user