Esempio n. 1
0
def app(request):
    """The redwind flask app, set up with an empty database and
    some sane defaults
    """

    def set_setting(key, value):
        from redwind.models import Setting
        s = Setting.query.get(key)
        if not s:
            s = Setting()
            s.key = key
            rw_db.session.add(s)
        s.value = value
        rw_db.session.commit()

    def bypass_login():
        from redwind.models import User
        from flask.ext.login import login_user
        from flask import redirect
        login_user(User('example.com'))
        return redirect('/')

    _, cfg_path = tempfile.mkstemp('redwind.cfg')
    with open(cfg_path, 'w') as f:
        f.write(CONFIG_FILE_CONTENT)

    rw_app = create_app(cfg_path)
    rw_app.add_url_rule('/', 'bypass_login', bypass_login)

    app_context = rw_app.app_context()
    app_context.push()
    assert str(rw_db.engine.url) == 'sqlite:///:memory:'

    rw_db.create_all()
    temp_upload_path = tempfile.mkdtemp()
    temp_imageproxy_path = tempfile.mkdtemp()
    rw_app.config['UPLOAD_PATH'] = temp_upload_path
    #rw_app.config['IMAGEPROXY_PATH'] = temp_imageproxy_path

    set_setting('posts_per_page', '15')
    set_setting('author_domain', 'example.com')
    set_setting('site_url', 'http://example.com')
    set_setting('timezone', 'America/Los_Angeles')
    rw_db.session.commit()

    yield rw_app

    assert str(rw_db.engine.url) == 'sqlite:///:memory:'
    shutil.rmtree(temp_upload_path)
    shutil.rmtree(temp_imageproxy_path)

    rw_db.session.remove()
    rw_db.drop_all()
    app_context.pop()
Esempio n. 2
0
def app(request):
    """The redwind flask app, set up with an empty database and
    some sane defaults
    """
    def set_setting(key, value):
        from redwind.models import Setting
        s = Setting.query.get(key)
        if not s:
            s = Setting()
            s.key = key
            rw_db.session.add(s)
        s.value = value
        rw_db.session.commit()

    def bypass_login():
        from redwind.models import User
        from flask.ext.login import login_user
        from flask import redirect
        login_user(User('example.com'))
        return redirect('/')

    _, cfg_path = tempfile.mkstemp('redwind.cfg')
    with open(cfg_path, 'w') as f:
        f.write(CONFIG_FILE_CONTENT)

    rw_app = create_app(cfg_path)
    rw_app.add_url_rule('/', 'bypass_login', bypass_login)

    app_context = rw_app.app_context()
    app_context.push()
    assert str(rw_db.engine.url) == 'sqlite:///:memory:'

    rw_db.create_all()
    temp_upload_path = tempfile.mkdtemp()
    temp_imageproxy_path = tempfile.mkdtemp()
    rw_app.config['UPLOAD_PATH'] = temp_upload_path
    #rw_app.config['IMAGEPROXY_PATH'] = temp_imageproxy_path

    set_setting('posts_per_page', '15')
    set_setting('author_domain', 'example.com')
    set_setting('site_url', 'http://example.com')
    set_setting('timezone', 'America/Los_Angeles')
    rw_db.session.commit()

    yield rw_app

    assert str(rw_db.engine.url) == 'sqlite:///:memory:'
    shutil.rmtree(temp_upload_path)
    shutil.rmtree(temp_imageproxy_path)

    rw_db.session.remove()
    rw_db.drop_all()
    app_context.pop()
from redwind import create_app
from redwind import util
from redwind import admin
from redwind.models import Post, Attachment
from redwind.extensions import db
import os
import datetime
import random
import string
import mimetypes
import shutil
from flask import current_app

app = create_app()


def convert_file_to_attachment(post, filename):
    fullpath = os.path.join(current_app.root_path, '_data',
                            post.path, 'files', filename)
    if not os.path.exists(fullpath):
        print('could not find', fullpath)
        return
    now = post.published
    storage_path = '{}/{:02d}/{:02d}/{}'.format(
        now.year, now.month, now.day,
        ''.join(random.choice(string.ascii_letters + string.digits)
                for _ in range(8)) + '-' + filename)
    mimetype, _ = mimetypes.guess_type(filename)
    attachment = Attachment(filename=filename,
                            mimetype=mimetype,
                            storage_path=storage_path)
Esempio n. 4
0
def async_app_context(app_config):
    from redwind import create_app
    app = create_app(app_config)
    with app.app_context():
        yield
Esempio n. 5
0
#!/usr/bin/env python

from redwind import create_app, models
from redwind.extensions import db
from flask import current_app

app = create_app()
with app.app_context():
    print('''\
    Welcome to the Red Wind installation script. This should only be used for
    to initialize a brand new database. Running this script against an existing
    database could destroy your data!''')

    print('creating database tables for database',
          current_app.config['SQLALCHEMY_DATABASE_URI'])
    db.create_all()
    print('done creating database tables')
Esempio n. 6
0
def async_app_context(config_file):
    from redwind import create_app
    app = create_app(config_file, is_queue=True)
    with app.app_context():
        yield
Esempio n. 7
0
def app(request):
    """The redwind flask app, set up with an empty database and
    some sane defaults
    """

    def set_setting(key, value):
        from redwind.models import Setting
        s = Setting.query.get(key)
        if not s:
            s = Setting()
            s.key = key
            rw_db.session.add(s)
        s.value = value
        rw_db.session.commit()

    def bypass_login():
        from redwind.models import User
        from flask.ext.login import login_user
        from flask import redirect
        login_user(User('example.com'))
        return redirect('/')

    dburi = 'sqlite:///:memory:'

    cfgfd, cfgname = tempfile.mkstemp(suffix='-redwind.cfg', text=True)
    with os.fdopen(cfgfd, 'w') as f:
        f.write("""\
SECRET_KEY = 'lmnop8765309'
DEBUG = True
DEBUG_TB_ENABLED = False
SQLALCHEMY_DATABASE_URI = '{}'
TESTING = True
REDIS_URL = 'redis://localhost:911'
BYPASS_INDIEAUTH = False""".format(dburi))

    rw_app = create_app(cfgname)
    rw_app.add_url_rule('/', 'bypass_login', bypass_login)

    app_context = rw_app.app_context()
    app_context.push()
    assert str(rw_db.engine.url) == dburi

    rw_db.create_all()
    temp_upload_path = tempfile.mkdtemp()
    temp_imageproxy_path = tempfile.mkdtemp()
    rw_app.config['UPLOAD_PATH'] = temp_upload_path
    rw_app.config['IMAGEPROXY_PATH'] = temp_imageproxy_path

    set_setting('posts_per_page', '15')
    set_setting('author_domain', 'example.com')
    set_setting('site_url', 'http://example.com')
    set_setting('timezone', 'America/Los_Angeles')
    rw_db.session.commit()

    yield rw_app

    assert str(rw_db.engine.url) == dburi
    shutil.rmtree(temp_upload_path)
    shutil.rmtree(temp_imageproxy_path)

    rw_db.session.remove()
    rw_db.drop_all()
    app_context.pop()
    os.unlink(cfgname)