mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Reorganize python sources into 'plinth' package
This commit is contained in:
1 parent
eaacd3864b
commit
65fa648d9f
109 files changed
+63
-61
No files matched your search
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# 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
|
||||
from .packages import init
|
||||
|
||||
__all__ = ['packages', 'init']
|
||||
|
||||
DEPENDS = ['system']
|
||||
@@ -0,0 +1,111 @@
|
||||
from django import forms
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.template.response import TemplateResponse
|
||||
from gettext import gettext as _
|
||||
|
||||
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"""
|
||||
output = actions.run('module-manager', ['list-enabled'])
|
||||
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', 'icon-gift', 'packages:index', 20)
|
||||
|
||||
|
||||
@login_required
|
||||
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"""
|
||||
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', cfg.python_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', cfg.python_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))
|
||||
@@ -0,0 +1,61 @@
|
||||
{% 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
{% endcomment %}
|
||||
|
||||
{% load bootstrap %}
|
||||
|
||||
{% block main_block %}
|
||||
|
||||
<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 %}
|
||||
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
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')
|
||||
)
|
||||
Reference in new issue
Block a user