simple form for enabling/disabling owncloud module

This commit is contained in:
James Valleroy 2014-01-27 22:42:06 -05:00
parent 6a6185a744
commit 7c6f1e72fa
7 changed files with 65 additions and 17 deletions

1
actions/module-disable Normal file → Executable file
View File

@ -8,6 +8,7 @@ case "$2" in
owncloud)
if [ -e "$1"/modules/owncloud.py ] ; then
rm -f "$1"/modules/owncloud.py
echo "disabled owncloud"
fi
;;
esac

1
actions/module-enable Normal file → Executable file
View File

@ -8,6 +8,7 @@ case "$2" in
owncloud)
if [ ! -e "$1"/modules/owncloud.py ] ; then
ln -s "$1"/modules/installed/apps/owncloud.py "$1"/modules/owncloud.py
echo "enabled owncloud"
fi
;;
esac

2
actions/module-list-available Normal file → Executable file
View File

@ -1,6 +1,6 @@
#!/bin/sh
# Usage: module-list-available python_root
# Usage: module-list-available
# This will change when we switch to using aptitude.
# TODO: Replace this with something like "aptitude search -F %p plinth-"

0
actions/module-list-enabled Normal file → Executable file
View File

View File

@ -0,0 +1,61 @@
import cherrypy
from gettext import gettext as _
from auth import require
from plugin_mount import PagePlugin, FormPlugin
from forms import Form
import actions
import cfg
from util import Message
class Packages(PagePlugin, FormPlugin):
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):
output, error = '', ''
if 'submitted' in kwargs:
if 'owncloud_enable' in kwargs:
output, error = actions.superuser_run("module-enable", [cfg.python_root, "owncloud"])
# TODO: need to get plinth to load the module we just enabled
else:
output, error = actions.superuser_run("module-disable", [cfg.python_root, "owncloud"])
# TODO: need a smoother way for plinth to unload the module
main=_("""
<p>aptitude purge modules</p>
<p>aptitude install modules</p>
<p>The modules should depend on the appropriate Debian packages.</p>""")
main += self.form(self, Message(output), args, kwargs)
sidebar_right = _("""
<strong>Help</strong>
<p>On this page, you can add or remove %s plugins to your %s.</p>
<p>Plugins are just Debian packages, so Debian's usual package management features should make this job fairly easy.</p>""" % (cfg.product_name, cfg.box_name))
return self.fill_template(title=_("Add/Remove Plugins"), main=main, sidebar_right=sidebar_right)
def form(self, message=None, *args, **kwargs):
output, error = actions.run("module-list-available")
if error:
raise Exception("something is wrong: " + error)
modules_available = output.split()
output, error = actions.run("module-list-enabled", cfg.python_root)
if error:
raise Exception("something is wrong: " + error)
modules_enabled = output.split()
form = Form(title="Manage Plugins",
action=cfg.server_dir + "/sys/packages/index",
name="manage_modules",
message=message)
for module in modules_available:
form.checkbox(_("Enable %s" % module), name="%s_enable" % module, id="%s_enable" % module, checked = True if module in modules_enabled else False)
form.hidden(name="submitted", value="True")
form.html(_("""<p>Enabling a plugin will cause a corresponding page to appear in Plinth.</p>"""))
form.submit(_("Update setup"))
return form.render()

View File

@ -23,7 +23,6 @@ class Sys(PagePlugin):
self.register_page("sys")
self.menu = cfg.main_menu.add_item(_("System"), "icon-cog", "/sys", 100)
self.menu.add_item(_("Configure"), "icon-cog", "/sys/config", 10)
self.menu.add_item(_("Package Manager"), "icon-gift", "/sys/packages", 20)
self.menu.add_item(_("Users and Groups"), "icon-user", "/sys/users", 15)
@cherrypy.expose
@ -35,18 +34,3 @@ class Sys(PagePlugin):
general level. This is where you add/remove users, install
applications, reboot, etc.</p>
""" % {'product':cfg.product_name}))
@cherrypy.expose
@require()
def packages(self):
side=_("""
<strong>Help</strong>
<p>On this page, you can add or remove %s plugins to your %s.</p>
<p>Plugins are just Debian packages, so Debian's usual package management features should make this job fairly easy.</p>
""" % (cfg.product_name, cfg.box_name))
return self.fill_template(title=_("Add/Remove Plugins"), main=_("""
<p>aptitude purge modules</p>
<p>aptitude install modules</p>
<p>The modules should depend on the appropriate Debian packages.</p>"""),
sidebar_right=side)

1
modules/packages.py Symbolic link
View File

@ -0,0 +1 @@
installed/system/packages.py