From ace9155ae171447d27047c365b7169ef5a550f47 Mon Sep 17 00:00:00 2001 From: Sadie Bartholomew Date: Fri, 3 May 2019 16:48:49 +0100 Subject: [PATCH] Respond to new feedback --- lib/python/rosie/ws.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/python/rosie/ws.py b/lib/python/rosie/ws.py index 261fbc804b..e0f35491b5 100644 --- a/lib/python/rosie/ws.py +++ b/lib/python/rosie/ws.py @@ -97,33 +97,34 @@ def __init__(self, service_root_mode=False, *args, **kwargs): self.db_url_map = db_url_map # Specify the root URL for the handlers and template. + self.service_root = r"/" ROOT = "%s-%s" % (self.NAMESPACE, self.UTIL) - service_root = r"/?" if self.service_root_mode: - service_root += ROOT + r"/?" + self.service_root += ROOT + r"/" # Set-up the Tornado application request-handling structure. prefix_handlers = [] class_args = {"props": self.props} root_class_args = dict(class_args) # mutable so copy for safety root_class_args.update({"db_url_map": self.db_url_map}) - root_handler = (service_root, RosieDiscoServiceRoot, root_class_args) + root_handler = ( + self.service_root, RosieDiscoServiceRoot, root_class_args) for key, db_url in list(self.db_url_map.items()): prefix_class_args = dict(class_args) # mutable so copy for safety prefix_class_args.update({ "prefix": key, "db_url": db_url, - "service_root": service_root, + "service_root": self.service_root, }) - handler = (service_root + key + r"/?", RosieDiscoService, + handler = (self.service_root + key + r"/?", RosieDiscoService, prefix_class_args) - get_handler = (service_root + key + r"/get_(.+)", GetHandler, + get_handler = (self.service_root + key + r"/get_(.+)", GetHandler, prefix_class_args) - hello_handler = (service_root + key + r"/hello/?", HelloHandler, - prefix_class_args) - search_handler = (service_root + key + r"/search", SearchHandler, - prefix_class_args) - query_handler = (service_root + key + r"/query", QueryHandler, + hello_handler = (self.service_root + key + r"/hello/?", + HelloHandler, prefix_class_args) + search_handler = (self.service_root + key + r"/search", + SearchHandler, prefix_class_args) + query_handler = (self.service_root + key + r"/query", QueryHandler, prefix_class_args) prefix_handlers.extend( [handler, get_handler, hello_handler, search_handler, @@ -244,12 +245,12 @@ class GetHandler(RosieDiscoService): "optional_keys", # Return the names of the optional fields. ] - def get(self, get_arg): + def get(self, *args): """Return data for basic API points of query keys without values.""" format_arg = self.get_query_argument("format", default=None) - if get_arg and format_arg == "json": + if args[0] and format_arg == "json": for query in self.QUERY_KEYS: - if get_arg.startswith(query): + if args[0].startswith(query): # No need to catch AttributeError as all QUERY_KEYS valid. self.write(json.dumps(getattr(self.dao, "get_" + query)())) @@ -294,7 +295,7 @@ class QueryHandler(RosieDiscoService): """Serves a query of the database on the page of a given prefix.""" - def get(self): + def get(self, *args): """Search database for rows with data matching the query string.""" q_args = self.get_query_arguments("q") # empty list if none given all_revs = self.get_query_argument("all_revs", default=0) @@ -462,8 +463,15 @@ def main(): _log_app_base(*app_info, "tornado.application", ".error") tornado.log.gen_log.info("Started" + log_msg_end) - # Call print before IOLoop start() else it prints only on loop stop. + # Call to print before IOLoop start() else it prints only on loop stop. print("Started" + user_msg_end) + append_url_root = "" + if app.service_root_mode: + append_url_root = "%s-%s/" % (app.NAMESPACE, app.UTIL) + # Also print the URL for quick access; 'http://' added so that the URL + # is hyperlinked in the terminal stdout, but it is not required. + print("Application root page available at http://%s:%s/%s" % ( + app.props["host_name"], port, append_url_root)) IOLoop.current().start() elif instruction == "stop" and (