|
@@ -332,47 +332,70 @@ def set_admin_password(context, admin_password): |
|
|
finally: |
|
|
finally: |
|
|
frappe.destroy() |
|
|
frappe.destroy() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command('set-limit') |
|
|
@click.command('set-limit') |
|
|
@click.option('--site', help='site name') |
|
|
@click.option('--site', help='site name') |
|
|
@click.argument('limit', type=click.Choice(['emails', 'space', 'users', 'expiry', |
|
|
|
|
|
'support_email', 'support_chat', 'upgrade_link'])) |
|
|
|
|
|
|
|
|
@click.argument('limit') |
|
|
@click.argument('value') |
|
|
@click.argument('value') |
|
|
@pass_context |
|
|
@pass_context |
|
|
def set_limit(context, site, limit, value): |
|
|
def set_limit(context, site, limit, value): |
|
|
"""Sets user / space / email limit for a site""" |
|
|
"""Sets user / space / email limit for a site""" |
|
|
|
|
|
_set_limits(context, site, ((limit, value),)) |
|
|
|
|
|
|
|
|
|
|
|
@click.command('set-limits') |
|
|
|
|
|
@click.option('--site', help='site name') |
|
|
|
|
|
@click.option('--limit', 'limits', type=(unicode, unicode), multiple=True) |
|
|
|
|
|
@pass_context |
|
|
|
|
|
def set_limits(context, site, limits): |
|
|
|
|
|
_set_limits(context, site, limits) |
|
|
|
|
|
|
|
|
|
|
|
def _set_limits(context, site, limits): |
|
|
import datetime |
|
|
import datetime |
|
|
|
|
|
|
|
|
|
|
|
if not limits: |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
if not site: |
|
|
if not site: |
|
|
site = get_site(context) |
|
|
site = get_site(context) |
|
|
|
|
|
|
|
|
with frappe.init_site(site): |
|
|
with frappe.init_site(site): |
|
|
if limit=='expiry': |
|
|
|
|
|
try: |
|
|
|
|
|
datetime.datetime.strptime(value, '%Y-%m-%d') |
|
|
|
|
|
except ValueError: |
|
|
|
|
|
raise ValueError("Incorrect data format, should be YYYY-MM-DD") |
|
|
|
|
|
|
|
|
new_limits = {} |
|
|
|
|
|
for limit, value in limits: |
|
|
|
|
|
if limit not in ('emails', 'space', 'users', 'expiry', |
|
|
|
|
|
'support_email', 'support_chat', 'upgrade_link'): |
|
|
|
|
|
frappe.throw('Invalid limit {0}'.format(limit)) |
|
|
|
|
|
|
|
|
|
|
|
if limit=='expiry': |
|
|
|
|
|
try: |
|
|
|
|
|
datetime.datetime.strptime(value, '%Y-%m-%d') |
|
|
|
|
|
except ValueError: |
|
|
|
|
|
raise ValueError("Incorrect data format, should be YYYY-MM-DD") |
|
|
|
|
|
|
|
|
elif limit=='space': |
|
|
|
|
|
value = float(value) |
|
|
|
|
|
|
|
|
elif limit=='space': |
|
|
|
|
|
value = float(value) |
|
|
|
|
|
|
|
|
elif limit in ('users', 'emails'): |
|
|
|
|
|
value = int(value) |
|
|
|
|
|
|
|
|
elif limit in ('users', 'emails'): |
|
|
|
|
|
value = int(value) |
|
|
|
|
|
|
|
|
update_limits({ limit : value }) |
|
|
|
|
|
|
|
|
new_limits[limit] = value |
|
|
|
|
|
|
|
|
@click.command('clear-limit') |
|
|
|
|
|
|
|
|
update_limits(new_limits) |
|
|
|
|
|
|
|
|
|
|
|
@click.command('clear-limits') |
|
|
@click.option('--site', help='site name') |
|
|
@click.option('--site', help='site name') |
|
|
@click.argument('limit', type=click.Choice(['emails', 'space', 'users', 'expiry', |
|
|
|
|
|
|
|
|
@click.argument('limits', nargs=-1, type=click.Choice(['emails', 'space', 'users', 'expiry', |
|
|
'support_email', 'support_chat', 'upgrade_link'])) |
|
|
'support_email', 'support_chat', 'upgrade_link'])) |
|
|
@pass_context |
|
|
@pass_context |
|
|
def clear_limit(context, site, limit): |
|
|
|
|
|
|
|
|
def clear_limits(context, site, limits): |
|
|
"""Clears given limit from the site config, and removes limit from site config if its empty""" |
|
|
"""Clears given limit from the site config, and removes limit from site config if its empty""" |
|
|
from frappe.limits import clear_limit as _clear_limit |
|
|
from frappe.limits import clear_limit as _clear_limit |
|
|
|
|
|
if not limits: |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
if not site: |
|
|
if not site: |
|
|
site = get_site(context) |
|
|
site = get_site(context) |
|
|
|
|
|
|
|
|
with frappe.init_site(site): |
|
|
with frappe.init_site(site): |
|
|
_clear_limit(limit) |
|
|
|
|
|
|
|
|
_clear_limit(limits) |
|
|
|
|
|
|
|
|
# Remove limits from the site_config, if it's empty |
|
|
# Remove limits from the site_config, if it's empty |
|
|
limits = get_limits() |
|
|
limits = get_limits() |
|
@@ -396,6 +419,7 @@ commands = [ |
|
|
set_admin_password, |
|
|
set_admin_password, |
|
|
uninstall, |
|
|
uninstall, |
|
|
set_limit, |
|
|
set_limit, |
|
|
clear_limit, |
|
|
|
|
|
|
|
|
set_limits, |
|
|
|
|
|
clear_limits, |
|
|
_use, |
|
|
_use, |
|
|
] |
|
|
] |