Exemple #1
0
    def __init__(self):

        #: If application is runing in debug mode.
        self.debug = settings.DEBUG

        # Initialize logging.
        init_logger()

        # Initialize the object pool
        pool.load()

        #: List of all the registered middlewares (settings.MIDDLEWARE_CLASSES)
        self.middlewares = [import_string(s)() for s in settings.MIDDLEWARE_CLASSES]

        # static data middleware
        self.dispatch = StaticMiddleware.from_paths(self.dispatch, {
                '/static': os.path.join(settings.PROJECT_DIR, 'static'),
            }, pool.get_static_paths(), settings.STATIC_LINKS)

        pool.url_map.add(
            Rule('/static/<filename>',
                endpoint='static', methods=('GET',), build_only=True))

        #: The jinja2 environment
        self.jinja_env = self._create_jinja_env(pool.get_template_paths())
Exemple #2
0
def run_tests(names, verbosity=1):
    """Run unittests for all the test names.

    A name can be either a package name or a fully qualified name of the
    test class or a specific test method within a package prefixed with
    ``package_name:``.

    For example:

        >>> run_tests('hello')
        >>> run_tests('hello:HelloTest')
        >>> run_tests('hello:HelloTest.test_hello')
        >>> run_tests('foo:foo.FooTest')
        >>> run_tests('foo:bar.BarTest')

    :param names: a sequence of names
    :param verbosity: verbose level
    """

    from kalapy.core.pool import pool
    from kalapy.db.engines import database

    database.connect()
    try:
        # Initialize the object pool
        pool.load()
        suite = unittest.TestSuite()
        for name in names:
            suite.addTest(build_suite(name))
        result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
    finally:
        database.close()

    return len(result.failures) + len(result.errors)
Exemple #3
0
    def execute(self, options, args):

        # Initialize the object pool
        from kalapy.core.pool import pool
        pool.load()

        try:
            if options.plain:
                raise ImportError
            import IPython
            shell = IPython.Shell.IPShell(argv=[])
            shell.mainloop()
        except ImportError:
            imported_objects = {}
            try:  # Try activating rlcompleter, because it's handy.
                import readline
                import rlcompleter
                readline.set_completer(
                    rlcompleter.Completer(imported_objects).complete)
                readline.parse_and_bind("tab:complete")
            except ImportError:
                pass

            import code
            code.interact(local=imported_objects)
Exemple #4
0
    def __init__(self):

        #: If application is runing in debug mode.
        self.debug = settings.DEBUG

        # Initialize logging.
        init_logger()

        # Initialize the object pool
        pool.load()

        #: List of all the registered middlewares (settings.MIDDLEWARE_CLASSES)
        self.middlewares = [
            import_string(s)() for s in settings.MIDDLEWARE_CLASSES
        ]

        # static data middleware
        self.dispatch = StaticMiddleware.from_paths(
            self.dispatch, {
                '/static': os.path.join(settings.PROJECT_DIR, 'static'),
            }, pool.get_static_paths(), settings.STATIC_LINKS)

        pool.url_map.add(
            Rule('/static/<filename>',
                 endpoint='static',
                 methods=('GET', ),
                 build_only=True))

        #: The jinja2 environment
        self.jinja_env = self._create_jinja_env(pool.get_template_paths())
Exemple #5
0
    def execute(self, options, args):
        try:
            script = args[0]
        except:
            self.print_help()

        if not os.path.exists(script):
            self.error("%r doesn't exist." % script)

        # Initialize the object pool
        from kalapy.core.pool import pool
        pool.load()

        execfile(script, {'__name__': '__main__'})
Exemple #6
0
    def execute(self, options, args):
        try:
            script = args[0]
        except:
            self.print_help()

        if not os.path.exists(script):
            self.error("%r doesn't exist." % script)

        # Initialize the object pool
        from kalapy.core.pool import pool
        pool.load()

        execfile(script, {'__name__': '__main__'})
Exemple #7
0
    def execute(self, options, args):

        if settings.DATABASE_ENGINE == "dummy":
            raise self.error("DATABASE_ENGINE is not configured.")

        try:
            database.connect()
            try:
                # Initialize the object pool
                from kalapy.core.pool import pool
                pool.load()
                super(DBCommand, self).execute(options, args)
            finally:
                database.close()
        except db.DatabaseError, e:
            self.error(e)
Exemple #8
0
    def execute(self, options, args):

        # Initialize the object pool
        from kalapy.core.pool import pool
        pool.load()

        try:
            if options.plain:
                raise ImportError
            import IPython
            shell = IPython.Shell.IPShell(argv=[])
            shell.mainloop()
        except ImportError:
            imported_objects = {}
            try: # Try activating rlcompleter, because it's handy.
                import readline
                import rlcompleter
                readline.set_completer(rlcompleter.Completer(imported_objects).complete)
                readline.parse_and_bind("tab:complete")
            except ImportError:
                pass

            import code
            code.interact(local=imported_objects)