From 2019b398f164aa3f7edb8af439c92f1a32d2e920 Mon Sep 17 00:00:00 2001 From: JocelynDelalande Date: Sun, 7 Jan 2018 00:27:42 +0100 Subject: manage commands testing (#313) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Rename manage.ConfigTemplate → manage.GenerateConfig To be consistent with the CLI name: `generate-config`. * Add tests for manage.py commands * Run tests from pip-installed package To be able to detect packaging-related issues on test runs. refs #305 --- ihatemoney/manage.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ihatemoney/manage.py') diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py index 797e6c4..315cfac 100755 --- a/ihatemoney/manage.py +++ b/ihatemoney/manage.py @@ -4,7 +4,7 @@ import os import pkgutil import random import sys -from getpass import getpass +import getpass from flask_script import Manager, Command, Option from flask_migrate import Migrate, MigrateCommand @@ -20,11 +20,11 @@ class GeneratePasswordHash(Command): """Get password from user and hash it without printing it in clear text.""" def run(self): - password = getpass(prompt='Password: ') + password = getpass.getpass(prompt='Password: ') print(generate_password_hash(password)) -class ConfigTemplate(Command): +class GenerateConfig(Command): def get_options(self): return [ Option('config_file', choices=[ @@ -74,7 +74,7 @@ def main(): manager = Manager(app) manager.add_command('db', MigrateCommand) manager.add_command('generate_password_hash', GeneratePasswordHash) - manager.add_command('generate-config', ConfigTemplate) + manager.add_command('generate-config', GenerateConfig) manager.run() -- cgit v1.1 From 0504fd82f52317d902e85a6e448048d5ef1c58d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Fri, 5 Jan 2018 22:36:31 +0100 Subject: Fix the supervisord template. The script was relying on the presence of an environment variable, which is only set when the virtualenv is activated. But a virtualenv does not have to be activated to work (it's possible to call the python command directly). This fixes it by relying on `sys.executable` which should be correct at all times. Fixes #306 --- ihatemoney/manage.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ihatemoney/manage.py') diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py index 315cfac..73bca57 100755 --- a/ihatemoney/manage.py +++ b/ihatemoney/manage.py @@ -49,9 +49,11 @@ class GenerateConfig(Command): os.path.join('conf-templates/', config_file) + '.j2' ).decode('utf-8') + bin_path = os.path.dirname(sys.executable) + print(Template(template_content).render( pkg_path=os.path.abspath(os.path.dirname(__file__)), - venv_path=os.environ.get('VIRTUAL_ENV'), + bin_path=bin_path, secret_key=self.gen_secret_key(), )) -- cgit v1.1 From 230eafdf58c46b983936cbf4f70b712bbddfd8c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Sun, 14 Jan 2018 16:52:52 +0100 Subject: Use Jinja2 strict rendering. For this I had to create an Jinja2 explicit environment, so I put a function in `ihatemoney.utils.create_jinja2_env(strict_rendering=False)`. When using this environment and if `strict_rendering` is activated, templates using undefined variables will now error out rather than failing silently. --- ihatemoney/manage.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'ihatemoney/manage.py') diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py index 73bca57..9058b39 100755 --- a/ihatemoney/manage.py +++ b/ihatemoney/manage.py @@ -1,18 +1,17 @@ #!/usr/bin/env python import os -import pkgutil import random import sys import getpass from flask_script import Manager, Command, Option from flask_migrate import Migrate, MigrateCommand -from jinja2 import Template from werkzeug.security import generate_password_hash from ihatemoney.run import create_app from ihatemoney.models import db +from ihatemoney.utils import create_jinja_env class GeneratePasswordHash(Command): @@ -44,15 +43,14 @@ class GenerateConfig(Command): for i in range(50)]) def run(self, config_file): - template_content = pkgutil.get_data( - 'ihatemoney', - os.path.join('conf-templates/', config_file) + '.j2' - ).decode('utf-8') + env = create_jinja_env('conf-templates', strict_rendering=True) + template = env.get_template('%s.j2' % config_file) bin_path = os.path.dirname(sys.executable) + pkg_path = os.path.abspath(os.path.dirname(__file__)) - print(Template(template_content).render( - pkg_path=os.path.abspath(os.path.dirname(__file__)), + print(template.render( + pkg_path=pkg_path, bin_path=bin_path, secret_key=self.gen_secret_key(), )) -- cgit v1.1 From c3f8ddd274a40b164b5fceeab44c1c26cf053b04 Mon Sep 17 00:00:00 2001 From: JocelynDelalande Date: Mon, 16 Jul 2018 22:55:54 +0200 Subject: Fix Apache conf template, without relying on environment var (#359) `python-home` is prefered over `python-path`. It will work with or without a virtualenv. See http://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html --- ihatemoney/manage.py | 1 + 1 file changed, 1 insertion(+) (limited to 'ihatemoney/manage.py') diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py index 9058b39..3207b55 100755 --- a/ihatemoney/manage.py +++ b/ihatemoney/manage.py @@ -52,6 +52,7 @@ class GenerateConfig(Command): print(template.render( pkg_path=pkg_path, bin_path=bin_path, + sys_prefix=sys.prefix, secret_key=self.gen_secret_key(), )) -- cgit v1.1