mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
upgrades: Use new setup mechanism
This commit is contained in:
parent
065d6c4c0a
commit
b5ccada3a6
@ -21,14 +21,32 @@ Plinth module for upgrades
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from plinth import actions
|
||||
from plinth import cfg
|
||||
|
||||
|
||||
version = 1
|
||||
|
||||
is_essential = 1
|
||||
|
||||
depends = ['system']
|
||||
|
||||
title = _('Software Upgrades')
|
||||
|
||||
description = [
|
||||
_('Upgrades install the latest software and security updates. When '
|
||||
'automatic upgrades are enabled, upgrades are automatically run every '
|
||||
'night. You don\'t normally need to start the upgrade process.')
|
||||
]
|
||||
|
||||
|
||||
def init():
|
||||
"""Initialize the module."""
|
||||
menu = cfg.main_menu.get('system:index')
|
||||
menu.add_urlname(_('Software Upgrades'), 'glyphicon-refresh',
|
||||
'upgrades:index', 21)
|
||||
menu.add_urlname(title, 'glyphicon-refresh', 'upgrades:index', 21)
|
||||
|
||||
|
||||
def setup(helper, old_version=None):
|
||||
"""Install and configure the module."""
|
||||
helper.install(['unattended-upgrades'])
|
||||
helper.call('post', actions.superuser_run, 'upgrades', ['enable-auto'])
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
{% extends 'base.html' %}
|
||||
{% extends 'app.html' %}
|
||||
{% comment %}
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
@ -29,17 +29,7 @@
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>{{ title }}</h2>
|
||||
|
||||
<p>
|
||||
{% blocktrans trimmed %}
|
||||
Upgrades install the latest software and security updates. When automatic
|
||||
upgrades are enabled, upgrades are automatically run every night. You
|
||||
don't normally need to start the upgrade process.
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
{% block configuration %}
|
||||
|
||||
<p>
|
||||
{% blocktrans trimmed %}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% extends "app.html" %}
|
||||
{% comment %}
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
@ -21,9 +21,7 @@
|
||||
{% load bootstrap %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>{{ title }}</h2>
|
||||
{% block configuration %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
@ -21,16 +21,14 @@ Plinth module for upgrades
|
||||
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.shortcuts import redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
from django.views.decorators.http import require_POST
|
||||
import subprocess
|
||||
|
||||
from .forms import ConfigureForm
|
||||
from plinth import actions
|
||||
from plinth import package
|
||||
from plinth.errors import ActionError
|
||||
from plinth.modules import upgrades
|
||||
|
||||
subsubmenu = [{'url': reverse_lazy('upgrades:index'),
|
||||
'text': ugettext_lazy('Automatic Upgrades')},
|
||||
@ -41,12 +39,6 @@ LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
|
||||
LOCK_FILE = '/var/log/dpkg/lock'
|
||||
|
||||
|
||||
def on_install():
|
||||
"""Enable automatic upgrades after install."""
|
||||
actions.superuser_run('upgrades', ['enable-auto'])
|
||||
|
||||
|
||||
@package.required(['unattended-upgrades'], on_install=on_install)
|
||||
def index(request):
|
||||
"""Serve the configuration form."""
|
||||
status = get_status()
|
||||
@ -63,10 +55,12 @@ def index(request):
|
||||
form = ConfigureForm(initial=status, prefix='upgrades')
|
||||
|
||||
return TemplateResponse(request, 'upgrades_configure.html',
|
||||
{'title': _('Automatic Upgrades'),
|
||||
{'title': upgrades.title,
|
||||
'description': upgrades.description,
|
||||
'form': form,
|
||||
'subsubmenu': subsubmenu})
|
||||
|
||||
|
||||
def is_package_manager_busy():
|
||||
"""Return whether a package manager is running."""
|
||||
try:
|
||||
@ -85,7 +79,6 @@ def get_log():
|
||||
return None
|
||||
|
||||
|
||||
@package.required(['unattended-upgrades'], on_install=on_install)
|
||||
def upgrade(request):
|
||||
"""Serve the upgrade page."""
|
||||
is_busy = is_package_manager_busy()
|
||||
@ -99,7 +92,8 @@ def upgrade(request):
|
||||
messages.error(request, _('Starting upgrade failed.'))
|
||||
|
||||
return TemplateResponse(request, 'upgrades.html',
|
||||
{'title': _('Package Upgrades'),
|
||||
{'title': upgrades.title,
|
||||
'description': upgrades.description,
|
||||
'subsubmenu': subsubmenu,
|
||||
'is_busy': is_busy,
|
||||
'log': get_log()})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user