From 3a72b59bf02ee74e9e9713705e819c5decbe3c88 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 9 Apr 2014 07:57:03 +0200 Subject: Removed initialization script. --- README.md | 52 +++++++++++++++++++++++++-- conf.py | 82 +++++++++++++++++++++--------------------- db_create.py | 16 --------- install.sh | 7 ++-- pyaggr3g470r/initialization.py | 29 --------------- pyaggr3g470r/views.py | 1 - runserver.py | 3 +- 7 files changed, 93 insertions(+), 97 deletions(-) delete mode 100755 pyaggr3g470r/initialization.py diff --git a/README.md b/README.md index d69fca13..23dd74b4 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,56 @@ Features * favorite articles; * share articles with Google +, Pinboard and reddit. -Installation ------------- -You need to have installed Python >= 2.7 and some Python libraries. +Deployment +---------- + +This application can be deployed both on Heroku and on a traditional server. + +Deploying the application on Heroku +''''''''''''''''''''''''''''''''''' + +.. code:: bash + + $ git clone https://bitbucket.org/cedricbonhomme/pyaggr3g470r.git + $ cd pyaggr3g470r + $ heroku create + $ heroku addons:add heroku-postgresql:dev + $ heroku config:set HEROKU=1 + $ git push heroku master + $ heroku run init + $ heroku ps:scale web=1 + + +Deploying the application on a traditional server +''''''''''''''''''''''''''''''''''''''''''''''''' + Configuration is done via the file *conf/conf.cfg*. +.. code:: bash + + $ git clone https://bitbucket.org/cedricbonhomme/pyaggr3g470r.git + $ cd pyaggr3g470r + $ cp conf/conf.cfg-sample conf/conf.cfg + $ sudo apt-get install postgresql postgresql-server-dev-9.1 postgresql-client + $ sudo pip install --upgrade -r requirements.txt + $ sudo -u postgres createuser + Enter name of role to add: username + Shall the new role be a superuser? (y/n) n + Shall the new role be allowed to create databases? (y/n) y + Shall the new role be allowed to create more new roles? (y/n) n + $ createdb pyAggr3g470r + $ sudo -u postgres psql + postgres=# ALTER USER username WITH ENCRYPTED PASSWORD 'password'; + postgres=# GRANT ALL PRIVILEGES ON DATABASE pyAggr3g470r TO username; + postgres=# \q + $ export DATABASE_URL="postgres://username:password@127.0.0.1:5432/pyAggr3g470r" + $ python db_create.py + $ python runserver.py + * Running on http://0.0.0.0:5000/ + * Restarting with reloader + + Launch the script ``install.sh`` in order to install automatically all requirements. In order to prevent all dependencies problems and to keep your system stable, the libraries will be installed in a Python virtual environment (with [virtualenv](http://www.virtualenv.org)). @@ -40,6 +84,8 @@ For example if you want to use pyAggr3g470r with Tor/Privoxy, you just have to s However, the default configuration should be good, so you really just have to run the script *install.sh*. + + Automatic updates ----------------- diff --git a/conf.py b/conf.py index d3beebce..be99b97b 100644 --- a/conf.py +++ b/conf.py @@ -7,57 +7,55 @@ This file contain the variables used by the application. """ import os, sys -try: - import configparser as confparser -except: - import ConfigParser as confparser -# load the configuration -config = confparser.SafeConfigParser() -config.read("./conf/conf.cfg") +ON_HEROKU = int(os.environ.get('HEROKU', 0)) == 1 +if not ON_HEROKU: + try: + import configparser as confparser + except: + import ConfigParser as confparser + # load the configuration + config = confparser.SafeConfigParser() + config.read("./conf/conf.cfg") + # Whoosh does not work on Heroku + WHOOSH_ENABLED = True + HTTP_PROXY = config.get('feedparser', 'http_proxy') + USER_AGENT = config.get('feedparser', 'user_agent') + RESOLVE_ARTICLE_URL = int(config.get('feedparser', 'resolve_article_url')) == 1 -basedir = os.path.abspath(os.path.dirname(__file__)) - -CSRF_ENABLED = True - -SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL'] - -# slow database query threshold (in seconds) -DATABASE_QUERY_TIMEOUT = 0.5 - - + WEBSERVER_DEBUG = int(config.get('webserver', 'debug')) == 1 + WEBSERVER_HOST = config.get('webserver', 'host') + WEBSERVER_PORT = int(config.get('webserver', 'port')) + MAIL_ENABLED = int(config.get('mail', 'enabled')) == 1 + MAIL_HOST = config.get('mail', 'host') + MAIL_PORT = int(config.get('mail', 'port')) + MAIL_TLS = int(config.get('mail', 'tls')) == 1 + MAIL_SSL = int(config.get('mail', 'ssl')) == 1 + MAIL_USERNAME = config.get('mail', 'username') + MAIL_PASSWORD = config.get('mail', 'password') + MAIL_FROM = config.get('mail', 'mail_from') + MAIL_TO = config.get('mail', 'mail_to') + basedir = os.path.abspath(os.path.dirname(__file__)) + PATH = os.path.abspath(".") +else: + HTTP_PROXY = "" + USER_AGENT = "pyAggr3g470r (https://bitbucket.org/cedricbonhomme/pyaggr3g470r)" + RESOLVE_ARTICLE_URL = int(os.environ.get('RESOLVE_ARTICLE_URL', 0)) == 1 + WEBSERVER_DEBUG = False + WEBSERVER_HOST ='0.0.0.0' + WEBSERVER_PORT = int(os.environ.get('PORT', 5000)) + MAIL_ENABLED = False -PATH = os.path.abspath(".") - -DATABASE_NAME = config.get('database', 'name') -DATABASE_PORT = int(config.get('database', 'port')) -DATABASE_USERNAME = config.get('database', 'username') -DATABASE_PASSWORD = config.get('database', 'password') -DATABASE_ADDRESS = config.get('database', 'address') - -HTTP_PROXY = config.get('feedparser', 'http_proxy') -USER_AGENT = config.get('feedparser', 'user_agent') -RESOLVE_ARTICLE_URL = int(config.get('feedparser', 'resolve_article_url')) == 1 - -WEBSERVER_DEBUG = int(config.get('webserver', 'debug')) == 1 -WEBSERVER_HOST = config.get('webserver', 'host') -WEBSERVER_PORT = int(config.get('webserver', 'port')) - -MAIL_ENABLED = int(config.get('mail', 'enabled')) == 1 -MAIL_HOST = config.get('mail', 'host') -MAIL_PORT = int(config.get('mail', 'port')) -MAIL_TLS = int(config.get('mail', 'tls')) == 1 -MAIL_SSL = int(config.get('mail', 'ssl')) == 1 -MAIL_USERNAME = config.get('mail', 'username') -MAIL_PASSWORD = config.get('mail', 'password') -MAIL_FROM = config.get('mail', 'mail_from') -MAIL_TO = config.get('mail', 'mail_to') +CSRF_ENABLED = True +SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL'] +# slow database query threshold (in seconds) +DATABASE_QUERY_TIMEOUT = 0.5 \ No newline at end of file diff --git a/db_create.py b/db_create.py index c6eaec7d..aac3f68c 100644 --- a/db_create.py +++ b/db_create.py @@ -1,22 +1,6 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- -# Grenouille - An online service for weather data. -# Copyright (C) 2014 Cédric Bonhomme - http://cedricbonhomme.org/ -# -# This program 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 of the -# License, or (at your option) any later version. -# -# This program 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - __author__ = "Cedric Bonhomme" __version__ = "$Revision: 0.2 $" __date__ = "$Date: 2014/03/16 $" diff --git a/install.sh b/install.sh index 3528781b..4789066f 100755 --- a/install.sh +++ b/install.sh @@ -1,8 +1,7 @@ #!/bin/bash -# Installation of MongoDB -sudo apt-get install -y mongodb-server -sudo service mongodb start +# Installation of PostgreSQL +sudo apt-get install postgresql postgresql-server-dev-9.1 postgresql-client # Python dependencies sudo apt-get install -y python-pip @@ -13,7 +12,7 @@ pip install --upgrade -r requirements.txt # Configuration cp conf/conf.cfg-sample conf/conf.cfg -python pyaggr3g470r/initialization.py firstname lastname firstname.lastname@mail.com secret +python db_create.py # Launch pyAggr3g470r python runserver.py diff --git a/pyaggr3g470r/initialization.py b/pyaggr3g470r/initialization.py deleted file mode 100755 index fd0a59f8..00000000 --- a/pyaggr3g470r/initialization.py +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -"""initialization.py - -Initialization script. -""" - -import sys -from mongoengine import * -from werkzeug import generate_password_hash - -sys.path.append(".") -import conf -import models - -if __name__ == "__main__": - # Point of entry in execution mode - firstname = sys.argv[1] - lastname = sys.argv[2] - email = sys.argv[3] - password = sys.argv[4] - - db = connect(conf.DATABASE_NAME) - db.drop_database(conf.DATABASE_NAME) - - user = models.User(firstname=firstname, lastname=lastname, \ - email=email, pwdhash=generate_password_hash(password)) - user.save() diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 04d24d95..7544ad7f 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -32,7 +32,6 @@ from flask import render_template, jsonify, request, flash, session, url_for, re from flask.ext.login import LoginManager, login_user, logout_user, login_required, current_user, AnonymousUserMixin from flask.ext.principal import Principal, Identity, AnonymousIdentity, identity_changed, identity_loaded, Permission, RoleNeed, UserNeed -import conf import utils import export import feedgetter diff --git a/runserver.py b/runserver.py index b9a10dd7..1e8de552 100644 --- a/runserver.py +++ b/runserver.py @@ -4,5 +4,4 @@ import conf from pyaggr3g470r import app -app.run(host=conf.WEBSERVER_HOST, port=conf.WEBSERVER_PORT, \ - debug=conf.WEBSERVER_DEBUG) +app.run(host=conf.WEBSERVER_HOST, port=conf.WEBSERVER_PORT, debug=conf.WEBSERVER_DEBUG) -- cgit