From d54238ed5b32ce10ea9e42ef4d8bc3feba6925b7 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Mon, 20 Nov 2017 12:31:59 +0100 Subject: Adding Makefile/setup.py/taler-merchant-survey. --- Makefile.in | 53 +++++++++++++++++++++++++++++++ setup.py | 27 ++++++++++++++++ taler-merchant-survey.in | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 Makefile.in create mode 100755 setup.py create mode 100644 taler-merchant-survey.in diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..eb34733 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,53 @@ +INSTALL = install +INSTALL_PROGRAM = $(INSTALL) +INSTALL_DATA = $(INSTALL) -m 644 +prefix = @prefix@ +srcdir = @srcdir@ + +script_templates = taler-merchant-survey frontend-survey.wsgi +templates = Makefile $(script_templates) + +edit = sed -e 's|@prefix[@]|$(prefix)|g' + +.PHONY: all +all: $(templates) + cd talersurvey/survey/static/web-common && make && cd - + +Makefile: Makefile.in + ./config.status $@ + +$(script_templates): %: Makefile %.in + rm -f $@ $@.tmp + $(edit) '$(srcdir)/$@.in' >$@.tmp + mv $@.tmp $@ + + +.PHONY: install-data +install-data: $(templates) + @$(INSTALL_DATA) -Dt $(prefix)/share/taler/ frontend-survey.wsgi + +# @test -n "$$(ls -A talerbank/app/static/web-common/)" || \ +# (echo "please check out git submodules"; exit 1) + + + +# link package under prefix to source tree +.PHONY: devinstall +devinstall: $(templates) install-data + @pip3 install -e . --install-option="--prefix=@prefix@" + + +# install into prefix +.PHONY: install +install: $(templates) install-data + @pip3 install . --install-option="--prefix=@prefix@" + @# force update when sources changed + @pip3 install . --install-option="--prefix=@prefix@" --upgrade --no-deps + cd talersurvey/survey/static/web-common && make install && cd - + +# run testcases +.PHONY: check +check: + @export TALER_CONFIG_FILE=./talersurvey/tests.conf; \ + export PYTHONPATH=@prefix@/lib/python3.5/site-packages; \ + python3 ./talersurvey/tests.py diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..6e92670 --- /dev/null +++ b/setup.py @@ -0,0 +1,27 @@ +from setuptools import setup, find_packages + +setup(name='talersurvey', + version='0.0', + description='Example survey site for GNU Taler', + url='git://taler.net/survey', + author='Marcello Stanisci', + author_email='stanisci.m@gmail.com', + license='GPL', + packages=find_packages(), + install_requires=["Flask>=0.10"], + package_data={ + '':[ + "survey/templates/*.html", + "survey/static/*.svg", + "survey/static/*.css", + "survey/static/*.js", + "survey/static/*.js.tar.gz", + "survey/static/web-common/*.png", + "survey/static/web-common/*.css", + "survey/static/web-common/*.js", + "survey/static/web-common/*.js.tar.gz", + "survey/static/web-common/*.html", + ] + }, + scripts=['taler-merchant-survey'], + zip_safe=False) diff --git a/taler-merchant-survey.in b/taler-merchant-survey.in new file mode 100644 index 0000000..11135cd --- /dev/null +++ b/taler-merchant-survey.in @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 + +""" +Stand-alone script to manage the GNU Taler +survey frontend. +""" + +import argparse +import sys +import os +import site + + +os.environ.setdefault("TALER_PREFIX", "@prefix@") +site.addsitedir("%s/lib/python%d.%d/site-packages" % ( + "@prefix@", + sys.version_info.major, + sys.version_info.minor)) + +from talersurvey.talerconfig import TalerConfig +import logging +logger = logging.getLogger(__name__) + +# No perfect match to our logging format, but good enough ... +uwsgi_logfmt = "%(ltime) %(proto) %(method) %(uri) %(proto) => %(status)" + +def handle_serve_http(args): + tc = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE")) + 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, + "--wsgi-file", "@prefix@/share/taler/frontend-survey.wsgi") + +def handle_serve_uwsgi(args): + tc = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE")) + serve_uwsgi = tc["survey"]["uwsgi_serve"].value_string(required=True).lower() + params = ["uwsgi", "uwsgi", + "--master", + "--die-on-term", + "--log-format", uwsgi_logfmt, + "--wsgi-file", "@prefix@/share/taler/frontend-survey.wsgi"] + 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) + + + +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() +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 + +args.func(args) -- cgit v1.2.3