Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/cmd_set_quota.py
Show All 11 Lines | |||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU Library General Public License for more details. | # GNU Library 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, write to the Free Software | # along with this program; if not, write to the Free Software | ||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
# | # | ||||
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 _ | ||||
from pykolab import utils | from pykolab import utils | ||||
log = pykolab.getLogger('pykolab.cli') | log = pykolab.getLogger('pykolab.cli') | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
def __init__(): | def __init__(): | ||||
commands.register('set_quota', execute, description=description(), aliases=['sq']) | commands.register('set_quota', execute, description=description(), aliases=['sq']) | ||||
def description(): | def description(): | ||||
return """Configure quota for a folder.""" | return """Configure quota for a folder.""" | ||||
def execute(*args, **kw): | def execute(*args, **kw): | ||||
try: | try: | ||||
folder = conf.cli_args.pop(0) | folder = conf.cli_args.pop(0) | ||||
try: | try: | ||||
quota = conf.cli_args.pop(0) | quota = conf.cli_args.pop(0) | ||||
except IndexError, errmsg: | except IndexError: | ||||
quota = utils.ask_question(_("New quota")) | quota = utils.ask_question(_("New quota")) | ||||
except IndexError, errmsg: | except IndexError: | ||||
folder = utils.ask_question(_("Folder name")) | folder = utils.ask_question(_("Folder name")) | ||||
quota = utils.ask_question(_("New quota")) | quota = utils.ask_question(_("New quota")) | ||||
if len(folder.split('@')) > 1: | if len(folder.split('@')) > 1: | ||||
domain = folder.split('@')[1] | domain = folder.split('@')[1] | ||||
else: | else: | ||||
domain = conf.get('kolab', 'primary_domain') | domain = conf.get('kolab', 'primary_domain') | ||||
imap = IMAP() | imap = IMAP() | ||||
imap.connect(domain=domain) | imap.connect(domain=domain) | ||||
if not imap.has_folder(folder): | if not imap.has_folder(folder): | ||||
print >> sys.stderr, _("No such folder %r") % (folder) | print(_("No such folder %r") % (folder), file=sys.stderr) | ||||
sys.exit(1) | sys.exit(1) | ||||
for _folder in imap.lm(imap.folder_utf7(folder)): | for _folder in imap.lm(imap.folder_utf7(folder)): | ||||
imap.set_quota(_folder, quota) | imap.set_quota(_folder, quota) | ||||
print >> sys.stdout, "Quota for folder '%s' set to %d" % (_folder, int(quota)) | print("Quota for folder '%s' set to %d" % (_folder, int(quota)), file=sys.stdout) | ||||