author | Pascal Volk <neverseen@users.sourceforge.net> |
Sun, 16 Oct 2011 18:12:55 +0000 | |
branch | v0.6.x |
changeset 430 | c11edcfc6e5f |
parent 407 | 3162ff959375 |
child 450 | fd4aa073015f |
permissions | -rw-r--r-- |
385
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
1 |
# -*- coding: UTF-8 -*- |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
2 |
# Copyright (c) 2011, Pascal Volk |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
3 |
# See COPYING for distribution information. |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
4 |
""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
5 |
VirtualMailManager.quotalimit |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
6 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
7 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
8 |
Virtual Mail Manager's QuotaLimit class to manage quota limits |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
9 |
for domains and accounts. |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
10 |
""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
11 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
12 |
from VirtualMailManager.constants import VMM_ERROR |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
13 |
from VirtualMailManager.errors import VMMError |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
14 |
from VirtualMailManager.pycompat import all |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
15 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
16 |
_ = lambda msg: msg |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
17 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
18 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
19 |
class QuotaLimit(object): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
20 |
"""Class to handle quota limit specific data.""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
21 |
__slots__ = ('_dbh', '_qid', '_bytes', '_messages') |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
22 |
_kwargs = ('qid', 'bytes', 'messages') |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
23 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
24 |
def __init__(self, dbh, **kwargs): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
25 |
"""Create a new QuotaLimit instance. |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
26 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
27 |
Either the `qid` keyword or the `bytes` and `messages` keywords |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
28 |
must be specified. |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
29 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
30 |
Arguments: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
31 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
32 |
`dbh` : pyPgSQL.PgSQL.Connection || psycopg2._psycopg.connection |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
33 |
A database connection for the database access. |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
34 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
35 |
Keyword arguments: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
36 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
37 |
`qid` : int |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
38 |
The id of a quota limit |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
39 |
`bytes` : long |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
40 |
The quota limit in bytes. |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
41 |
`messages` : int |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
42 |
The quota limit in number of messages |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
43 |
""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
44 |
self._dbh = dbh |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
45 |
self._qid = 0 |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
46 |
self._bytes = 0 |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
47 |
self._messages = 0 |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
48 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
49 |
for key in kwargs.iterkeys(): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
50 |
if key not in self.__class__._kwargs: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
51 |
raise ValueError('unrecognized keyword: %r' % key) |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
52 |
qid = kwargs.get('qid') |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
if qid is not None: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
54 |
assert isinstance(qid, (int, long)) |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
55 |
self._load_by_qid(qid) |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
56 |
else: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
57 |
bytes_, msgs = kwargs.get('bytes'), kwargs.get('messages') |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
58 |
assert all(isinstance(i, (int, long)) for i in (bytes_, msgs)) |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
59 |
if bytes_ < 0: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
60 |
self._bytes = -bytes_ |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
61 |
else: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
62 |
self._bytes = bytes_ |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
63 |
if msgs < 0: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
64 |
self._messages = -msgs |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
65 |
else: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
66 |
self._messages = msgs |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
67 |
self._load_by_limit() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
68 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
69 |
@property |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
70 |
def bytes(self): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
71 |
"""Quota limit in bytes.""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
72 |
return self._bytes |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
73 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
74 |
@property |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
75 |
def messages(self): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
76 |
"""Quota limit in number of messages.""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
77 |
return self._messages |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
78 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
79 |
@property |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
80 |
def qid(self): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
81 |
"""The quota limit's unique ID.""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
82 |
return self._qid |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
83 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
84 |
def __eq__(self, other): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
85 |
if isinstance(other, self.__class__): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
86 |
return self._qid == other._qid |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
87 |
return NotImplemented |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
88 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
89 |
def __ne__(self, other): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
90 |
if isinstance(other, self.__class__): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
91 |
return self._qid != other._qid |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
92 |
return NotImplemented |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
93 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
94 |
def _load_by_limit(self): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
95 |
"""Load the quota limit by limit values from the database.""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
96 |
dbc = self._dbh.cursor() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
97 |
dbc.execute('SELECT qid FROM quotalimit WHERE bytes = %s AND ' |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
98 |
'messages = %s', (self._bytes, self._messages)) |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
99 |
res = dbc.fetchone() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
100 |
dbc.close() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
101 |
if res: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
102 |
self._qid = res[0] |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
103 |
else: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
104 |
self._save() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
105 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
106 |
def _load_by_qid(self, qid): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
107 |
"""Load the quota limit by its unique ID from the database.""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
108 |
dbc = self._dbh.cursor() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
109 |
dbc.execute('SELECT bytes, messages FROM quotalimit WHERE qid = %s', |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
110 |
(qid,)) |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
111 |
res = dbc.fetchone() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
112 |
dbc.close() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
113 |
if not res: |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
114 |
raise VMMError(_(u'Unknown quota limit id specified.'), VMM_ERROR) |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
115 |
self._qid = qid |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
116 |
self._bytes, self._messages = res |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
117 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
118 |
def _save(self): |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
119 |
"""Store a new quota limit in the database.""" |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
120 |
dbc = self._dbh.cursor() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
121 |
dbc.execute("SELECT nextval('quotalimit_id')") |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
122 |
self._qid = dbc.fetchone()[0] |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
123 |
dbc.execute('INSERT INTO quotalimit (qid, bytes, messages) VALUES ' |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
124 |
'(%s, %s, %s)', (self._qid, self._bytes, self._messages)) |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
125 |
self._dbh.commit() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
126 |
dbc.close() |
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
127 |
|
0cae9989395b
VMM/quotalimit: Added new module quotalimit to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
128 |
del _ |