mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-19 10:04:05 +01:00
Refactored extension API
* Modoboa extensions must now declare themselves * Now using django 1.3 *staticfiles* module * Better distinction between *static* content and *media* content see #197
This commit is contained in:
+22
-29
@@ -10,7 +10,7 @@ from modoboa.lib import parameters, events
|
||||
from modoboa.lib.exceptions import PermDeniedException
|
||||
from modoboa.lib.sysutils import exec_cmd, exec_as_vuser
|
||||
from modoboa.lib.emailutils import split_mailbox
|
||||
from modoboa.extensions import get_ext_module
|
||||
from modoboa.extensions import exts_pool
|
||||
from exceptions import *
|
||||
import os, sys
|
||||
import pwd
|
||||
@@ -806,56 +806,49 @@ class Extension(models.Model):
|
||||
help_text=ugettext_lazy("Check to enable this extension")
|
||||
)
|
||||
|
||||
def init(self):
|
||||
module = get_ext_module(self.name)
|
||||
if hasattr(module, "init"):
|
||||
module.init()
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Extension, self).__init__(*args, **kwargs)
|
||||
self.instance = exts_pool.get_extension(self.name)
|
||||
self.__get_ext_dir()
|
||||
|
||||
def load(self):
|
||||
module = get_ext_module(self.name)
|
||||
if hasattr(module, "load"):
|
||||
module.load()
|
||||
|
||||
def unload(self):
|
||||
module = get_ext_module(self.name)
|
||||
module.destroy()
|
||||
def __get_ext_dir(self):
|
||||
modname = self.instance.__module__
|
||||
path = os.path.realpath(sys.modules[modname].__file__)
|
||||
self.extdir = os.path.dirname(path)
|
||||
|
||||
def on(self):
|
||||
self.enabled = True
|
||||
self.save()
|
||||
|
||||
self.load()
|
||||
self.init()
|
||||
self.instance.load()
|
||||
self.instance.init()
|
||||
|
||||
extdir = "%s/extensions/%s" % (settings.MODOBOA_DIR, self.name)
|
||||
scriptdir = "%s/%s" % (extdir, "scripts")
|
||||
if self.instance.needs_media:
|
||||
path = os.path.join(settings.MEDIA_ROOT, self.name)
|
||||
exec_cmd("mkdir %s" % path)
|
||||
|
||||
scriptdir = "%s/%s" % (self.extdir, "scripts")
|
||||
if os.path.exists(scriptdir):
|
||||
targetdir = os.path.join(settings.MODOBOA_DIR, "scripts")
|
||||
exec_cmd("ln -s %s %s/%s" % (scriptdir, targetdir, self.name))
|
||||
|
||||
staticpath = "%s/%s" % (extdir, "static")
|
||||
if os.path.exists(staticpath):
|
||||
exec_cmd("ln -s %s/static %s/static/%s" % \
|
||||
(extdir, settings.MODOBOA_DIR, self.name))
|
||||
|
||||
events.raiseEvent("ExtEnabled", self)
|
||||
|
||||
def off(self):
|
||||
self.unload()
|
||||
self.instance.destroy()
|
||||
|
||||
self.enabled = False
|
||||
self.save()
|
||||
|
||||
extdir = "%s/extensions/%s" % (settings.MODOBOA_DIR, self.name)
|
||||
scriptdir = "%s/%s" % (extdir, "scripts")
|
||||
if self.instance.needs_media:
|
||||
path = os.path.join(settings.MEDIA_ROOT, self.name)
|
||||
exec_cmd("rm -r %s" % path)
|
||||
|
||||
scriptdir = "%s/%s" % (self.extdir, "scripts")
|
||||
if os.path.exists(scriptdir):
|
||||
target = "%s/scripts/%s" % (settings.MODOBOA_DIR, self.name)
|
||||
exec_cmd("rm %s" % target)
|
||||
|
||||
staticpath = "%s/%s" % (extdir, "static")
|
||||
if os.path.exists(staticpath):
|
||||
exec_cmd("rm -r %s/static/%s" % (settings.MODOBOA_DIR, self.name))
|
||||
|
||||
events.raiseEvent("ExtDisabled", self)
|
||||
|
||||
def populate_callback(sender, user=None, **kwargs):
|
||||
|
||||
+2
-2
@@ -41,11 +41,11 @@ class DomainsTable(tables.Table):
|
||||
class ExtensionsTable(tables.Table):
|
||||
idkey = "id"
|
||||
selection = tables.SelectionColumn("selection", width="4%", header=False)
|
||||
name = tables.Column("name", label=ugettext_lazy("Name"), width="15%")
|
||||
label = tables.Column("label", label=ugettext_lazy("Name"), width="15%")
|
||||
version = tables.Column("version", label=ugettext_lazy("Version"), width="6%")
|
||||
descr = tables.Column("description", label=ugettext_lazy("Description"))
|
||||
|
||||
cols_order = ["selection", "name", "version", "descr"]
|
||||
cols_order = ["selection", "label", "version", "descr"]
|
||||
|
||||
class IdentitiesTable(tables.Table):
|
||||
idkey = "id"
|
||||
|
||||
+2
-2
@@ -494,9 +494,9 @@ def saveparameters(request):
|
||||
@login_required
|
||||
@user_passes_test(lambda u: u.is_superuser)
|
||||
def viewextensions(request, tplname='admin/extensions.html'):
|
||||
from modoboa.extensions import list_extensions
|
||||
from modoboa.extensions import exts_pool
|
||||
|
||||
exts = list_extensions()
|
||||
exts = exts_pool.list_all()
|
||||
for ext in exts:
|
||||
try:
|
||||
dbext = Extension.objects.get(name=ext["id"])
|
||||
|
||||
Reference in New Issue
Block a user