|
|
|
@ -1,19 +1,15 @@ |
|
|
|
|
import click |
|
|
|
|
|
|
|
|
|
from zope import component |
|
|
|
|
from zope.interface.interfaces import IRegistered, IUtilityRegistration |
|
|
|
|
import zope.component.event # noqa: F401 |
|
|
|
|
|
|
|
|
|
from ..utils import http_get, http_post |
|
|
|
|
from .utils import handle_sync_response, handle_stream_response, print_colon_kv |
|
|
|
|
from ceo_common.interfaces import IConfig |
|
|
|
|
from ceod.transactions.members import UpdateMemberPositionsTransaction |
|
|
|
|
|
|
|
|
|
from .utils import handle_sync_response, handle_stream_response, print_colon_kv |
|
|
|
|
from ..utils import http_get, http_post |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.group(short_help='List or change exec positions') |
|
|
|
|
def positions(): |
|
|
|
|
pass |
|
|
|
|
update_commands() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@positions.command(short_help='Get current positions') |
|
|
|
@ -25,24 +21,21 @@ def get(): |
|
|
|
|
|
|
|
|
|
@positions.command(short_help='Update positions') |
|
|
|
|
def set(**kwargs): |
|
|
|
|
body = {k.replace('_', '-'): v for k, v in kwargs.items()} |
|
|
|
|
print_body = {k: v or '' for k, v in body.items()} |
|
|
|
|
click.echo('The positions will be updated:') |
|
|
|
|
print_colon_kv(kwargs.items()) |
|
|
|
|
print_colon_kv(print_body.items()) |
|
|
|
|
click.confirm('Do you want to continue?', abort=True) |
|
|
|
|
|
|
|
|
|
resp = http_post('/api/positions', json={k.replace('_', '-'): v for k, v in kwargs.items()}) |
|
|
|
|
resp = http_post('/api/positions', json=body) |
|
|
|
|
handle_stream_response(resp, UpdateMemberPositionsTransaction.operations) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Provides dynamic parameter for update command using config file |
|
|
|
|
@component.provideHandler |
|
|
|
|
@component.adapter(IRegistered) |
|
|
|
|
def _handler(event): |
|
|
|
|
# Provides dynamic parameters for `set' command using config file |
|
|
|
|
def update_commands(): |
|
|
|
|
global set |
|
|
|
|
|
|
|
|
|
if not (IUtilityRegistration.providedBy(event.object) and IConfig.providedBy(event.object.component)): |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
cfg = event.object.component |
|
|
|
|
cfg = component.getUtility(IConfig) |
|
|
|
|
avail = cfg.get('positions_available') |
|
|
|
|
required = cfg.get('positions_required') |
|
|
|
|
|
|
|
|
|