From 05ef2921db90b296f5ce571b114a332797b1c44b Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 28 Jul 2015 16:51:19 +0530 Subject: [PATCH] package: Remove package module - It does not work on all the modules available. - It does not reload Plinth after changes. - As of now, there is not strong case for disabling modules in Plinth making it unnecessary UI complication. - Split into multiple small Debian packages is not yet implemented for Plinth. The module expects to work on the Debian modules. When smaller Debian packages are available perhaps we should consider using packages.py library instead. --- actions/module-manager | 85 ------------ data/etc/plinth/modules-enabled/packages | 1 - plinth/modules/packages/__init__.py | 27 ---- plinth/modules/packages/packages.py | 130 ------------------ .../modules/packages/templates/packages.html | 63 --------- plinth/modules/packages/tests/__init__.py | 0 plinth/modules/packages/urls.py | 28 ---- 7 files changed, 334 deletions(-) delete mode 100755 actions/module-manager delete mode 100644 data/etc/plinth/modules-enabled/packages delete mode 100644 plinth/modules/packages/__init__.py delete mode 100644 plinth/modules/packages/packages.py delete mode 100644 plinth/modules/packages/templates/packages.html delete mode 100644 plinth/modules/packages/tests/__init__.py delete mode 100644 plinth/modules/packages/urls.py diff --git a/actions/module-manager b/actions/module-manager deleted file mode 100755 index 275aba608..000000000 --- a/actions/module-manager +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/sh -# -# This file is part of Plinth. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -# Usage: -# module-manager list-available -# module-manager list-enabled -# module-manager enable -# module-manager disable - -# list of modules that may be enabled/disabled -modules="owncloud" - -case "$1" in -"list-available") - # TODO: Replace this with something like "aptitude search -F %p plinth-" - echo "$modules" - ;; - -"list-enabled") - # TODO: Replace this with something like 'aptitude search -F %p | grep "plinth-"' - for module in "$modules" - do - if [ -e "$2"/modules/enabled/"$module" ] ; then - echo "$module" - fi - done - ;; - -"enable") - # TODO: Replace this with "aptitude install plinth-" - for module in "$modules" - do - if [ "$3" = "$module" ] ; then - if [ ! -e "$2"/modules/enabled/"$3" ] ; then - touch "$2"/modules/enabled/"$3" - RETVAL=$? - if [ $RETVAL -eq 0 ] ; then - echo "enabled" "$3" - else - echo "failed to enable" "$3" - fi - exit $RETVAL - fi - fi - done - echo "failed to enable invalid module" "$3" - exit 1 - ;; - -"disable") - # TODO: Replace this with "aptitude purge plinth-" - for module in "$modules" - do - if [ "$3" = "$module" ] ; then - if [ -e "$2"/modules/enabled/"$3" ] ; then - rm -f "$2"/modules/enabled/"$3" - RETVAL=$? - if [ $RETVAL -eq 0 ] ; then - echo "disabled" "$3" - else - echo "failed to disable" "$3" - fi - exit $RETVAL - fi - fi - done - echo "failed to disable invalid module" "$3" - exit 1 - ;; -esac diff --git a/data/etc/plinth/modules-enabled/packages b/data/etc/plinth/modules-enabled/packages deleted file mode 100644 index 4e007642b..000000000 --- a/data/etc/plinth/modules-enabled/packages +++ /dev/null @@ -1 +0,0 @@ -plinth.modules.packages diff --git a/plinth/modules/packages/__init__.py b/plinth/modules/packages/__init__.py deleted file mode 100644 index 64b060a1a..000000000 --- a/plinth/modules/packages/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -# -# This file is part of Plinth. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -""" -Plinth module to manage packages -""" - -from . import packages -from .packages import init - -__all__ = ['packages', 'init'] - -depends = ['plinth.modules.system'] diff --git a/plinth/modules/packages/packages.py b/plinth/modules/packages/packages.py deleted file mode 100644 index ce92dff64..000000000 --- a/plinth/modules/packages/packages.py +++ /dev/null @@ -1,130 +0,0 @@ -# -# This file is part of Plinth. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -from django import forms -from django.contrib import messages -from django.template.response import TemplateResponse -from gettext import gettext as _ -import os - -from plinth import actions -from plinth import cfg - - -def get_modules_available(): - """Return list of all modules""" - output = actions.run('module-manager', ['list-available']) - return output.split() - - -def get_modules_enabled(): - """Return list of all modules""" - root = os.path.join(os.path.dirname(__file__), '..', '..') - output = actions.run('module-manager', - ['list-enabled', root]) - return output.split() - - -class PackagesForm(forms.Form): - """Packages form""" - def __init__(self, *args, **kwargs): - # pylint: disable-msg=E1002, E1101 - super(forms.Form, self).__init__(*args, **kwargs) - - modules_available = get_modules_available() - - for module in modules_available: - label = _('Enable {module}').format(module=module) - self.fields[module + '_enabled'] = forms.BooleanField( - label=label, required=False) - - -def init(): - """Initialize the Packages module""" - menu = cfg.main_menu.get('system:index') - menu.add_urlname('Package Manager', 'glyphicon-gift', 'packages:index', 20) - - -def index(request): - """Serve the form""" - status = get_status() - - form = None - - if request.method == 'POST': - form = PackagesForm(request.POST, prefix='packages') - # pylint: disable-msg=E1101 - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = PackagesForm(initial=status, prefix='packages') - else: - form = PackagesForm(initial=status, prefix='packages') - - return TemplateResponse(request, 'packages.html', - {'title': _('Add/Remove Plugins'), - 'form': form}) - - -def get_status(): - """Return the current status""" - modules_available = get_modules_available() - modules_enabled = get_modules_enabled() - - return {module + '_enabled': module in modules_enabled - for module in modules_available} - - -def _apply_changes(request, old_status, new_status): - """Apply form changes""" - root = os.path.join(os.path.dirname(__file__), '..', '..') - for field, enabled in new_status.items(): - if not field.endswith('_enabled'): - continue - - if old_status[field] == new_status[field]: - continue - - module = field.split('_enabled')[0] - if enabled: - try: - actions.superuser_run('module-manager', - ['enable', root, module]) - except Exception: - # TODO: need to get plinth to load the module we just - # enabled - messages.error( - request, _('Error enabling module - {module}').format( - module=module)) - else: - messages.success( - request, _('Module enabled - {module}').format( - module=module)) - else: - try: - actions.superuser_run('module-manager', - ['disable', root, module]) - except Exception: - # TODO: need a smoother way for plinth to unload the - # module - messages.error( - request, _('Error disabling module - {module}').format( - module=module)) - else: - messages.success( - request, _('Module disabled - {module}').format( - module=module)) diff --git a/plinth/modules/packages/templates/packages.html b/plinth/modules/packages/templates/packages.html deleted file mode 100644 index 6254df28d..000000000 --- a/plinth/modules/packages/templates/packages.html +++ /dev/null @@ -1,63 +0,0 @@ -{% extends "base.html" %} -{% comment %} -# -# This file is part of Plinth. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -{% endcomment %} - -{% load bootstrap %} - -{% block content %} - -

{{ title }}

- -

aptitude purge modules

- -

aptitude install modules

- -

The modules should depend on the appropriate Debian packages.

- -

Manage Plugins

- -
- {% csrf_token %} - - {{ form|bootstrap }} - -

Enabling a plugin will cause a corresponding page to appear in - Plinth.

- - - -
- -{% endblock %} - -{% block sidebar %} - - - -{% endblock %} diff --git a/plinth/modules/packages/tests/__init__.py b/plinth/modules/packages/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/plinth/modules/packages/urls.py b/plinth/modules/packages/urls.py deleted file mode 100644 index 6eaf99b04..000000000 --- a/plinth/modules/packages/urls.py +++ /dev/null @@ -1,28 +0,0 @@ -# -# This file is part of Plinth. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -""" -URLs for the Packages module -""" - -from django.conf.urls import patterns, url - - -urlpatterns = patterns( # pylint: disable-msg=C0103 - 'plinth.modules.packages.packages', - url(r'^sys/packages/$', 'index', name='index') -)