Esempio n. 1
0
def app(config_path):
    core.load_config(config_path)
    core.load_storage()
    core.load_session()
    core.load_wsgi()
    app = core.app
    return app
Esempio n. 2
0
def app(config_path):
    config = ConfigParser.ConfigParser()

    if not os.path.exists(config_path):
        print('Error: "%s" file not exists.' % config_path)
        sys.exit(1)

    config.read(config_path)

    # Create storage
    storage_settings = {}
    for item in config.items('storage'):
        storage_settings[item[0]] = item[1]
    del storage_settings['type']

    # Flask webserver config
    if config.has_section('webserver') and config.get('webserver', 'host'):
        core.host = config.get('webserver', 'host')
    if config.has_section('webserver') and config.get('webserver', 'port'):
        core.port = config.get('webserver', 'port')
    if config.has_section('webserver') and config.get('webserver', 'debug'):
        if config.get('webserver', 'debug') in ['True', 'true']:
            core.debug = True
        else:
            core.debug = False

    storage_module = _load_storage(config.get('storage', 'type'))
    core.storage = storage_module
    core.storage_settings = storage_settings
    core.load_storage()
    core.load_wsgi()

    app = core.app
    return app
Esempio n. 3
0
def run(config_path, args):
    args.append('-B')
    args.append('-l')
    args.append('INFO')
    core.load_config(config_path)
    core.load_storage()
    core.load_session()

    broker = core.config.get('worker', 'broker')
    interval = core.config.get('worker', 'interval')
    retention = core.config.get('worker', 'retention')
    story_before_retention = core.config.get('worker', 'story_before_retention')

    celery = Celery('tasks', broker=broker)

    @celery.task
    def refresh_all():
        helpers.refresh_all()

    @celery.task
    def run_retention(delta):
        helpers.run_retention(delta)

    celery.conf.CELERYBEAT_SCHEDULE = {
        'refresh-job': {
            'task': 'leselys.worker.refresh_all',
            'schedule': timedelta(minutes=int(interval))
        },
        'retention-job': {
            'task': 'leselys.worker.run_retention',
            'schedule': timedelta(days=1),
            'args': (int(retention), int(story_before_retention))
        }
    }
    celery.conf.INSTALLED_APPS = ('tasks.refresh_all', 'tasks.run_retention')

    print('Args: %s' % ' '.join(args))
    celery.start(args)
Esempio n. 4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest

from leselys import core


from flask import request

core.app.config['TESTING'] = True
core.load_config('config.ini')
core.load_storage()
core.load_session()
core.load_wsgi()

class TestLeselysAPI(unittest.TestCase):

    def setUp(self):
        self.r = core.app.test_client()

    def test_01_home(self):
        with self.r as c:
            rv = c.get('/?jsonsify=true')
            print(rv.status_code)
            print(rv.data)

if __name__ == "__main__":
    unittest.main()