mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
@@ -0,0 +1,18 @@
|
||||
"""
|
||||
Extra classes for management commands.
|
||||
"""
|
||||
|
||||
from django.db import connection
|
||||
|
||||
|
||||
class CloseConnectionMixin(object):
|
||||
|
||||
"""
|
||||
A simple mixin used to close all database connections after
|
||||
command execution.
|
||||
"""
|
||||
|
||||
def execute(self, *args, **options):
|
||||
"""Execute will call handle so we can close the connection here."""
|
||||
super(CloseConnectionMixin, self).execute(*args, **options)
|
||||
connection.close()
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import datetime
|
||||
from optparse import make_option
|
||||
|
||||
from django.db import connection
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
|
||||
@@ -11,8 +10,10 @@ from modoboa.core import load_core_settings
|
||||
from modoboa.core.models import Log
|
||||
from modoboa.lib import parameters
|
||||
|
||||
from . import CloseConnectionMixin
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
args = ''
|
||||
help = 'Log table cleanup'
|
||||
|
||||
@@ -45,5 +46,4 @@ class Command(BaseCommand):
|
||||
self.__vprint("Deleting logs older than %d days..." % log_maximum_age)
|
||||
limit = timezone.now() - datetime.timedelta(log_maximum_age)
|
||||
Log.objects.filter(date_created__lt=limit).delete()
|
||||
connection.close()
|
||||
self.__vprint("Done.")
|
||||
|
||||
@@ -6,12 +6,12 @@ from optparse import make_option
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import connection
|
||||
|
||||
from modoboa.core.models import Extension
|
||||
from . import CloseConnectionMixin
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
|
||||
"""Command definition."""
|
||||
|
||||
@@ -56,5 +56,3 @@ class Command(BaseCommand):
|
||||
if not fullname in settings.MODOBOA_APPS:
|
||||
continue
|
||||
self._change_extension_state(extname, options)
|
||||
|
||||
connection.close()
|
||||
|
||||
@@ -6,12 +6,13 @@ See `https://docs.djangoproject.com/en/dev/ref/contrib/sites/`_.
|
||||
"""
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import connection
|
||||
|
||||
from django.contrib.sites.models import Site
|
||||
|
||||
from . import CloseConnectionMixin
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
|
||||
"""Management command to set the default site."""
|
||||
|
||||
@@ -25,4 +26,3 @@ class Command(BaseCommand):
|
||||
site.domain = args[0]
|
||||
site.name = args[0]
|
||||
site.save()
|
||||
connection.close()
|
||||
|
||||
@@ -4,8 +4,8 @@ from optparse import make_option
|
||||
import os
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import connection
|
||||
|
||||
from modoboa.core.management.commands import CloseConnectionMixin
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.lib.sysutils import exec_cmd
|
||||
from modoboa.lib.exceptions import InternalError
|
||||
@@ -17,7 +17,7 @@ class OperationError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
help = 'Handles rename and delete operations on mailboxes'
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
@@ -76,7 +76,10 @@ class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
AdminConsole().load()
|
||||
if parameters.get_admin("HANDLE_MAILBOXES") == 'no':
|
||||
try:
|
||||
if parameters.get_admin("HANDLE_MAILBOXES") == 'no':
|
||||
return
|
||||
except parameters.NotDefined:
|
||||
return
|
||||
if not self.check_pidfile(options['pidfile']):
|
||||
return
|
||||
@@ -94,4 +97,3 @@ class Command(BaseCommand):
|
||||
self.logger.info('%s succeed', ope)
|
||||
ope.delete()
|
||||
os.unlink(options['pidfile'])
|
||||
connection.close()
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
# coding: utf-8
|
||||
from optparse import make_option
|
||||
|
||||
from django.db import connection
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from modoboa.core.management.commands import CloseConnectionMixin
|
||||
from modoboa.core.models import User
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.lib.emailutils import sendmail_simple
|
||||
@@ -20,7 +20,7 @@ from modoboa.extensions.amavis.models import (
|
||||
from modoboa.extensions.amavis.sql_connector import get_connector
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
help = 'Amavis notification tool'
|
||||
|
||||
sender = None
|
||||
@@ -94,4 +94,3 @@ class Command(BaseCommand):
|
||||
continue
|
||||
rcpt = su.mailbox_set.all()[0].full_address
|
||||
self.send_pr_notification(rcpt, reqs)
|
||||
connection.close()
|
||||
|
||||
@@ -3,16 +3,18 @@
|
||||
|
||||
import time
|
||||
from optparse import make_option
|
||||
from django.db import connection
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from modoboa.lib import parameters
|
||||
|
||||
from modoboa.core.management.commands import CloseConnectionMixin
|
||||
from modoboa.extensions.amavis import Amavis
|
||||
from modoboa.extensions.amavis.models import (
|
||||
Msgrcpt, Msgs, Maddr
|
||||
)
|
||||
from modoboa.lib import parameters
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
args = ''
|
||||
help = 'Amavis quarantine cleanup'
|
||||
|
||||
@@ -56,7 +58,8 @@ class Command(BaseCommand):
|
||||
if not msg.msgrcpt_set.exclude(rs__in=flags).count():
|
||||
msg.delete()
|
||||
|
||||
self.__vprint("Deleting messages older than %d days..." % max_messages_age)
|
||||
self.__vprint(
|
||||
"Deleting messages older than %d days..." % max_messages_age)
|
||||
limit = int(time.time()) - (max_messages_age * 24 * 3600)
|
||||
Msgs.objects.filter(time_num__lt=limit).delete()
|
||||
|
||||
@@ -64,6 +67,5 @@ class Command(BaseCommand):
|
||||
for maddr in Maddr.objects.all():
|
||||
if not maddr.msgs_set.count() and not maddr.msgrcpt_set.count():
|
||||
maddr.delete()
|
||||
connection.close()
|
||||
|
||||
self.__vprint("Done.")
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
import sys
|
||||
import datetime
|
||||
|
||||
from django.db import connection
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils import timezone
|
||||
|
||||
from modoboa.core.management.commands import CloseConnectionMixin
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.lib.emailutils import split_mailbox, sendmail_simple
|
||||
from modoboa.extensions.admin.models import Mailbox
|
||||
@@ -45,7 +45,7 @@ def send_autoreply(sender, mailbox, armessage):
|
||||
lastar.save()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
args = '<sender> <recipient ...>'
|
||||
help = 'Send autoreply emails'
|
||||
|
||||
@@ -67,4 +67,3 @@ class Command(BaseCommand):
|
||||
continue
|
||||
|
||||
send_autoreply(sender, mbox, armessage)
|
||||
connection.close()
|
||||
|
||||
@@ -4,6 +4,7 @@ from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from modoboa.core.management.commands import CloseConnectionMixin
|
||||
from modoboa.core.models import User
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.extensions.admin import Domain
|
||||
@@ -13,7 +14,7 @@ from modoboa.extensions.radicale.models import (
|
||||
)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
help = "Generate Radicale rights file"
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
|
||||
@@ -25,10 +25,10 @@ import rrdtool
|
||||
import string
|
||||
from optparse import make_option
|
||||
|
||||
from django.db import connection
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from modoboa.core.extensions import exts_pool
|
||||
from modoboa.core.management.commands import CloseConnectionMixin
|
||||
from modoboa.extensions.admin.models import Domain
|
||||
from modoboa.extensions.stats import Stats
|
||||
from modoboa.extensions.stats.lib import date_to_timestamp
|
||||
@@ -354,7 +354,7 @@ class LogParser(object):
|
||||
self.update_rrd(dom, t)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
help = 'Log file parser'
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
@@ -372,4 +372,3 @@ class Command(BaseCommand):
|
||||
options["logfile"] = parameters.get_admin("LOGFILE", app="stats")
|
||||
p = LogParser(options, parameters.get_admin("RRD_ROOTDIR", app="stats"))
|
||||
p.process()
|
||||
connection.close()
|
||||
|
||||
Reference in New Issue
Block a user