parent
d8e5b1f1d4
commit
7b289cda56
@ -0,0 +1,48 @@ |
||||
import click |
||||
from zope import component |
||||
from zope.interface.interfaces import IRegistered, IUtilityRegistration |
||||
import zope.component.event |
||||
|
||||
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 |
||||
|
||||
|
||||
@positions.command(short_help='Get current positions') |
||||
def get(): |
||||
resp = http_get('/api/positions') |
||||
result = handle_sync_response(resp) |
||||
print_colon_kv(result.items()) |
||||
|
||||
|
||||
@positions.command(short_help='Update positions') |
||||
def update(**kwargs): |
||||
click.echo('The positions will be updated:') |
||||
print_colon_kv(kwargs.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()}) |
||||
handle_stream_response(resp, UpdateMemberPositionsTransaction.operations) |
||||
|
||||
|
||||
# Provides dynamic parameter for update command using config file |
||||
@component.provideHandler |
||||
@component.adapter(IRegistered) |
||||
def _handler(event): |
||||
global update |
||||
|
||||
if not (IUtilityRegistration.providedBy(event.object) and IConfig.providedBy(event.object.component)): |
||||
return |
||||
|
||||
cfg = event.object.component |
||||
avail = cfg.get('positions_available') |
||||
required = cfg.get('positions_required') |
||||
|
||||
for pos in avail: |
||||
update = click.option(f'--{pos}', metavar='USER', required=(pos in required))(update) |
Loading…
Reference in new issue