From c9d58ee73dc9815ac899ed458d2ec014e465a156 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Fri, 31 Jan 2014 21:44:32 -0500 Subject: [PATCH] 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()