Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/cmd_check_quota.py
Show All 11 Lines | |||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | # GNU General Public License for more details. | ||||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | # | ||||
from __future__ import print_function | |||||
import sys | import sys | ||||
import commands | import commands | ||||
import pykolab | import pykolab | ||||
from pykolab.auth import Auth | from pykolab.auth import Auth | ||||
from pykolab.imap import IMAP | from pykolab.imap import IMAP | ||||
Show All 37 Lines | def execute(*args, **kw): | ||||
imap.connect(server=conf.connect_server) | imap.connect(server=conf.connect_server) | ||||
auth = Auth() | auth = Auth() | ||||
auth.connect() | auth.connect() | ||||
domains = auth.list_domains() | domains = auth.list_domains() | ||||
folders = [] | folders = [] | ||||
for domain in domains.keys(): | for domain in domains: | ||||
folders = imap.lm("user/%%@%s" % (domain)) | folders = imap.lm("user/%%@%s" % (domain)) | ||||
domain_auth = Auth(domain=domain) | domain_auth = Auth(domain=domain) | ||||
domain_auth.connect(domain=domain) | domain_auth.connect(domain=domain) | ||||
for folder in folders: | for folder in folders: | ||||
login = folder.split('/')[1] | login = folder.split('/')[1] | ||||
user_dn = domain_auth.find_recipient(login) | user_dn = domain_auth.find_recipient(login) | ||||
if user_dn == None: | if user_dn == None: | ||||
print >> sys.stderr, _("No such user %s") % (login) | print(_("No such user %s") % (login), file=sys.stderr) | ||||
continue | continue | ||||
if len(login.split('@')) > 1: | if len(login.split('@')) > 1: | ||||
domain = login.split('@')[1] | domain = login.split('@')[1] | ||||
else: | else: | ||||
domain = conf.get('kolab', 'primary_domain') | domain = conf.get('kolab', 'primary_domain') | ||||
try: | try: | ||||
user_quota = auth.get_entry_attribute(domain, user_dn, 'mailquota') | user_quota = auth.get_entry_attribute(domain, user_dn, 'mailquota') | ||||
except: | except: | ||||
user_quota = None | user_quota = None | ||||
if user_quota == None: | if user_quota == None: | ||||
print >> sys.stderr, _("No quota for user %s") % (login) | print(_("No quota for user %s") % (login), file=sys.stderr) | ||||
continue | continue | ||||
try: | try: | ||||
(used, quota) = imap.get_quota(folder) | (used, quota) = imap.get_quota(folder) | ||||
if not (int)(quota) == (int)(user_quota): | if not (int)(quota) == (int)(user_quota): | ||||
print >> sys.stderr, _("user quota does not match for %s (IMAP: %d, LDAP: %d)") % (login, (int)(quota), (int)(user_quota)) | print(_("user quota does not match for %s (IMAP: %d, LDAP: %d)") % (login, (int)(quota), (int)(user_quota)), file=sys.stderr) | ||||
except: | except: | ||||
pass | pass |