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/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'] diff --git a/modules/installed/system/packages.py b/modules/installed/system/packages.py new file mode 100644 index 000000000..276939358 --- /dev/null +++ b/modules/installed/system/packages.py @@ -0,0 +1,83 @@ +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 = actions.run("module-manager", ["list-available"]) + if error: + raise Exception("something is wrong: " + error) + modules_available = output.split() + + output, error = actions.run("module-manager", \ + ["list-enabled", cfg.python_root]) + if error: + raise Exception("something is wrong: " + error) + modules_enabled = output.split() + + 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-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-manager",\ + ["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.

""") + 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-manager", ["list-available"]) + if error: + raise Exception("something is wrong: " + error) + modules_available = output.split() + + output, error = actions.run("module-manager",\ + ["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