Пример #1
0
def loadConfig(options):
    """Load the Warp config"""
    siteDir = FilePath(options['siteDir'])
    sys.path.insert(0, siteDir.path)

    configModule = reflect.namedModule(options['config'])
    config = configModule.config
    runtime.config.update(config)

    runtime.config['siteDir'] = siteDir
    runtime.config['warpDir'] = FilePath(runtime.__file__).parent()

    if options["skipSchemaCheck"]:
        runtime.config["schema"] = runtime.config.get("schema", {})
        runtime.config["schema"]["check"] = False

    store.setupStore()
    translate.loadMessages()

    _session, _base = db_session.setupSession()
    runtime.db_session = _session
    runtime.db_base = _base

    factory = site.WarpSite(resource.WarpResourceWrapper())
    runtime.config['warpSite'] = factory

    return configModule
Пример #2
0
    def getChildWithDefault(self, firstSegment, request):

        if firstSegment:
            fp = self.buildFilePath(request)
            if fp is not None:
                del request.postpath[:]
                return static.File(fp.path)

        # Init for everything except static files
        session = request.getSession()
        request.avatar = session.avatar

        if config.get("reloadMessages"):
            translate.loadMessages()

        request.translateTerm = translate.getTranslator(session.language)

        handler = self.dispatch.get(firstSegment)

        if handler is not None:
            return handler(request)

        node = helpers.getNode(firstSegment)

        if node is not None:
            if not access.allowed(request.avatar, node):
                return AccessDenied()
            return NodeResource(node)

        return NoResource()
Пример #3
0
    def getChildWithDefault(self, firstSegment, request):

        if firstSegment:
            fp = self.buildFilePath(request)
            if fp is not None:
                del request.postpath[:]
                return static.File(fp.path)

        # Init for everything except static files
        session = request.getSession()
        request.avatar = session.avatar

        getCurrentUser = config.get('getCurrentUser')
        if getCurrentUser and request.avatar:
            request.current_user = getCurrentUser(request.avatar.id)

        getRequestStore = config.get('getRequestStore')
        if getRequestStore is not None:
            request.store = getRequestStore(request)
        else:
            request.store = avatar_store

        if request.avatar is not None:
            getUser = config.get('getRequestUser')
            if getUser is not None:
                request.avatar.user = getUser(request)
            else:
                # Backward compatibility
                getUser = config.get('getAppUser')
                if getUser is not None:
                    warnings.warn(
                        "getAppUser is deprecated, use getRequestUser instead",
                        DeprecationWarning)
                    request.avatar.user = getUser(request.avatar)

        if config.get('reloadMessages'):
            translate.loadMessages()

        request.translateTerm = translate.getTranslator(session.language)

        segment = firstSegment
        if self.caseInsensitiveUrl:
            segment = firstSegment.lower()
        handler = self.dispatch.get(segment)

        if handler is not None:
            return handler(request)

        node = helpers.getNode(firstSegment)

        if node is not None:
            return NodeResource(node)

        return NoResource()
Пример #4
0
    def getChildWithDefault(self, firstSegment, request):

        if firstSegment:
            fp = self.buildFilePath(request)
            if fp is not None:
                del request.postpath[:]
                return static.File(fp.path)

        # Init for everything except static files
        session = request.getSession()
        request.avatar = session.avatar

        getRequestStore = config.get('getRequestStore')
        if getRequestStore is not None:
            request.store = getRequestStore(request)
        else:
            request.store = avatar_store

        if request.avatar is not None:
            getUser = config.get('getRequestUser')
            if getUser is not None:
                request.avatar.user = getUser(request)
            else:
                # Backward compatibility
                getUser = config.get('getAppUser')
                if getUser is not None:
                    warnings.warn("getAppUser is deprecated, use getRequestUser instead",
                                  DeprecationWarning)
                    request.avatar.user = getUser(request.avatar)

        if config.get('reloadMessages'):
            translate.loadMessages()

        request.translateTerm = translate.getTranslator(session.language)


        segment = firstSegment
        if self.caseInsensitiveUrl:
            segment = firstSegment.lower()
        handler = self.dispatch.get(segment)

        if handler is not None:
            return handler(request)

        node = helpers.getNode(firstSegment)

        if node is not None:
            if not access.allowed(request.avatar, node):
                return AccessDenied()
            return NodeResource(node)

        return NoResource()
Пример #5
0
    def makeService(self, options):

        siteDir = FilePath(options['siteDir'])

        if options.subCommand == "skeleton":
            print "Creating skeleton..."
            from warp.tools import skeleton
            skeleton.createSkeleton(siteDir)
            raise SystemExit

        elif options.subCommand == "node":
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import skeleton
            skeleton.createNode(nodes, options.subOptions['name'])
            raise SystemExit

        sys.path.insert(0, siteDir.path)

        configModule = __import__('warpconfig')
        config = configModule.config
        runtime.config.update(config)
        runtime.config['siteDir'] = siteDir
        runtime.config['warpDir'] = FilePath(runtime.__file__).parent()
        store.setupStore(config)
        translate.loadMessages()

        if hasattr(configModule, 'startup'):
            configModule.startup()


        if options.subCommand == "console":
            import code
            locals = {'store': runtime.store}
            c = code.InteractiveConsole(locals)
            c.interact()
            raise SystemExit


        factory = site.WarpSite(resource.WarpResourceWrapper())
        service = internet.TCPServer(config["port"], factory)

        if hasattr(configModule, 'mungeService'):
            service = configModule.mungeService(service)

        return service
Пример #6
0
    def makeService(self, options):

        siteDir = FilePath(options['siteDir'])

        sys.path.insert(0, siteDir.path)

        if options.subCommand == "skeleton":
            print "Creating skeleton..."
            from warp.tools import skeleton
            skeleton.createSkeleton(siteDir)
            raise SystemExit

        configModule = reflect.namedModule(options['config'])
        config = configModule.config
        runtime.config.update(config)
        runtime.config['siteDir'] = siteDir
        runtime.config['warpDir'] = FilePath(runtime.__file__).parent()
        store.setupStore()
        translate.loadMessages()

        if options.subCommand == "node":
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import skeleton
            skeleton.createNode(nodes, options.subOptions['name'])
            raise SystemExit

        elif options.subCommand == 'crud':
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import autocrud
            autocrud.autocrud(nodes, options.subOptions['name'], options.subOptions['model'])
            raise SystemExit

        elif options.subCommand == 'adduser':
            from warp.tools import adduser
            adduser.addUser()
            raise SystemExit


        factory = site.WarpSite(resource.WarpResourceWrapper())
        runtime.config['warpSite'] = factory

        if hasattr(configModule, 'startup'):
            configModule.startup()

        if options.subCommand == "console":
            import code
            locals = {'store': runtime.store}
            c = code.InteractiveConsole(locals)
            c.interact()
            raise SystemExit

        if options.subCommand == 'command':
            obj = reflect.namedObject(options.subOptions['fqn'])
            if options.subOptions['args']:
                obj(*options.subOptions['args'])
            else:
                obj()
            raise SystemExit

        if config.get('ssl'):
            from warp.webserver import sslcontext
            service = internet.SSLServer(config['port'], factory,
                                         sslcontext.ServerContextFactory())
        else:
            service = internet.TCPServer(config["port"], factory)

        if hasattr(configModule, 'mungeService'):
            service = configModule.mungeService(service)

        return service
Пример #7
0
    def makeService(self, options):

        siteDir = FilePath(options['siteDir'])

        sys.path.insert(0, siteDir.path)

        if options.subCommand == "skeleton":
            print "Creating skeleton..."
            from warp.tools import skeleton
            skeleton.createSkeleton(siteDir)
            raise SystemExit

        configModule = reflect.namedModule(options['config'])
        config = configModule.config
        runtime.config.update(config)
        runtime.config['siteDir'] = siteDir
        runtime.config['warpDir'] = FilePath(runtime.__file__).parent()
        store.setupStore()
        translate.loadMessages()

        if options.subCommand == "node":
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import skeleton
            skeleton.createNode(nodes, options.subOptions['name'])
            raise SystemExit

        elif options.subCommand == 'crud':
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import autocrud
            autocrud.autocrud(nodes, options.subOptions['name'],
                              options.subOptions['model'])
            raise SystemExit

        elif options.subCommand == 'adduser':
            from warp.tools import adduser
            adduser.addUser()
            raise SystemExit

        factory = site.WarpSite(resource.WarpResourceWrapper())
        runtime.config['warpSite'] = factory

        if hasattr(configModule, 'startup'):
            configModule.startup()

        if options.subCommand == "console":
            import code
            locals = {'store': runtime.store}
            c = code.InteractiveConsole(locals)
            c.interact()
            raise SystemExit

        if options.subCommand == 'command':
            obj = reflect.namedObject(options.subOptions['fqn'])
            obj()
            raise SystemExit

        if config.get('ssl'):
            from warp.webserver import sslcontext
            service = internet.SSLServer(config['port'], factory,
                                         sslcontext.ServerContextFactory())
        else:
            service = internet.TCPServer(config["port"], factory)

        if hasattr(configModule, 'mungeService'):
            service = configModule.mungeService(service)

        return service