Move all modules from 'modules/installed' to 'modules' directory

This commit is contained in:
Sunil Mohan Adapa committed 2014-06-06 12:14:17 +05:30
1 parent 912c5022ca
commit 37206f1e83
72 files changed
+20 -22

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
#
# 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 <http://www.gnu.org/licenses/>.
#
"""
Plinth module to manage packages
"""
from . import packages
__all__ = ['packages']
+133
View File
@@ -0,0 +1,133 @@
import cherrypy
from django import forms
from gettext import gettext as _
from ..lib.auth import require
from plugin_mount import PagePlugin
import actions
import cfg
import util
def get_modules_available():
"""Return list of all modules"""
output, error = actions.run('module-manager', ['list-available'])
if error:
raise Exception('Error getting modules: %s' % error)
return output.split()
def get_modules_enabled():
"""Return list of all modules"""
output, error = actions.run('module-manager', ['list-enabled'])
if error:
raise Exception('Error getting enabled modules - %s' % error)
return output.split()
class PackagesForm(forms.Form):
"""Packages form"""
# XXX: Only present due to issue with submitting empty form
dummy = forms.CharField(label='Dummy', initial='dummy',
widget=forms.HiddenInput())
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)
class Packages(PagePlugin):
"""Package page"""
order = 20
def __init__(self, *args, **kwargs):
PagePlugin.__init__(self, *args, **kwargs)
self.register_page('sys.packages')
cfg.html_root.sys.menu.add_item('Package Manager', 'icon-gift',
'/sys/packages', 20)
@cherrypy.expose
@require()
def index(self, *args, **kwargs):
"""Serve the form"""
del args # Unused
status = self.get_status()
form = None
messages = []
if kwargs:
form = PackagesForm(kwargs, prefix='packages')
# pylint: disable-msg=E1101
if form.is_valid():
self._apply_changes(status, form.cleaned_data, messages)
status = self.get_status()
form = PackagesForm(initial=status, prefix='packages')
else:
form = PackagesForm(initial=status, prefix='packages')
return util.render_template(template='packages',
title=_('Add/Remove Plugins'),
form=form, messages=messages)
@staticmethod
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}
@staticmethod
def _apply_changes(old_status, new_status, messages):
"""Apply form changes"""
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:
output, error = actions.superuser_run(
'module-manager', ['enable', cfg.python_root, module])
del output # Unused
# TODO: need to get plinth to load the module we just
# enabled
if error:
messages.append(
('error', _('Error enabling module - {module}').format(
module=module)))
else:
messages.append(
('success', _('Module enabled - {module}').format(
module=module)))
else:
output, error = actions.superuser_run(
'module-manager', ['disable', cfg.python_root, module])
del output # Unused
# TODO: need a smoother way for plinth to unload the
# module
if error:
messages.append(
('error',
_('Error disabling module - {module}').format(
module=module)))
else:
messages.append(
('success', _('Module disabled - {module}').format(
module=module)))
+63
View File
@@ -0,0 +1,63 @@
{% extends "login_nav.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 <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load bootstrap %}
{% block main_block %}
{% include 'messages.html' %}
<p>aptitude purge modules</p>
<p>aptitude install modules</p>
<p>The modules should depend on the appropriate Debian packages.</p>
<h2>Manage Plugins</h2>
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<p>Enabling a plugin will cause a corresponding page to appear in
Plinth.</p>
<input type="submit" class="btn-primary" value="Update setup"/>
</form>
{% endblock %}
{% block sidebar_right_block %}
<div class="well sidebar-nav">
<h3>Help</h3>
<p>On this page, you can add or remove {{ cfg.product_name }}
plugins to your {{ cfg.box_name }}.</p>
<p>Plugins are just Debian packages, so Debian's usual package
management features should make this job fairly easy.</p>
</div>
{% endblock %}