Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/cmd_list_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.imap import IMAP | from pykolab.imap import IMAP | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
Show All 34 Lines | else: | ||||
imap.connect() | imap.connect() | ||||
folders = [] | folders = [] | ||||
quota_folders = imap.list_folders(quota_folder) | quota_folders = imap.list_folders(quota_folder) | ||||
for quota_folder in quota_folders: | for quota_folder in quota_folders: | ||||
try: | try: | ||||
(used, quota) = imap.get_quota(quota_folder) | (used, quota) = imap.get_quota(quota_folder) | ||||
print "Folder: %s" % (quota_folder) | print("Folder: %s" % (quota_folder)) | ||||
if not used == None and not quota == None: | if not used == None and not quota == None: | ||||
if quota == 0: | if quota == 0: | ||||
print >> sys.stderr, _("The quota for folder %s is set to literally allow 0KB of storage.") % (quota_folder) | print(_("The quota for folder %s is set to literally allow 0KB of storage.") % (quota_folder), file=sys.stderr) | ||||
print "%d (Used: %d, Percentage: %s)" % (quota, used, u'\u221E') | print("%d (Used: %d, Percentage: %s)" % (quota, used, u'\u221E')) | ||||
else: | else: | ||||
percentage = round(((float)(used)/(float)(quota)) * 100.0, 1) | percentage = round(((float)(used)/(float)(quota)) * 100.0, 1) | ||||
print "%d (Used: %d, Percentage: %d)" % (quota, used, percentage) | print("%d (Used: %d, Percentage: %d)" % (quota, used, percentage)) | ||||
else: | else: | ||||
if used == None: | if used == None: | ||||
print "%d (Used: %d, Percentage: %d)" % (quota, 0, 0) | print("%d (Used: %d, Percentage: %d)" % (quota, 0, 0)) | ||||
else: | else: | ||||
print "No quota" | print("No quota") | ||||
except: | except: | ||||
try: | try: | ||||
(quota_root, used, quota) = imap.get_quota_root(quota_folder) | (quota_root, used, quota) = imap.get_quota_root(quota_folder) | ||||
print "Folder: %s" % (quota_folder) | print("Folder: %s" % (quota_folder)) | ||||
if not quota_root == None and not used == None and not quota == None: | if not quota_root == None and not used == None and not quota == None: | ||||
if quota == 0: | if quota == 0: | ||||
print >> sys.stderr, _("The quota for folder %s is set to literally allow 0KB of storage.") % (quota_folder) | print(_("The quota for folder %s is set to literally allow 0KB of storage.") % (quota_folder), file=sys.stderr) | ||||
print "%d (Used: %d, Percentage: %d)" % (quota, used, u'\u221E') | print("%d (Used: %d, Percentage: %d)" % (quota, used, u'\u221E')) | ||||
else: | else: | ||||
percentage = round(((float)(used)/(float)(quota)) * 100.0, 1) | percentage = round(((float)(used)/(float)(quota)) * 100.0, 1) | ||||
print "%d (Root: %s, Used: %d, Percentage: %d)" % (quota, quota_root, used, percentage) | print("%d (Root: %s, Used: %d, Percentage: %d)" % (quota, quota_root, used, percentage)) | ||||
else: | else: | ||||
if used == None and not quota_root == None: | if used == None and not quota_root == None: | ||||
print "%d (Root: %s, Used: %d, Percentage: %d)" % (quota, quota_root, 0, 0) | print("%d (Root: %s, Used: %d, Percentage: %d)" % (quota, quota_root, 0, 0)) | ||||
else: | else: | ||||
print "No quota" | print("No quota") | ||||
except: | except: | ||||
print "Folder: %s" % (quota_folder) | print("Folder: %s" % (quota_folder)) | ||||
print "No quota root" | print("No quota root") | ||||