Verified Commit 3a9c4128 authored by JoKeyser's avatar JoKeyser Committed by James Valleroy

setup: disable install button for currently unavailable apps

- Fixes #1229.
Signed-off-by: JoKeyser's avatarJohannes Keyser <johanneskeyser@posteo.de>
Reviewed-by: James Valleroy's avatarJames Valleroy <jvalleroy@mailbox.org>
parent d5797395
......@@ -143,6 +143,8 @@ class Helper(object):
return 'up-to-date'
if not current_version:
if any(self.list_unavailable_packages()):
return 'unavailable'
return 'needs-setup'
else:
return 'needs-update'
......@@ -166,6 +168,14 @@ class Helper(object):
'setup_version': version
})
def list_unavailable_packages(self):
"""List the unavailable packages managed by the module (if any)."""
cache = apt.Cache()
managed_pkgs = getattr(self.module, 'managed_packages', [])
unavailable_pkgs = [pkg_name for pkg_name in managed_pkgs
if pkg_name not in cache]
return unavailable_pkgs
def init(module_name, module):
"""Create a setup helper for a module for later use."""
......
......@@ -72,13 +72,22 @@
Please wait for a few moments before trying again.
{% endblocktrans %}
</div>
{% elif setup_helper.get_state == 'unavailable' %}
<div class="alert alert-warning" role="alert">
{% blocktrans trimmed %}
This application is currently unavailable in your distribution.
{% endblocktrans %}
</div>
{% endif %}
<input type="submit" class="btn btn-md btn-primary"
{{ package_manager_is_busy|yesno:'disabled="disabled"' }}
{% if setup_helper.get_state == 'needs-setup' %}
value="{% trans "Install" %}"
{% elif setup_helper.get_state == 'needs-upgrade' %}
value="{% trans "Update" %}"
{% elif setup_helper.get_state == 'unavailable' %}
value="{% trans "Install" %}" disabled="disabled"
{% endif %} />
</form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment