summaryrefslogtreecommitdiffstats
path: root/pykolab/plugins/dynamicquota/__init__.py
blob: c9b9b7fe10d0e300ea09c98f8b79b137897ec050 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com)
#
# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import pykolab

from pykolab.translate import _

conf = pykolab.getConf()
log = pykolab.getLogger('pykolab.plugins.dynamicquota')

class KolabDynamicquota(object):
    """
        Example plugin making quota adjustments given arbitrary conditions.
    """

    def __init__(self):
        pass

    def add_options(self, *args,  **kw):
        pass

    def set_user_folder_quota(self, *args, **kw):
        """
            The arguments passed to the 'set_user_folder_quota' hook:

            - used (integer, in KB)
            - imap_quota (current imap quota obtained from IMAP, integer, in KB)
            - ldap_quota (current LDAP quota obtained from LDAP, integer, in KB)
            - default_quota (integer, in KB)

            Returns:

            - None - an error has occurred and this plugin doesn't care.
            - Negative 1 - remove quota.
            - Zero - Absolute 0.
            - Positive Integer - set new quota.
        """

        for keyword in [ 'used', 'imap_quota', 'ldap_quota', 'default_quota' ]:
            if not kw.has_key(keyword):
                log.warning(
                        _("No keyword %s passed to set_user_folder_quota") % (
                                keyword
                            )
                    )

                return
            else:
                try:
                    if not kw[keyword] == None:
                        kw[keyword] = (int)(kw[keyword])

                except:
                    log.error(_("Quota '%s' not an integer!") % (keyword))
                    return

        # Escape the user without quota
        if kw['ldap_quota'] == None:
            return kw['default_quota']
        elif kw['ldap_quota'] == -1:
            return -1
        elif kw['ldap_quota'] > 0:
            return kw['ldap_quota']
        else:
            return kw['default_quota']