aboutsummaryrefslogtreecommitdiff
path: root/ihatemoney/manage.py
diff options
context:
space:
mode:
authorJocelynDelalande <JocelynDelalande@users.noreply.github.com>2017-10-23 18:05:50 +0200
committerAlexis Metaireau <alexis@notmyidea.org>2017-10-23 18:05:50 +0200
commite3285bef364a675f97b9e4f08c47a45405399561 (patch)
tree3b9caa6f10a544de6f635ed570a1f3223229003e /ihatemoney/manage.py
parentefd2b66ac6dd5018939e4d8a9ed5e6bc326559bf (diff)
downloadihatemoney-mirror-e3285bef364a675f97b9e4f08c47a45405399561.zip
ihatemoney-mirror-e3285bef364a675f97b9e4f08c47a45405399561.tar.gz
ihatemoney-mirror-e3285bef364a675f97b9e4f08c47a45405399561.tar.bz2
Enhance install process by generating config files from templates (#275)
* Add a command to generate configuration examples Config files are generated from templates (which remplace previous example files). - solve the issue of hard-to-explain configuration examples - ease pkg path seeking (avoid it, actually) - add working defaults for sqlite and unix socket paths (instead of /replace/me/path/example) - move settings comments from default_settings.py to ihatemoney.cfg.j2, as it is the one that will be facing user. * Use generate-config command in install doc Also follow the new working defaults of templates for socket and db path. * Fix doc settings table On the long term, plaintext tables might destroy humanity. * Mention templates dir URL in documentation As requested by @almet
Diffstat (limited to 'ihatemoney/manage.py')
-rwxr-xr-xihatemoney/manage.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py
index 6f63a98..c1821c5 100755
--- a/ihatemoney/manage.py
+++ b/ihatemoney/manage.py
@@ -1,8 +1,13 @@
#!/usr/bin/env python
+import os
+import pkgutil
+import random
from getpass import getpass
-from flask_script import Manager, Command
+
+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
@@ -18,6 +23,38 @@ class GeneratePasswordHash(Command):
print(generate_password_hash(password))
+class ConfigTemplate(Command):
+ def get_options(self):
+ return [
+ Option('config_file', choices=[
+ 'ihatemoney.cfg',
+ 'apache-vhost.conf',
+ 'gunicorn.conf.py',
+ 'supervisord.conf',
+ 'nginx.conf',
+ ]),
+ ]
+
+ @staticmethod
+ def gen_secret_key():
+ return ''.join([
+ random.SystemRandom().choice(
+ 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
+ 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')
+
+ print(Template(template_content).render(
+ pkg_path=os.path.abspath(os.path.dirname(__file__)),
+ venv_path=os.environ.get('VIRTUAL_ENV'),
+ secret_key=self.gen_secret_key(),
+ ))
+
+
def main():
app = create_app()
Migrate(app, db)
@@ -25,6 +62,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.run()