Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 50 additions & 27 deletions coco/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def _endpoint_params(self):

# If there were no parameters, make one out of the name
if len(param_decls) == 1:
param_decls.append("--" + name.lower().replace("_", "-"))
param_decls.append(
("-" if len(name) == 1 else "--")
+ name.lower().replace("_", "-")
)

# Add false-type params for bools
if is_flag:
Expand Down Expand Up @@ -293,11 +296,10 @@ def client_send_request(
path : str
Endpoint path.
type : str, optional
HTTP request type. If `data` is provided, the default is "POST",
otherwise it's "GET".
HTTP request type. Defaults to "GET".
data : Any
If `type` is not "GET", other keyword arguments to this function are
JSON-serialized and sent to the endpoint.
Other keyword arguments to this function are JSON-serialized and sent
to the endpoint.

Returns
-------
Expand All @@ -316,7 +318,7 @@ def client_send_request(

# Determine HTTP command
if type is None:
type_ = "post" if data else "get"
type_ = "get"
else:
type_ = type.lower()

Expand All @@ -329,15 +331,18 @@ def client_send_request(

client_options = ctx.obj["options"]

# Add report type
data["coco_report_type"] = client_options["report"]

# Short-circut for --show-call-only
if client_options["show_call"]:
result = {"endpoint": url, "method": type_.upper()}
if type_ != "get":
result["data"] = data
return True, result
return True, {"endpoint": url, "method": type_.upper(), "data": data}

silent = client_options["silent"]
refresh_time = client_options["refresh_time"]
if silent:
refresh_time = 0
else:
refresh_time = client_options["refresh_time"]

async def print_queue_size(metric_request_count):
try:
Expand Down Expand Up @@ -383,7 +388,7 @@ async def request_and_wait():
Done task for request result.
"""
main_request = asyncio.create_task(send_request())
if not silent:
if refresh_time > 0:
metric_request_count = 0
while True:
metric_request_count = metric_request_count + 1
Expand Down Expand Up @@ -866,16 +871,22 @@ def _bullet(formatter, text):
"--json/--yaml",
"json",
is_flag=True,
default=False,
help="Print style for output. The default is --yaml.",
default=None,
help="Print style for output. If one of these flags is used, --quiet is also "
"turned on, unless --interactive is explicitly used. The default is "
"equivalent to: --interactive --yaml.",
)
@click.option(
"-q",
"--silent",
"--silent/--interactive",
"--quiet",
is_flag=True,
default=False,
help="Turn off all output except for the result.",
default=None,
help="Quiet mode ensures the output from coco is decodable as either YAML or "
"JSON by suppressing all output except the result. Quiet mode is "
"automatically turned on if one of the output style flags (--json or --yaml) "
"is used. Use --interactive along with those flags to select an output "
"style without turning on quiet mode.",
)
@click.option(
"-r",
Expand All @@ -901,7 +912,8 @@ def _bullet(formatter, text):
type=int,
default=2,
show_default=True,
help="Set refresh time for queue updates to SEC seconds.",
help="Set refresh time for queue updates to SEC seconds. A refresh time of "
"zero disables queue updates completley.",
)
@click.option(
"--help-config",
Expand All @@ -917,15 +929,26 @@ def entry(
):
"""This is the coco client."""

# legacy --style overrides --json or --yaml
if style:
if style == "json":
json = True
elif style == "yaml":
json = False
else:
# Otherwise, just ignore the option.
pass
# legacy --style overrides --json or --yaml, and doesn't turn on quiet mode
# like those flags do. A --style value which isn't "json" or "yaml" is silently
# ignored.
if style == "json":
json = True
if silent is None:
silent = False
elif style == "yaml":
json = False
if silent is None:
silent = False
elif json is not None:
# --json and --yaml turn on --silent, unless overriden
if silent is None:
silent = True
else:
# Default is --yaml --interactive
json = False
if silent is None:
silent = False

# Add all the global options to the click context.
obj["options"] = {
Expand Down
22 changes: 20 additions & 2 deletions coco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,22 @@ def __init__(
# Now that the state is loaded, validate all the endpoints defined by the config
endpoints = []
groups = self.config["groups"]

all_endpoints = {endpoint["name"] for endpoint in self.config["endpoints"]}

# These are all the local endpoints
all_local_endpoints = {
"blocklist",
"update-blocklist",
"saved-states",
"reset-state",
"save-state",
"load-state",
"get-coco-config",
"wait",
}
all_endpoints |= all_local_endpoints

for endpoint in self.config["endpoints"]:
endpoints.append(
validate_endpoint(endpoint, groups, all_endpoints, self.state)
Expand All @@ -134,7 +148,7 @@ def __init__(
self._config_slack_loggers()

self._load_endpoints()
self._local_endpoints()
self._local_endpoints(all_local_endpoints)
self._check_endpoint_links()

try:
Expand Down Expand Up @@ -440,7 +454,7 @@ def _load_endpoints(self):
)
self.forwarder.add_endpoint(name, self.endpoints[name])

def _local_endpoints(self):
def _local_endpoints(self, all_local_endpoints):
# Register any local endpoints

endpoints = {
Expand All @@ -454,6 +468,10 @@ def _local_endpoints(self):
"wait": ("POST", wait.process_post),
}

# Verify that everything's defined
if all_local_endpoints != set(endpoints):
raise RuntimeError("local endpoint mismatch")

for name, (type_, callable_) in endpoints.items():
self.endpoints[name] = LocalEndpoint(name, type_, callable_)
self.forwarder.add_endpoint(name, self.endpoints[name])
Expand Down
37 changes: 0 additions & 37 deletions old_tests/simulate-chime/Dockerfile

This file was deleted.

27 changes: 0 additions & 27 deletions old_tests/simulate-chime/base.yaml

This file was deleted.

43 changes: 0 additions & 43 deletions old_tests/simulate-chime/coco.conf

This file was deleted.

31 changes: 0 additions & 31 deletions old_tests/simulate-chime/comet/Dockerfile

This file was deleted.

Binary file removed old_tests/simulate-chime/data/init_gain.hdf5
Binary file not shown.
Binary file removed old_tests/simulate-chime/data/update_gain.hdf5
Binary file not shown.
60 changes: 0 additions & 60 deletions old_tests/simulate-chime/docker-compose.yaml

This file was deleted.

Loading