diff --git a/bin/geomag_webservice.py b/bin/geomag_webservice.py new file mode 100755 index 0000000000000000000000000000000000000000..43d75180bcdf93671f0fd24337cfc57048d08c74 --- /dev/null +++ b/bin/geomag_webservice.py @@ -0,0 +1,36 @@ +#! /usr/bin/env python + +from __future__ import absolute_import, print_function +from builtins import str as unicode + +import os +import sys +from wsgiref.simple_server import make_server +# ensure geomag is on the path before importing +try: + import geomagio # noqa (tells linter to ignore this line.) +except: + path = os.path + script_dir = path.dirname(path.abspath(__file__)) + sys.path.append(path.normpath(path.join(script_dir, '..'))) + import geomagio + + +if __name__ == '__main__': + # read configuration from environment + edge_host = os.getenv('EDGE_HOST', 'cwbpub.cr.usgs.gov') + edge_port = int(os.getenv('EDGE_PORT', '2060')) + factory_type = os.getenv('GEOMAG_FACTORY_TYPE', 'edge') + webservice_host = os.getenv('GEOMAG_WEBSERVICE_HOST', '') + webservice_port = int(os.getenv('GEOMAG_WEBSERVICE_PORT', '7981')) + + # configure factory + if factory_type == 'edge': + factory = geomagio.edge.EdgeFactory(host=edge_host, port=edge_port) + else: + raise "Unknown factory type '%s'" % factory_type + + print("Starting webservice on %s:%d" % (webservice_host, webservice_port)) + app = geomagio.WebService(factory) + httpd = make_server(webservice_host, webservice_port, app) + httpd.serve_forever() diff --git a/geomagio/WebService.py b/geomagio/WebService.py index 411ab6b80f9c2eac0f9188b453a94f9b1d66821c..cee204334a4e7da7139c5565ab3745dd285f394d 100644 --- a/geomagio/WebService.py +++ b/geomagio/WebService.py @@ -343,11 +343,3 @@ class WebServiceQuery(object): class WebServiceException(Exception): """Base class for exceptions thrown by web services.""" pass - - -if __name__ == '__main__': - from wsgiref.simple_server import make_server - - app = WebService(EdgeFactory()) - httpd = make_server('', 7981, app) - httpd.serve_forever()