Exemple #1
0
    def setUp(self):
        DbFixturesMixin.setUp(self)
        WebPySetupMixin.setUp(self)
#        super(AppSetupMixin, self).setUp()

        # Set the dev flag in Config to False.
        Config.data['dev'] = False

        # Set up the routes
        app = web.application(main.ROUTES, globals())
        SessionHolder.set(web.session.Session(app, web.session.DBStore(self.db, 'web_session')))

        # Finally, create a test app
        self.app = TestApp(app.wsgifunc())

        class ObjectDict (dict):
            def __getattr__(self, key):
                if key in self:
                    return self[key]
                else:
                    raise AttributeError(key)

            def __setattr__(self, key, value):
                self[key] = value
                return value

        self.session = ObjectDict()
        self.session.session_id = 1

        self.__real_get_session = SessionHolder.get_session
        SessionHolder.get_session = Mock(return_value=self.session)
 def setUp(self):
     # HACK: We kept getting db.printing inexplicably set to True, so patch
     # it to be False here.
     _real_db_execute = web.db.DB._db_execute
     def _db_execute(self, cur, sql_query):
         self.printing = False
         return _real_db_execute(self, cur, sql_query)
     web.db.DB._db_execute = _db_execute
         
     # Set the dev flag in Config to False.
     Config.load()
     Config.data['dev'] = False
     
     # Set the debug flag to true, despite what is in the config file
     web.config.debug = False
     web.config.session_parameters['cookie_name'] = 'gam'
     
     # TODO: Clean up this initialization
     web.ctx.method = ''
     web.ctx.path = ''
     import StringIO
     web.ctx.env = {'wsgi.input': StringIO.StringIO(),
                    'REQUEST_METHOD': ''}
     
     # Set up the routes
     app = web.application(main.ROUTES, globals())
     
     # Grab a database connection
     self.db = main.sessionDB()
     
     # Initialize the session holder (I don't know what that is yet)
     #main.SessionHolder.set(web.session.Session(app, web.session.DBStore(db, 'web_session')))
     
     # Finally, create a test app
     self.app = TestApp(app.wsgifunc())
Exemple #3
0
    def run(self):
        urls = (
                '/', 'Index',
                '/favicon.ico', 'Favicon',
                '/bokken/file/dump', 'FileDump',
                '/bokken/file/exports', 'FileExports',
                '/bokken/file/functions', 'FileFunctions',
                '/bokken/file/imports', 'FileImports',
                '/bokken/file/name', 'FileName',
                '/bokken/file/sections', 'FileSections',
               )

        self.http = web.application(urls, globals())
        web.httpserver.runsimple(self.http.wsgifunc(), self.http, (self.bind_address, self.port))
Exemple #4
0
	def start(self):
		logging.info('---> Logger Initialized')
		logging.critical("---> VoxPop Producer started!")
		web.debug = True
		app = web.application(ROUTES, globals(), True)
		logging.critical("---> DB: "+str(voxpop.VPE.get_db()))
		logging.critical("---> GeoDB: "+str(voxpop.VPE.get_geodb()))
		logging.critical("---> CouchDB Connected to DB: " + voxpop.VPE.get_db().connected_to())
		logging.critical("---> Memcache: "+str(voxpop.VPE.get_memcache()))
		logging.critical("---> ITEMS: "+str(voxpop.VPE.get_items(cache_worker=self.cache_worker)))
		logging.critical("---> NYT Scraper: "+str(voxpop.VPE.get_scraper()))
		#logging.critical("---> Classifier: "+str(voxpop.VPE.get_classifier()))
		cacheWorker = vp_workers.VoxPopWorker({'tube':self.cache_worker})
		cacheWorker.setDaemon(False)
		cacheWorker.start()
		app.run()
Exemple #5
0
    def run(self):
        urls = (
            '/',
            'Index',
            '/favicon.ico',
            'Favicon',
            '/bokken/file/dump',
            'FileDump',
            '/bokken/file/exports',
            'FileExports',
            '/bokken/file/functions',
            'FileFunctions',
            '/bokken/file/imports',
            'FileImports',
            '/bokken/file/name',
            'FileName',
            '/bokken/file/sections',
            'FileSections',
        )

        self.http = web.application(urls, globals())
        web.httpserver.runsimple(self.http.wsgifunc(), self.http,
                                 (self.bind_address, self.port))
Exemple #6
0
    def setUp(self):
        # HACK: We kept getting db.printing inexplicably set to True, so patch
        # it to be False here.
        _real_db_execute = web.db.DB._db_execute

        def _db_execute(self, cur, sql_query):
            self.printing = False
            return _real_db_execute(self, cur, sql_query)

        web.db.DB._db_execute = _db_execute

        # Set the dev flag in Config to False.
        Config.load()
        Config.data['dev'] = False

        # Set the debug flag to true, despite what is in the config file
        web.config.debug = False
        web.config.session_parameters['cookie_name'] = 'gam'

        # TODO: Clean up this initialization
        web.ctx.method = ''
        web.ctx.path = ''
        import StringIO
        web.ctx.env = {'wsgi.input': StringIO.StringIO(), 'REQUEST_METHOD': ''}

        # Set up the routes
        app = web.application(main.ROUTES, globals())

        # Grab a database connection
        self.db = main.sessionDB()

        # Initialize the session holder (I don't know what that is yet)
        #main.SessionHolder.set(web.session.Session(app, web.session.DBStore(db, 'web_session')))

        # Finally, create a test app
        self.app = TestApp(app.wsgifunc())
Exemple #7
0
    def POST(self):
        name = web.input().name
        ip = web.ctx.ip
        cookieName_identity = 'identity'
        cookieName_name = 'name'
        identity = web.cookies().get(cookieName_identity)
        browserId = ''
        user = None

        if identity:
            user = Identity.Update(identity, name, ip, browserId)
        if not user:
            user = Identity.Put(name, ip, browserId)

        web.setcookie(cookieName_identity, user.Id, _cookie_expire_time)
        web.setcookie(cookieName_name, user.DisplayName, _cookie_expire_time)

        return user.Id


def notfound():
    return web.notfound(render.index())


app = web.application(urls, globals())
app.notfound = notfound
app = app.gaerun()

#if __name__ == '__main__':
#    app.gaerun()
Exemple #8
0
def daemonize():
    """Become a daemon"""
    if os.fork():
        os._exit(0)

    # decouple from parent environment
    os.setsid()
    os.umask(0)

    sys.stdin.close()
    sys.stdout = NullDevice()
    sys.stderr = NullDevice()


app = web.application(urls, globals())
search = search.SearchThread()

if __name__ == '__main__':
    port = settings.get("Anorak", "port")
    optionParser = OptionParser()
    optionParser.add_option('-d', '--daemon', action = "store_true",
                 dest = 'daemon', help = "Run the server as a daemon")
    options, args = optionParser.parse_args()
    if options.daemon:
        if not sys.platform == 'win32':
            daemonize()
        else:
            print "Daemon mode not supported under Windows, starting normally."
    sys.argv[1:] = [port]
    search.start()
Exemple #9
0
            log.info(e)

    # Add blitz.io route.  We put into new var because of an odd behaviors
    # where a changed ROUTES is not handled correctly.
    try:
        if Config.get('blitz_io').get('route') and Config.get('app_env') != 'live':
            blitz_route = r'/%s/?([^/.]*)' % Config.get('blitz_io').get('route')
            NEW_ROUTES = (blitz_route, 'controllers.blitz.Blitz') + ROUTES
        else:
            NEW_ROUTES = ROUTES
    except KeyError:
        NEW_ROUTES = ROUTES
    except Exception, e:
        log.error(e)

    app = web.application(NEW_ROUTES, globals())
    db = sessionDB()
    SessionHolder.set(web.session.Session(app, web.session.DBStore(db, 'web_session')))

    # WARNING:
    #    Adding new processors may cause duplicate insertions!
    #    The basic_processor has been disabled for this reason
    # app.add_processor(basic_processor)
    
    # Load SQLAlchemy
    app.add_processor(load_sqla)

    return app

# Main logic for the CBU application.  Does some basic configuration,
# then starts the web.py application.
Exemple #10
0
            raise Exception("ERROR: No valid email engine has been configured. Please check your configurations")
        except Exception, e:
            log.info(e)

    # Add blitz.io route.  We put into new var because of an odd behaviors
    # where a changed ROUTES is not handled correctly.
    try:
        if Config.get('blitz_io').get('route') and Config.get('app_env') != 'live':
            blitz_route = r'/%s/?([^/.]*)' % Config.get('blitz_io').get('route')
            NEW_ROUTES = (blitz_route, 'controllers.blitz.Blitz') + ROUTES
        else:
            NEW_ROUTES = ROUTES
    except KeyError:
        NEW_ROUTES = ROUTES

    app = web.application(NEW_ROUTES, globals())
    db = sessionDB()
    SessionHolder.set(web.session.Session(app, web.session.DBStore(db, 'web_session')))

    # Load SQLAlchemy
    app.add_processor(load_sqla)

    # Finally, run the web.py app!    
    app.run()

# Main logic for the CBU application.  Does some basic configuration,
# then starts the web.py application.
if __name__ == "__main__":
    try:
        main()
    except Exception, e: