call update_commands from positions() group
This commit is contained in:
parent
36fd303433
commit
9f549ee58b
|
@ -24,12 +24,10 @@ def register_services():
|
||||||
else:
|
else:
|
||||||
config_file = os.environ.get('CEO_CONFIG', '/etc/csc/ceo.ini')
|
config_file = os.environ.get('CEO_CONFIG', '/etc/csc/ceo.ini')
|
||||||
cfg = Config(config_file)
|
cfg = Config(config_file)
|
||||||
component.provideUtility(cfg, IConfig)
|
|
||||||
baseComponent.registerUtility(cfg, IConfig)
|
baseComponent.registerUtility(cfg, IConfig)
|
||||||
|
|
||||||
# HTTPService
|
# HTTPService
|
||||||
http_client = HTTPClient()
|
http_client = HTTPClient()
|
||||||
component.provideUtility(http_client, IHTTPClient)
|
|
||||||
baseComponent.registerUtility(http_client, IHTTPClient)
|
baseComponent.registerUtility(http_client, IHTTPClient)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from zope import component
|
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 ceo_common.interfaces import IConfig
|
||||||
from ceod.transactions.members import UpdateMemberPositionsTransaction
|
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')
|
@click.group(short_help='List or change exec positions')
|
||||||
def positions():
|
def positions():
|
||||||
pass
|
update_commands()
|
||||||
|
|
||||||
|
|
||||||
@positions.command(short_help='Get current positions')
|
@positions.command(short_help='Get current positions')
|
||||||
|
@ -25,24 +21,21 @@ def get():
|
||||||
|
|
||||||
@positions.command(short_help='Update positions')
|
@positions.command(short_help='Update positions')
|
||||||
def set(**kwargs):
|
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:')
|
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)
|
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)
|
handle_stream_response(resp, UpdateMemberPositionsTransaction.operations)
|
||||||
|
|
||||||
|
|
||||||
# Provides dynamic parameter for update command using config file
|
# Provides dynamic parameters for `set' command using config file
|
||||||
@component.provideHandler
|
def update_commands():
|
||||||
@component.adapter(IRegistered)
|
|
||||||
def _handler(event):
|
|
||||||
global set
|
global set
|
||||||
|
|
||||||
if not (IUtilityRegistration.providedBy(event.object) and IConfig.providedBy(event.object.component)):
|
cfg = component.getUtility(IConfig)
|
||||||
return
|
|
||||||
|
|
||||||
cfg = event.object.component
|
|
||||||
avail = cfg.get('positions_available')
|
avail = cfg.get('positions_available')
|
||||||
required = cfg.get('positions_required')
|
required = cfg.get('positions_required')
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,8 @@ def space_colon_kv(pairs: List[Tuple[str, str]]) -> List[str]:
|
||||||
key1000: val3
|
key1000: val3
|
||||||
val4
|
val4
|
||||||
"""
|
"""
|
||||||
|
if not pairs:
|
||||||
|
return []
|
||||||
lines = []
|
lines = []
|
||||||
maxlen = max(len(key) for key, val in pairs)
|
maxlen = max(len(key) for key, val in pairs)
|
||||||
for key, val in pairs:
|
for key, val in pairs:
|
||||||
|
|
|
@ -23,7 +23,7 @@ def test_positions(cli_setup):
|
||||||
assert result.output == '''
|
assert result.output == '''
|
||||||
The positions will be updated:
|
The positions will be updated:
|
||||||
president: test_0
|
president: test_0
|
||||||
vice_president: test_1
|
vice-president: test_1
|
||||||
sysadmin: test_2
|
sysadmin: test_2
|
||||||
secretary: test_3
|
secretary: test_3
|
||||||
webmaster: test_4
|
webmaster: test_4
|
||||||
|
|
Loading…
Reference in New Issue