From daebe1981a0df80187660d5aeda497fe43bf3531 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 29 Aug 2019 23:08:07 +0200 Subject: missing files --- bin/taler-merchant-survey | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100755 bin/taler-merchant-survey (limited to 'bin') diff --git a/bin/taler-merchant-survey b/bin/taler-merchant-survey new file mode 100755 index 0000000..418cd78 --- /dev/null +++ b/bin/taler-merchant-survey @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 + +## +# This file is part of TALER +# (C) 2017 INRIA +# +# TALER is free software; you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public +# License as published by the Free Software Foundation; either +# version 3, or (at your option) any later version. +# +# TALER is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty +# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with TALER; see the file COPYING. If not, +# see +# +# @author Florian Dold +# @file Standalone script to launch the Survey site. + +import argparse +import sys +import os +import site +import logging +from talersurvey.talerconfig import TalerConfig + + +LOGGER = logging.getLogger(__name__) +# No perfect match to our logging format, but good enough ... +UWSGI_LOGFMT = "%(ltime) %(proto) %(method) %(uri) %(proto) => %(status)" + + +## +# This function interprets the 'serve-http' subcommand. +# The effect it to launch the Survey site as a HTTP service. +# +# @param args command line options. +def handle_serve_http(args): + port = args.port + if port is None: + port = TC["survey"]["http_port"].value_int(required=True) + spec = ":%d" % (port,) + os.execlp("uwsgi", "uwsgi", + "--master", + "--die-on-term", + "--log-format", UWSGI_LOGFMT, + "--http", spec, + "--module", "talersurvey") + + +## +# This function interprets the 'serve-uwsgi' subcommand. +# The effect is to launch the Survey UWSGI service. This +# type of service is usually used when the HTTP Survey interface +# is accessed via a reverse proxy (like Nginx, for example). +# +# @param command line options. +def handle_serve_uwsgi(args): + del args # pacify PEP checkers + serve_uwsgi = TC["survey"]["uwsgi_serve"].value_string(required=True).lower() + params = ["uwsgi", "uwsgi", + "--master", + "--die-on-term", + "--log-format", UWSGI_LOGFMT, + "--module", "talersurvey"] + if serve_uwsgi == "tcp": + port = TC["survey"]["uwsgi_port"].value_int(required=True) + spec = ":%d" % (port,) + params.extend(["--socket", spec]) + elif serve_uwsgi == "unix": + spec = TC["survey"]["uwsgi_unixpath"].value_filename(required=True) + mode = TC["survey"]["uwsgi_unixpath_mode"].value_filename(required=True) + params.extend(["--socket", spec]) + params.extend(["--chmod-socket="+mode]) + os.makedirs(os.path.dirname(spec), exist_ok=True) + logging.info("launching uwsgi with argv %s", params[1:]) + os.execlp(*params) + + +## @cond +PARSER = argparse.ArgumentParser() +PARSER.set_defaults(func=None) +PARSER.add_argument('--config', '-c', + help="configuration file to use", + metavar="CONFIG", type=str, + dest="config", default=None) +SUB = PARSER.add_subparsers() + +P = SUB.add_parser('serve-http', help="Serve over HTTP") +P.add_argument("--port", "-p", dest="port", type=int, default=None, metavar="PORT") +P.set_defaults(func=handle_serve_http) + +P = SUB.add_parser('serve-uwsgi', help="Serve over UWSGI") +P.set_defaults(func=handle_serve_uwsgi) + +ARGS = PARSER.parse_args() +## @endcond + +if getattr(ARGS, 'func', None) is None: + PARSER.print_help() + sys.exit(1) + +if ARGS.config is not None: + os.environ["TALER_CONFIG_FILE"] = ARGS.config +TC = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE")) + +ARGS.func(ARGS) -- cgit v1.2.3 From 141e949fa9f09e5f54acdfa90f609895236a8ac0 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 29 Aug 2019 23:08:26 +0200 Subject: make pretty --- bin/taler-merchant-survey | 48 +++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'bin') diff --git a/bin/taler-merchant-survey b/bin/taler-merchant-survey index 418cd78..2da6fde 100755 --- a/bin/taler-merchant-survey +++ b/bin/taler-merchant-survey @@ -28,7 +28,6 @@ import site import logging from talersurvey.talerconfig import TalerConfig - LOGGER = logging.getLogger(__name__) # No perfect match to our logging format, but good enough ... UWSGI_LOGFMT = "%(ltime) %(proto) %(method) %(uri) %(proto) => %(status)" @@ -43,13 +42,11 @@ def handle_serve_http(args): port = args.port if port is None: port = TC["survey"]["http_port"].value_int(required=True) - spec = ":%d" % (port,) - os.execlp("uwsgi", "uwsgi", - "--master", - "--die-on-term", - "--log-format", UWSGI_LOGFMT, - "--http", spec, - "--module", "talersurvey") + spec = ":%d" % (port, ) + os.execlp( + "uwsgi", "uwsgi", "--master", "--die-on-term", "--log-format", + UWSGI_LOGFMT, "--http", spec, "--module", "talersurvey" + ) ## @@ -60,22 +57,22 @@ def handle_serve_http(args): # # @param command line options. def handle_serve_uwsgi(args): - del args # pacify PEP checkers - serve_uwsgi = TC["survey"]["uwsgi_serve"].value_string(required=True).lower() - params = ["uwsgi", "uwsgi", - "--master", - "--die-on-term", - "--log-format", UWSGI_LOGFMT, - "--module", "talersurvey"] + del args # pacify PEP checkers + serve_uwsgi = TC["survey"]["uwsgi_serve"].value_string(required=True + ).lower() + params = [ + "uwsgi", "uwsgi", "--master", "--die-on-term", "--log-format", + UWSGI_LOGFMT, "--module", "talersurvey" + ] if serve_uwsgi == "tcp": port = TC["survey"]["uwsgi_port"].value_int(required=True) - spec = ":%d" % (port,) + spec = ":%d" % (port, ) params.extend(["--socket", spec]) elif serve_uwsgi == "unix": spec = TC["survey"]["uwsgi_unixpath"].value_filename(required=True) mode = TC["survey"]["uwsgi_unixpath_mode"].value_filename(required=True) params.extend(["--socket", spec]) - params.extend(["--chmod-socket="+mode]) + params.extend(["--chmod-socket=" + mode]) os.makedirs(os.path.dirname(spec), exist_ok=True) logging.info("launching uwsgi with argv %s", params[1:]) os.execlp(*params) @@ -84,14 +81,21 @@ def handle_serve_uwsgi(args): ## @cond PARSER = argparse.ArgumentParser() PARSER.set_defaults(func=None) -PARSER.add_argument('--config', '-c', - help="configuration file to use", - metavar="CONFIG", type=str, - dest="config", default=None) +PARSER.add_argument( + '--config', + '-c', + help="configuration file to use", + metavar="CONFIG", + type=str, + dest="config", + default=None +) SUB = PARSER.add_subparsers() P = SUB.add_parser('serve-http', help="Serve over HTTP") -P.add_argument("--port", "-p", dest="port", type=int, default=None, metavar="PORT") +P.add_argument( + "--port", "-p", dest="port", type=int, default=None, metavar="PORT" +) P.set_defaults(func=handle_serve_http) P = SUB.add_parser('serve-uwsgi', help="Serve over UWSGI") -- cgit v1.2.3 From 498b14392f7f828af1a239d680da27b859f85033 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 31 Aug 2019 17:00:27 +0200 Subject: use correct WSGI module --- bin/taler-merchant-survey | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/taler-merchant-survey b/bin/taler-merchant-survey index 2da6fde..41e6637 100755 --- a/bin/taler-merchant-survey +++ b/bin/taler-merchant-survey @@ -45,7 +45,7 @@ def handle_serve_http(args): spec = ":%d" % (port, ) os.execlp( "uwsgi", "uwsgi", "--master", "--die-on-term", "--log-format", - UWSGI_LOGFMT, "--http", spec, "--module", "talersurvey" + UWSGI_LOGFMT, "--http", spec, "--module", "talersurvey.survey:app" ) @@ -62,7 +62,7 @@ def handle_serve_uwsgi(args): ).lower() params = [ "uwsgi", "uwsgi", "--master", "--die-on-term", "--log-format", - UWSGI_LOGFMT, "--module", "talersurvey" + UWSGI_LOGFMT, "--module", "talersurvey.survey:app" ] if serve_uwsgi == "tcp": port = TC["survey"]["uwsgi_port"].value_int(required=True) -- cgit v1.2.3