From 6a6185a7444e09d632024e5bd61d2bf48619d714 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sun, 26 Jan 2014 21:59:58 -0500 Subject: [PATCH 1/5] Added actions to manage modules (manually adding/removing symlinks for now). --- actions/module-disable | 13 +++++++++++++ actions/module-enable | 13 +++++++++++++ actions/module-list-available | 7 +++++++ actions/module-list-enabled | 9 +++++++++ 4 files changed, 42 insertions(+) create mode 100644 actions/module-disable create mode 100644 actions/module-enable create mode 100644 actions/module-list-available create mode 100644 actions/module-list-enabled diff --git a/actions/module-disable b/actions/module-disable new file mode 100644 index 000000000..cf77decce --- /dev/null +++ b/actions/module-disable @@ -0,0 +1,13 @@ +#!/bin/sh + +# Usage: module-disable python_root module +# This will change when we switch to using aptitude. + +# TODO: Replace this with "aptitude purge plinth-" +case "$2" in + owncloud) + if [ -e "$1"/modules/owncloud.py ] ; then + rm -f "$1"/modules/owncloud.py + fi + ;; +esac diff --git a/actions/module-enable b/actions/module-enable new file mode 100644 index 000000000..6f7ed169f --- /dev/null +++ b/actions/module-enable @@ -0,0 +1,13 @@ +#!/bin/sh + +# Usage: module-enable python_root module +# This will change when we switch to using aptitude. + +# TODO: Replace this with "aptitude install plinth-" +case "$2" in + owncloud) + if [ ! -e "$1"/modules/owncloud.py ] ; then + ln -s "$1"/modules/installed/apps/owncloud.py "$1"/modules/owncloud.py + fi + ;; +esac diff --git a/actions/module-list-available b/actions/module-list-available new file mode 100644 index 000000000..626af92f1 --- /dev/null +++ b/actions/module-list-available @@ -0,0 +1,7 @@ +#!/bin/sh + +# Usage: module-list-available python_root +# This will change when we switch to using aptitude. + +# TODO: Replace this with something like "aptitude search -F %p plinth-" +echo "owncloud" diff --git a/actions/module-list-enabled b/actions/module-list-enabled new file mode 100644 index 000000000..4c378a618 --- /dev/null +++ b/actions/module-list-enabled @@ -0,0 +1,9 @@ +#!/bin/sh + +# Usage: module-list-enabled python_root +# This will change when we switch to using aptitude. + +# TODO: Replace this with something like 'aptitude search -F %p | grep "plinth-"' +if [ -e "$1"/modules/owncloud.py ] ; then + echo "owncloud" +fi From 7c6f1e72facd81fe538e108b862377846198f4a5 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Mon, 27 Jan 2014 22:42:06 -0500 Subject: [PATCH 2/5] 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 From 411785eb3f2c254f50581e05994ff45d6bdb7429 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Fri, 31 Jan 2014 19:48:40 -0500 Subject: [PATCH 3/5] Make module manager work for any available modules. --- modules/installed/system/packages.py | 36 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/modules/installed/system/packages.py b/modules/installed/system/packages.py index 0e06bbce0..5b627333d 100644 --- a/modules/installed/system/packages.py +++ b/modules/installed/system/packages.py @@ -18,16 +18,34 @@ class Packages(PagePlugin, FormPlugin): @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 + 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() - main=_(""" + if 'submitted' in kwargs: + del kwargs['submitted'] + modules_selected = map(lambda x: x.split("_")[0], kwargs.keys()) + for module in modules_available: + if module in modules_enabled: + if module not in modules_selected: + output, error = actions.superuser_run(\ + "module-disable", [cfg.python_root, module]) + # TODO: need a smoother way for plinth + # to unload the module + else: + if module in modules_selected: + output, error = actions.superuser_run(\ + "module-enable", [cfg.python_root, module]) + # TODO: need to get plinth to load + # the module we just enabled + + main = _("""

aptitude purge modules

aptitude install modules

The modules should depend on the appropriate Debian packages.

""") From c9d58ee73dc9815ac899ed458d2ec014e465a156 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Fri, 31 Jan 2014 21:44:32 -0500 Subject: [PATCH 4/5] Combined module management actions into a single file, so it should be easier to add new optional modules. --- actions/module-disable | 14 ------- actions/module-enable | 14 ------- actions/module-list-available | 7 ---- actions/module-list-enabled | 9 ----- actions/module-manager | 59 ++++++++++++++++++++++++++++ modules/installed/system/packages.py | 16 +++++--- 6 files changed, 69 insertions(+), 50 deletions(-) delete mode 100755 actions/module-disable delete mode 100755 actions/module-enable delete mode 100755 actions/module-list-available delete mode 100755 actions/module-list-enabled create mode 100755 actions/module-manager diff --git a/actions/module-disable b/actions/module-disable deleted file mode 100755 index d383d43cc..000000000 --- a/actions/module-disable +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -# Usage: module-disable python_root module -# This will change when we switch to using aptitude. - -# TODO: Replace this with "aptitude purge plinth-" -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 deleted file mode 100755 index 18e587fd6..000000000 --- a/actions/module-enable +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -# Usage: module-enable python_root module -# This will change when we switch to using aptitude. - -# TODO: Replace this with "aptitude install plinth-" -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 deleted file mode 100755 index 7814a4015..000000000 --- a/actions/module-list-available +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -# Usage: module-list-available -# This will change when we switch to using aptitude. - -# TODO: Replace this with something like "aptitude search -F %p plinth-" -echo "owncloud" diff --git a/actions/module-list-enabled b/actions/module-list-enabled deleted file mode 100755 index 4c378a618..000000000 --- a/actions/module-list-enabled +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -# Usage: module-list-enabled python_root -# This will change when we switch to using aptitude. - -# TODO: Replace this with something like 'aptitude search -F %p | grep "plinth-"' -if [ -e "$1"/modules/owncloud.py ] ; then - echo "owncloud" -fi diff --git a/actions/module-manager b/actions/module-manager new file mode 100755 index 000000000..624e1f91a --- /dev/null +++ b/actions/module-manager @@ -0,0 +1,59 @@ +#!/bin/bash + +# Usage: +# module-manager list-available +# module-manager list-enabled +# module-manager enable +# module-manager disable + +# associate array with mapping between module names and install paths +# (relative to /modules/) +declare -A modules=( ["owncloud"]="installed/apps/owncloud.py" ) + +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/"$module".py ] ; 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/"$3".py ] ; then + ln -s "$2"/modules/"${modules["$3"]}" "$2"/modules/"$3".py + RETVAL=$? + [ $RETVAL -eq 0 ] && echo "enabled" "$3" + [ $RETVAL -ne 0 ] && echo "failed to enable" "$3" + fi + fi + done + ;; + +"disable") + # TODO: Replace this with "aptitude purge plinth-" + for module in "${!modules[@]}" + do + if [ "$3" == "$module" ] ; then + if [ -e "$2"/modules/"$3".py ] ; then + rm -f "$2"/modules/"$3".py + RETVAL=$? + [ $RETVAL -eq 0 ] && echo "disabled" "$3" + [ $RETVAL -ne 0 ] && echo "failed to disable" "$3" + fi + fi + done + ;; +esac + diff --git a/modules/installed/system/packages.py b/modules/installed/system/packages.py index 5b627333d..276939358 100644 --- a/modules/installed/system/packages.py +++ b/modules/installed/system/packages.py @@ -18,12 +18,13 @@ class Packages(PagePlugin, FormPlugin): @cherrypy.expose @require() def index(self, *args, **kwargs): - output, error = actions.run("module-list-available") + output, error = actions.run("module-manager", ["list-available"]) if error: raise Exception("something is wrong: " + error) modules_available = output.split() - output, error = actions.run("module-list-enabled", cfg.python_root) + output, error = actions.run("module-manager", \ + ["list-enabled", cfg.python_root]) if error: raise Exception("something is wrong: " + error) modules_enabled = output.split() @@ -35,13 +36,15 @@ class Packages(PagePlugin, FormPlugin): if module in modules_enabled: if module not in modules_selected: output, error = actions.superuser_run(\ - "module-disable", [cfg.python_root, module]) + "module-manager",\ + ["disable", cfg.python_root, module]) # TODO: need a smoother way for plinth # to unload the module else: if module in modules_selected: output, error = actions.superuser_run(\ - "module-enable", [cfg.python_root, module]) + "module-manager",\ + ["enable", cfg.python_root, module]) # TODO: need to get plinth to load # the module we just enabled @@ -57,12 +60,13 @@ class Packages(PagePlugin, FormPlugin): 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") + output, error = actions.run("module-manager", ["list-available"]) if error: raise Exception("something is wrong: " + error) modules_available = output.split() - output, error = actions.run("module-list-enabled", cfg.python_root) + output, error = actions.run("module-manager",\ + ["list-enabled", cfg.python_root]) if error: raise Exception("something is wrong: " + error) modules_enabled = output.split() From 1e21712fa5b766bbaf7504d0a6070065d6944cc8 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Fri, 31 Jan 2014 23:19:38 -0500 Subject: [PATCH 5/5] Instead of a separate page and form classes for ownCloud module, just need one class that does both. --- modules/installed/apps/owncloud.py | 40 +++++++++++++----------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/modules/installed/apps/owncloud.py b/modules/installed/apps/owncloud.py index 92b004029..fff75bc8c 100644 --- a/modules/installed/apps/owncloud.py +++ b/modules/installed/apps/owncloud.py @@ -7,40 +7,36 @@ import actions import cfg from util import Message -class Owncloud(PagePlugin): +class Owncloud(PagePlugin, FormPlugin): order = 90 def __init__(self, *args, **kwargs): PagePlugin.__init__(self, *args, **kwargs) self.register_page("apps.owncloud") - self.register_page("apps.owncloud.configure") cfg.html_root.apps.menu.add_item("Owncloud", "icon-picture", "/apps/owncloud", 35) @cherrypy.expose @require() def index(self, **kwargs): - main=""" -

ownCloud gives you universal access to your files through a web interface or WebDAV. It also provides a platform to easily view & sync your contacts, calendars and bookmarks across all your devices and enables basic editing right on the web. Installation has minimal server requirements, doesn't need special permissions and is quick. ownCloud is extendable via a simple but powerful API for applications and plugins. -

-""" - sidebar_right = 'Configure Owncloud' - return self.fill_template(title="Owncloud", main=main, sidebar_right=sidebar_right) - -class configure(FormPlugin, PagePlugin): - url = ["/apps/owncloud/configure"] - - sidebar_left = '' - sidebar_right = _("Configure Owncloud") - - def main(self, owncloud_enable=False, message=None, *args, **kwargs): output, error = actions.run("owncloud-setup", 'status') if error: raise Exception("something is wrong: " + error) - if "enable" in output.split(): - owncloud_enable = True + owncloud_enable = "enable" in output.split() + if 'submitted' in kwargs: + owncloud_enable = self.process_form(kwargs) + + main = self.form(owncloud_enable) + sidebar_right=""" +ownCloud
+

ownCloud gives you universal access to your files through a web interface or WebDAV. It also provides a platform to easily view & sync your contacts, calendars and bookmarks across all your devices and enables basic editing right on the web. Installation has minimal server requirements, doesn't need special permissions and is quick. ownCloud is extendable via a simple but powerful API for applications and plugins. +

+""" + return self.fill_template(title="Owncloud", main=main, sidebar_right=sidebar_right) + + def form(self, owncloud_enable, message=None): form = Form(title="Configuration", - action=cfg.server_dir + "/apps/owncloud/configure/index", + action=cfg.server_dir + "/apps/owncloud/index", name="configure_owncloud", message=message) form.checkbox(_("Enable Owncloud"), name="owncloud_enable", id="owncloud_enable", checked=owncloud_enable) @@ -50,7 +46,7 @@ class configure(FormPlugin, PagePlugin): form.submit(_("Update setup")) return form.render() - def process_form(self, **kwargs): + def process_form(self, kwargs): checkedinfo = { 'enable' : False, } @@ -68,6 +64,4 @@ class configure(FormPlugin, PagePlugin): opts.append('no'+key) actions.superuser_run("owncloud-setup", opts, async=True) - main = self.main(checkedinfo['enable']) - return self.fill_template(title="Owncloud Configuration", main=main, sidebar_left=self.sidebar_left, sidebar_right=self.sidebar_right) - + return checkedinfo['enable']