mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
Merge pull request #59 from jvalleroy/module-manager
Merge: James Valleroy's Plinth Module Manager
This commit is contained in:
commit
434a2a5833
59
actions/module-manager
Executable file
59
actions/module-manager
Executable file
@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage:
|
||||
# module-manager list-available
|
||||
# module-manager list-enabled <python_root>
|
||||
# module-manager enable <python_root> <module_name>
|
||||
# module-manager disable <python_root> <module_name>
|
||||
|
||||
# associate array with mapping between module names and install paths
|
||||
# (relative to <python_root>/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-<module>"
|
||||
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-<module>"
|
||||
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
|
||||
|
||||
@ -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="""
|
||||
<p>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.
|
||||
</p>
|
||||
"""
|
||||
sidebar_right = '<strong><a href="'+cfg.server_dir+'/apps/owncloud/configure">Configure Owncloud</a></strong>'
|
||||
return self.fill_template(title="Owncloud", main=main, sidebar_right=sidebar_right)
|
||||
|
||||
class configure(FormPlugin, PagePlugin):
|
||||
url = ["/apps/owncloud/configure"]
|
||||
|
||||
sidebar_left = ''
|
||||
sidebar_right = _("<strong>Configure Owncloud</strong>")
|
||||
|
||||
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="""
|
||||
<strong>ownCloud</strong></br>
|
||||
<p>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.
|
||||
</p>
|
||||
"""
|
||||
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']
|
||||
|
||||
83
modules/installed/system/packages.py
Normal file
83
modules/installed/system/packages.py
Normal file
@ -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 = _("""
|
||||
<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-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(_("""<p>Enabling a plugin will cause a corresponding page to appear in Plinth.</p>"""))
|
||||
form.submit(_("Update setup"))
|
||||
return form.render()
|
||||
@ -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
1
modules/packages.py
Symbolic link
@ -0,0 +1 @@
|
||||
installed/system/packages.py
|
||||
Loading…
x
Reference in New Issue
Block a user