Beispiel #1
0
def main():
    """Start the commandline manager."""
    from invenio.base.factory import create_app

    app = create_app()
    manager.app = app
    manager.run()
Beispiel #2
0
def iter_suites(packages=None):
    """Yield all testsuites."""
    from werkzeug.utils import import_string, find_modules
    from flask_registry import ModuleAutoDiscoveryRegistry, \
        ImportPathRegistry

    app = create_app()

    if packages is None:
        testsuite = ModuleAutoDiscoveryRegistry('testsuite', app=app)
        from invenio import testsuite as testsuite_invenio
        from invenio.base import testsuite as testsuite_base
        from invenio.celery import testsuite as testsuite_celery
        testsuite.register(testsuite_invenio)
        testsuite.register(testsuite_base)
        testsuite.register(testsuite_celery)
    else:
        exclude = map(lambda x: x + '.testsuite',
                      app.config.get('PACKAGES_EXCLUDE', []))
        testsuite = ImportPathRegistry(initial=packages, exclude=exclude,
                                       load_modules=True)

    for package in testsuite:
        for name in find_modules(package.__name__):
            module = import_string(name)
            if not module.__name__.split('.')[-1].startswith('test_'):
                continue
            if hasattr(module, 'TEST_SUITE'):
                yield module.TEST_SUITE
            else:
                app.logger.warning(
                    "%s: No test suite defined." % module.__name__)
Beispiel #3
0
def main():
    from invenio.base.factory import create_app
    app = create_app()
    manager.app = app
    if len(sys.argv) < 2 or sys.argv[1] != 'dbexec':
        sys.argv.insert(1, 'dbexec')
    manager.run()
Beispiel #4
0
def main():
    """Main."""
    from invenio.base.factory import create_app

    app = create_app()
    manager.app = app
    manager.run()
Beispiel #5
0
def iter_suites(packages=None):
    """Yield all testsuites."""
    from werkzeug.utils import import_string, find_modules
    from flask_registry import ModuleAutoDiscoveryRegistry, \
        ImportPathRegistry

    app = create_app()

    if packages is None:
        testsuite = ModuleAutoDiscoveryRegistry('testsuite', app=app)
        from invenio import testsuite as testsuite_invenio
        from invenio.base import testsuite as testsuite_base
        from invenio.celery import testsuite as testsuite_celery
        testsuite.register(testsuite_invenio)
        testsuite.register(testsuite_base)
        testsuite.register(testsuite_celery)
    else:
        exclude = map(lambda x: x + '.testsuite',
                      app.config.get('PACKAGES_EXCLUDE', []))
        testsuite = ImportPathRegistry(initial=packages,
                                       exclude=exclude,
                                       load_modules=True)

    for package in testsuite:
        for name in find_modules(package.__name__):
            module = import_string(name)
            if not module.__name__.split('.')[-1].startswith('test_'):
                continue
            if hasattr(module, 'TEST_SUITE'):
                yield module.TEST_SUITE
            else:
                app.logger.warning("%s: No test suite defined." %
                                   module.__name__)
Beispiel #6
0
def main():
    from invenio.base.factory import create_app
    app = create_app()
    manager.app = app
    if len(sys.argv) < 2 or sys.argv[1] != 'dbexec':
        sys.argv.insert(1, 'dbexec')
    manager.run()
Beispiel #7
0
def setup(sphinx):
    """Setup Sphinx object."""
    from flask import has_app_context
    from invenio.base.factory import create_app

    if not has_app_context():
        app = create_app()
        ctx = app.test_request_context("/")
        ctx.push()
def init_app_context():
    """Initialize app context for Invenio 2.x."""
    try:
        from invenio.base.factory import create_app
        app = create_app()
        app.test_request_context('/').push()
        app.preprocess_request()
    except ImportError:
        pass
Beispiel #9
0
def setup(sphinx):
    """Setup Sphinx object."""
    from flask import has_app_context
    from invenio.base.factory import create_app

    if not has_app_context():
        app = create_app()
        ctx = app.test_request_context('/')
        ctx.push()
Beispiel #10
0
def init_app_context():
    """Initialize app context for Invenio 2.x."""
    try:
        from invenio.base.factory import create_app
        app = create_app()
        app.test_request_context('/').push()
        app.preprocess_request()
    except ImportError:
        pass
Beispiel #11
0
def setup(sphinx):
    """Setup Sphinx object."""
    from flask import has_app_context
    from invenio.base.factory import create_app
    PACKAGES = ['invenio.base', 'invenio.modules.accounts',
                'invenio.modules.records', 'invenio_tags']

    if not has_app_context():
        app = create_app(PACKAGES=PACKAGES)
        ctx = app.test_request_context('/')
        ctx.push()
Beispiel #12
0
def iter_suites():
    """Yield all testsuites."""
    app = create_app()
    packages = ['invenio', 'invenio.base', 'invenio.celery']
    packages += app.config.get('PACKAGES', [])

    for module in import_submodules_from_packages('testsuite',
                                                  packages=packages):
        if not module.__name__.split('.')[-1].startswith('test_'):
            continue
        if hasattr(module, 'TEST_SUITE'):
            yield module.TEST_SUITE
Beispiel #13
0
def setup(sphinx):
    """Setup Sphinx object."""
    from flask import has_app_context
    from invenio.base.factory import create_app
    PACKAGES = [
        'invenio.base', 'invenio.modules.accounts', 'invenio.modules.records',
        'invenio_tags'
    ]

    if not has_app_context():
        app = create_app(PACKAGES=PACKAGES)
        ctx = app.test_request_context('/')
        ctx.push()
Beispiel #14
0
def dumpfiles():
    """Dump files."""
    from invenio.base.factory import create_app

    app = create_app()
    with app.app_context():
        from invenio.modules.editor.models import Bibdoc
        from invenio.legacy.bibdocfile.api import BibDoc

        q = Bibdoc.query
        with open("files.json", "w") as fp:
            fp.write("[")
            with click.progressbar(q, length=q.count()) as query:
                for d in query:
                    bd = BibDoc(d.id)
                    try:
                        for f in bd.docfiles:
                            fp.write(
                                json.dumps(
                                    dict(
                                        comment=f.comment,
                                        creation_date=f.cd.isoformat(),
                                        modification_date=f.md.isoformat(),
                                        description=f.description,
                                        docid=f.docid,
                                        encoding=f.encoding,
                                        flags=f.flags,
                                        format=f.get_format(),
                                        hidden=f.hidden,
                                        is_icon=f.is_icon(),
                                        magic=f.get_magic(),
                                        md5=f.get_checksum(),
                                        mime=f.mime,
                                        name=f.get_full_name(),
                                        path=f.fullpath,
                                        recid=f.get_recid(),
                                        size=f.size,
                                        status=f.status,
                                        subformat=f.get_subformat(),
                                        version=f.version,
                                    )
                                )
                            )
                            fp.write(",")
                    except Exception:
                        print("Failed: {0}".format(bd.id))
            fp.seek(fp.tell() - 1)
            fp.write("]")
Beispiel #15
0
    def _init_flask(self):
        """
        Initialize Flask application.

        The Flask application should only be created in the workers, thus
        this method should not be called from the __init__ method.
        """
        if not self.flask_app:
            from flask import current_app
            if current_app:
                self.flask_app = current_app
            else:
                from invenio.base.factory import create_app
                self.flask_app = create_app(CELERY_CONTEXT=True)
                from invenio.ext.sqlalchemy import db
                self.db = db
Beispiel #16
0
    def _init_flask(self):
        """
        Initialize Flask application.

        The Flask application should only be created in the workers, thus
        this method should not be called from the __init__ method.
        """
        if not self.flask_app:
            from flask import current_app
            if current_app:
                self.flask_app = current_app
            else:
                from invenio.base.factory import create_app
                self.flask_app = create_app()
                from invenio.ext.sqlalchemy import db
                self.db = db
Beispiel #17
0
def dumpfiles():
    """Dump files."""
    from invenio.base.factory import create_app

    app = create_app()
    with app.app_context():
        from invenio.modules.editor.models import Bibdoc
        from invenio.legacy.bibdocfile.api import BibDoc

        q = Bibdoc.query
        with open('files.json', 'w') as fp:
            fp.write("[")
            with click.progressbar(q, length=q.count()) as query:
                for d in query:
                    bd = BibDoc(d.id)
                    try:
                        for f in bd.docfiles:
                            fp.write(
                                json.dumps(
                                    dict(
                                        comment=f.comment,
                                        creation_date=f.cd.isoformat(),
                                        modification_date=f.md.isoformat(),
                                        description=f.description,
                                        docid=f.docid,
                                        encoding=f.encoding,
                                        flags=f.flags,
                                        format=f.get_format(),
                                        hidden=f.hidden,
                                        is_icon=f.is_icon(),
                                        magic=f.get_magic(),
                                        md5=f.get_checksum(),
                                        mime=f.mime,
                                        name=f.get_full_name(),
                                        path=f.fullpath,
                                        recid=f.get_recid(),
                                        size=f.size,
                                        status=f.status,
                                        subformat=f.get_subformat(),
                                        version=f.version,
                                    )))
                            fp.write(",")
                    except Exception:
                        print("Failed: {0}".format(bd.id))
            fp.seek(fp.tell() - 1)
            fp.write("]")
Beispiel #18
0
def dumprecords():
    """Dump records."""
    from invenio.base.factory import create_app

    app = create_app()
    with app.app_context():
        from invenio.modules.editor.models import Bibrec
        from invenio.modules.records.api import Record
        data = []
        q = Bibrec.query
        with click.progressbar(q, length=q.count()) as query:
            for r in query:
                d = Record.get_record(r.id)
                if d:
                    data.append(d.dumps(clean=True))

        with open('dump2.json', 'w') as f:
            json.dump(data, f)
Beispiel #19
0
def dumprecords():
    """Dump records."""
    from invenio.base.factory import create_app

    app = create_app()
    with app.app_context():
        from invenio.modules.editor.models import Bibrec
        from invenio.modules.records.api import Record

        data = []
        q = Bibrec.query
        with click.progressbar(q, length=q.count()) as query:
            for r in query:
                d = Record.get_record(r.id)
                if d:
                    data.append(d.dumps(clean=True))

        with open("dump2.json", "w") as f:
            json.dump(data, f)
Beispiel #20
0
def setup(sphinx):
    from invenio.base.factory import create_app
    app = create_app()
    ctx = app.test_request_context('/')
    ctx.push()
Beispiel #21
0
def main():
    """Start the commandline manager."""
    from invenio.base.factory import create_app
    app = create_app()
    manager.app = app
    manager.run()
Beispiel #22
0
def main():
    """Run manager."""
    from invenio.base.factory import create_app
    app = create_app()
    manager.app = app
    manager.run()
Beispiel #23
0
def main():
    """Execute script."""
    from invenio.base.factory import create_app
    app = create_app()
    manager.app = app
    manager.run()
Beispiel #24
0
def main():
    """Run manager."""
    manager.app = create_app()
    manager.run()
Beispiel #25
0
def main():
    """Execute script."""
    from invenio.base.factory import create_app
    app = create_app()
    manager.app = app
    manager.run()
Beispiel #26
0
 def create_app(self):
     """Create the Flask application for testing."""
     app = create_app(**self.config)
     app.testing = True
     return app
Beispiel #27
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""Invenio manager implementation using *Flask-Script*."""

from __future__ import print_function

from flask import current_app
from invenio.base.factory import create_app
from invenio.ext.script import Manager, change_command_name, register_manager

manager = Manager(create_app(), with_default_commands=False)


@manager.shell
def make_shell_context():
    """Extend shell context."""
    from invenio.ext.sqlalchemy import db
    return dict(current_app=current_app, db=db)


@manager.command
def version():
    """Get running version of Invenio."""
    return current_app.config.get('CFG_VERSION')

Beispiel #28
0
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""Invenio manager implementation using *Flask-Script*."""

from __future__ import print_function

from flask import current_app
from invenio.base.factory import create_app
from invenio.ext.script import Manager, change_command_name, register_manager

manager = Manager(create_app(), with_default_commands=False)


@manager.shell
def make_shell_context():
    """Extend shell context."""
    from invenio.ext.sqlalchemy import db
    return dict(current_app=current_app, db=db)


@manager.command
def version():
    """Get running version of Invenio."""
    return current_app.config.get('CFG_VERSION')

Beispiel #29
0
if __name__ == '__main__':

    usage = "usage: %prog [options]"

    parser = OptionParser(usage)

    parser.set_description("""
    This script is done to test elasticserarch for Invenio.
    It should be replaced by unittests.
    Bascally it create a new index, index 100 records and perform a search
    query.
    """)

    (options, args) = parser.parse_args()
    from invenio.base.factory import create_app
    current_app = create_app()

    with current_app.test_request_context():
        print("-- Connect to the ES server --")
        es = current_app.extensions.get("elasticsearch")

        print("-- Delete old index --")
        es.delete_index()

        print("-- Create the index --")
        es.create_index()

        print("-- Index records --")
        es.index_records(range(1, 100), bulk_size=10)

        print("-- Index documents --")
Beispiel #30
0
def main():
    """Run manager."""
    manager.app = create_app()
    manager.run()
Beispiel #31
0
 def create_app(self):
     """Create the Flask application for testing."""
     app = create_app(**self.config)
     app.testing = True
     return app
Beispiel #32
0
if __name__ == '__main__':

    usage = "usage: %prog [options]"

    parser = OptionParser(usage)

    parser.set_description("""
    This script is done to test elasticserarch for Invenio.
    It should be replaced by unittests.
    Bascally it create a new index, index 100 records and perform a search
    query.
    """)

    (options, args) = parser.parse_args()
    from invenio.base.factory import create_app
    current_app = create_app()

    with current_app.test_request_context():
        print ("-- Connect to the ES server --")
        es = current_app.extensions.get("elasticsearch")

        print("-- Delete old index --")
        es.delete_index()

        print("-- Create the index --")
        es.create_index()

        print("-- Index records --")
        es.index_records(range(1, 100), bulk_size=10)

        print("-- Index documents --")