From be838a30c1c00522d5d636310b5b06457f8acc42 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 17 Mar 2015 17:10:05 +0530 Subject: [PATCH] package: Add ability to receive notification on install - Fix issue with Mumble firewall enabling after a fresh install. --- plinth/modules/firewall/firewall.py | 2 +- plinth/modules/mumble/views.py | 7 ++++++- plinth/modules/owncloud/owncloud.py | 2 +- plinth/modules/pagekite/pagekite.py | 2 +- plinth/modules/tor/tor.py | 2 +- plinth/modules/upgrades/upgrades.py | 6 +++--- plinth/modules/xmpp/xmpp.py | 2 +- plinth/package.py | 18 ++++++++++++------ plinth/views.py | 3 ++- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/plinth/modules/firewall/firewall.py b/plinth/modules/firewall/firewall.py index 189762255..b7a5d0dc6 100644 --- a/plinth/modules/firewall/firewall.py +++ b/plinth/modules/firewall/firewall.py @@ -43,7 +43,7 @@ def init(): @login_required -@package.required('firewalld') +@package.required(['firewalld']) def index(request): """Serve introcution page""" if not get_enabled_status(): diff --git a/plinth/modules/mumble/views.py b/plinth/modules/mumble/views.py index 767b9cd4e..afddb4262 100644 --- a/plinth/modules/mumble/views.py +++ b/plinth/modules/mumble/views.py @@ -33,8 +33,13 @@ from plinth.modules import mumble logger = logging.getLogger(__name__) +def on_install(): + """Notify that the service is now enabled.""" + mumble.service.notify_enabled(None, True) + + @login_required -@package.required('mumble-server') +@package.required(['mumble-server'], on_install=on_install) def index(request): """Serve configuration page.""" status = get_status() diff --git a/plinth/modules/owncloud/owncloud.py b/plinth/modules/owncloud/owncloud.py index cd3402d8d..96c743507 100644 --- a/plinth/modules/owncloud/owncloud.py +++ b/plinth/modules/owncloud/owncloud.py @@ -48,7 +48,7 @@ def init(): @login_required -@package.required('postgresql', 'php5-pgsql', 'owncloud') +@package.required(['postgresql', 'php5-pgsql', 'owncloud']) def index(request): """Serve the ownCloud configuration page""" status = get_status() diff --git a/plinth/modules/pagekite/pagekite.py b/plinth/modules/pagekite/pagekite.py index 519a7b0fd..132d7fff7 100644 --- a/plinth/modules/pagekite/pagekite.py +++ b/plinth/modules/pagekite/pagekite.py @@ -102,7 +102,7 @@ https://pagekite.net/wiki/Howto/SshOverPageKite/">instructions')) @login_required -@package.required('pagekite') +@package.required(['pagekite']) def configure(request): """Serve the configuration form""" status = get_status() diff --git a/plinth/modules/tor/tor.py b/plinth/modules/tor/tor.py index 7e300d169..37089fb0b 100644 --- a/plinth/modules/tor/tor.py +++ b/plinth/modules/tor/tor.py @@ -44,7 +44,7 @@ def init(): @login_required -@package.required('tor') +@package.required(['tor']) def index(request): """Service the index page""" status = get_status() diff --git a/plinth/modules/upgrades/upgrades.py b/plinth/modules/upgrades/upgrades.py index 745010d8a..7a67759ac 100644 --- a/plinth/modules/upgrades/upgrades.py +++ b/plinth/modules/upgrades/upgrades.py @@ -46,7 +46,7 @@ def init(): @login_required -@package.required('unattended-upgrades') +@package.required(['unattended-upgrades']) def index(request): """Serve the index page.""" return TemplateResponse(request, 'upgrades.html', @@ -56,7 +56,7 @@ def index(request): @login_required @require_POST -@package.required('unattended-upgrades') +@package.required(['unattended-upgrades']) def run(request): """Run upgrades and show the output page.""" output = '' @@ -85,7 +85,7 @@ available.')) @login_required -@package.required('unattended-upgrades') +@package.required(['unattended-upgrades']) def configure(request): """Serve the configuration form.""" status = get_status() diff --git a/plinth/modules/xmpp/xmpp.py b/plinth/modules/xmpp/xmpp.py index 718c981e5..125ea3448 100644 --- a/plinth/modules/xmpp/xmpp.py +++ b/plinth/modules/xmpp/xmpp.py @@ -62,7 +62,7 @@ def init(): @login_required -@package.required('jwchat', 'ejabberd') +@package.required(['jwchat', 'ejabberd']) def index(request): """Serve XMPP page""" return TemplateResponse(request, 'xmpp.html', diff --git a/plinth/package.py b/plinth/package.py index e7fd3a344..bce510d0c 100644 --- a/plinth/package.py +++ b/plinth/package.py @@ -35,12 +35,14 @@ packages_resolved = {} class Transaction(object): """Information about an ongoing transaction.""" - def __init__(self, package_names): + def __init__(self, package_names, on_install=None): """Initialize transaction object. Set most values to None until they are sent as progress update. """ self.package_names = package_names + # XXX: This is hack, remove after implementing proper setup mechanism. + self.on_install = on_install # Progress self.allow_cancel = None @@ -120,10 +122,13 @@ class Transaction(object): Remove self from global transactions list. """ + if self.status == packagekit.StatusEnum.FINISHED: + self.on_install() + del transactions[self.get_id()] -def required(*package_names): +def required(package_names, on_install=None): """Decorate a view to check and install required packages.""" def wrapper2(func): @@ -137,7 +142,8 @@ def required(*package_names): return func(request, *args, **kwargs) view = plinth.views.PackageInstallView.as_view() - return view(request, package_names=package_names, *args, **kwargs) + return view(request, package_names=package_names, + on_install=on_install, *args, **kwargs) return wrapper @@ -155,7 +161,7 @@ def check_installed(package_names): client = packagekit.Client() response = client.resolve(packagekit.FilterEnum.INSTALLED, - package_names + (None, ), None, + tuple(package_names) + (None, ), None, _callback, None) installed_package_names = [] @@ -173,12 +179,12 @@ def is_installing(package_names): return frozenset(package_names) in transactions -def start_install(package_names): +def start_install(package_names, on_install=None): """Start a PackageKit transaction to install given list of packages. This operation is non-blocking at it spawns a new thread. """ - transaction = Transaction(package_names) + transaction = Transaction(package_names, on_install=on_install) transactions[frozenset(package_names)] = transaction transaction.start_install() diff --git a/plinth/views.py b/plinth/views.py index e63501af5..9dc1af75d 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -58,5 +58,6 @@ class PackageInstallView(TemplateView): Start the package installation, and refresh the page every x seconds to keep displaying PackageInstallView.get() with the installation status. """ - package_module.start_install(self.kwargs['package_names']) + package_module.start_install(self.kwargs['package_names'], + on_install=self.kwargs.get('on_install')) return self.render_to_response(self.get_context_data())