From 7c6f1e72facd81fe538e108b862377846198f4a5 Mon Sep 17 00:00:00 2001
From: James Valleroy
Date: Mon, 27 Jan 2014 22:42:06 -0500
Subject: [PATCH] simple form for enabling/disabling owncloud module
---
actions/module-disable | 1 +
actions/module-enable | 1 +
actions/module-list-available | 2 +-
actions/module-list-enabled | 0
modules/installed/system/packages.py | 61 ++++++++++++++++++++++++++++
modules/installed/system/system.py | 16 --------
modules/packages.py | 1 +
7 files changed, 65 insertions(+), 17 deletions(-)
mode change 100644 => 100755 actions/module-disable
mode change 100644 => 100755 actions/module-enable
mode change 100644 => 100755 actions/module-list-available
mode change 100644 => 100755 actions/module-list-enabled
create mode 100644 modules/installed/system/packages.py
create mode 120000 modules/packages.py
diff --git a/actions/module-disable b/actions/module-disable
old mode 100644
new mode 100755
index cf77decce..d383d43cc
--- a/actions/module-disable
+++ b/actions/module-disable
@@ -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
diff --git a/actions/module-enable b/actions/module-enable
old mode 100644
new mode 100755
index 6f7ed169f..18e587fd6
--- a/actions/module-enable
+++ b/actions/module-enable
@@ -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
diff --git a/actions/module-list-available b/actions/module-list-available
old mode 100644
new mode 100755
index 626af92f1..7814a4015
--- a/actions/module-list-available
+++ b/actions/module-list-available
@@ -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-"
diff --git a/actions/module-list-enabled b/actions/module-list-enabled
old mode 100644
new mode 100755
diff --git a/modules/installed/system/packages.py b/modules/installed/system/packages.py
new file mode 100644
index 000000000..0e06bbce0
--- /dev/null
+++ b/modules/installed/system/packages.py
@@ -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=_("""
+aptitude purge modules
+aptitude install modules
+The modules should depend on the appropriate Debian packages.
""")
+ main += self.form(self, Message(output), args, kwargs)
+ sidebar_right = _("""
+Help
+On this page, you can add or remove %s plugins to your %s.
+Plugins are just Debian packages, so Debian's usual package management features should make this job fairly easy.
""" % (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(_("""Enabling a plugin will cause a corresponding page to appear in Plinth.
"""))
+ form.submit(_("Update setup"))
+ return form.render()
diff --git a/modules/installed/system/system.py b/modules/installed/system/system.py
index eba279a90..906a5b3ca 100644
--- a/modules/installed/system/system.py
+++ b/modules/installed/system/system.py
@@ -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.
""" % {'product':cfg.product_name}))
-
- @cherrypy.expose
- @require()
- def packages(self):
- side=_("""
-Help
-On this page, you can add or remove %s plugins to your %s.
-Plugins are just Debian packages, so Debian's usual package management features should make this job fairly easy.
-""" % (cfg.product_name, cfg.box_name))
- return self.fill_template(title=_("Add/Remove Plugins"), main=_("""
- aptitude purge modules
- aptitude install modules
- The modules should depend on the appropriate Debian packages.
"""),
- sidebar_right=side)
-
diff --git a/modules/packages.py b/modules/packages.py
new file mode 120000
index 000000000..fa4dedfc6
--- /dev/null
+++ b/modules/packages.py
@@ -0,0 +1 @@
+installed/system/packages.py
\ No newline at end of file