def setUp(self): middleware = [] self.logger = logging.getLogger('restapi') urls = karesansui.urls.urls app = web.application(urls, globals(), autoreload=False) from karesansui.app import load_sqlalchemy_karesansui,load_sqlalchemy_pysilhouette app.add_processor(load_sqlalchemy_karesansui) app.add_processor(load_sqlalchemy_pysilhouette) self.prefix = "" if karesansui.config['application.url.prefix']: mapping = (karesansui.config['application.url.prefix'], app) app = web.subdir_application(mapping) self.prefix = karesansui.config['application.url.prefix'] self.app = TestApp(app.wsgifunc(*middleware)) self.headers = {} if username != None and password != None: from base64 import b64encode base64string =b64encode("%s:%s" % (username, password)) self.headers = {"Authorization": "Basic %s" % base64string} return True
def wsgi_application(): """ Application factory to create, configure, and return a WSGI application using the web.py framework and custom Pulp middleware. @return: wsgi application callable """ application = web.subdir_application(URLS).wsgifunc() stack_components = [application, PostponedOperationMiddleware, ExceptionHandlerMiddleware] stack = reduce(lambda a, m: m(a), stack_components) # The following intentionally don't raise the exception. The logging writes # to both error_log and pulp.log. Raising the exception caused it to be # logged twice to error_log, which was annoying. The Pulp server still # fails to start (I can't even log in), and on attempts to use it the # initialize failure message is logged again. I like that behavior so I # think this approach makes sense. But if there is a compelling reason to # raise the exception, change it; I don't have a strong conviction behind # this approach other than the duplicate logging and the appearance that it # works as desired. # jdob, Nov 21, 2012 try: _initialize_pulp() except initialization.InitializationException, e: logger.fatal('*************************************************************') logger.fatal('The Pulp server failed to start due to the following reasons:') logger.exception(' ' + e.message) logger.fatal('*************************************************************') return
def wsgi_application(): """ Application factory to create, configure, and return a WSGI application using the web.py framework and custom Pulp middleware. @return: wsgi application callable """ application = web.subdir_application(URLS).wsgifunc() stack_components = [ application, PostponedOperationMiddleware, ExceptionHandlerMiddleware ] stack = reduce(lambda a, m: m(a), stack_components) # The following intentionally don't raise the exception. The logging writes # to both error_log and pulp.log. Raising the exception caused it to be # logged twice to error_log, which was annoying. The Pulp server still # fails to start (I can't even log in), and on attempts to use it the # initialize failure message is logged again. I like that behavior so I # think this approach makes sense. But if there is a compelling reason to # raise the exception, change it; I don't have a strong conviction behind # this approach other than the duplicate logging and the appearance that it # works as desired. # jdob, Nov 21, 2012 try: _initialize_pulp() except InitializationException, e: _LOG.fatal( '*************************************************************') _LOG.fatal( 'The Pulp server failed to start due to the following reasons:') _LOG.exception(' ' + e.message) _LOG.fatal( '*************************************************************') return
def setUpClass(cls): PulpServerTests.setUpClass() # The application setup is somewhat time consuming and really only needs # to be done once. We might be able to move it out to a single call for # the entire test suite, but for now I'm seeing performance improvements # by only doing it once per class instead of on every run. # Because our code is a tightly coupled mess, the test config has to be # loaded before we can import application load_test_config() from pulp.server.webservices import application pulp_app = web.subdir_application(application.URLS).wsgifunc() pulp_stack_components = [pulp_app, PostponedOperationMiddleware, ExceptionHandlerMiddleware] pulp_stack = reduce(lambda a, m: m(a), pulp_stack_components) PulpWebserviceTests.TEST_APP = TestApp(pulp_stack) def request_info(key): if key == "REQUEST_URI": key = "PATH_INFO" return web.ctx.environ.get(key, None) PulpWebserviceTests.ORIG_HTTP_REQUEST_INFO = http.request_info http.request_info = request_info base64string = base64.encodestring('%s:%s' % ('ws-user', 'ws-user'))[:-1] PulpWebserviceTests.HEADERS = {'Authorization' : 'Basic %s' % base64string}
def setUpClass(cls): super(PulpWebserviceTests, cls).setUpClass() # The application setup is somewhat time consuming and really only needs # to be done once. We might be able to move it out to a single call for # the entire test suite, but for now I'm seeing performance improvements # by only doing it once per class instead of on every run. # Because our code is a tightly coupled mess, the test config has to be # loaded before we can import application load_test_config() from pulp.server.webservices import application pulp_app = web.subdir_application(application.URLS).wsgifunc() pulp_stack_components = [ pulp_app, PostponedOperationMiddleware, ExceptionHandlerMiddleware ] pulp_stack = reduce(lambda a, m: m(a), pulp_stack_components) PulpWebserviceTests.TEST_APP = TestApp(pulp_stack) def request_info(key): if key == "REQUEST_URI": key = "PATH_INFO" return web.ctx.environ.get(key, None) PulpWebserviceTests.ORIG_HTTP_REQUEST_INFO = http.request_info http.request_info = request_info base64string = base64.encodestring('%s:%s' % ('ws-user', 'ws-user'))[:-1] PulpWebserviceTests.HEADERS = { 'Authorization': 'Basic %s' % base64string }
def setUp(self): middleware = [] self.logger = logging.getLogger('restapi') urls = karesansui.urls.urls app = web.application(urls, globals(), autoreload=False) from karesansui.app import load_sqlalchemy_karesansui, load_sqlalchemy_pysilhouette app.add_processor(load_sqlalchemy_karesansui) app.add_processor(load_sqlalchemy_pysilhouette) self.prefix = "" if karesansui.config['application.url.prefix']: mapping = (karesansui.config['application.url.prefix'], app) app = web.subdir_application(mapping) self.prefix = karesansui.config['application.url.prefix'] self.app = TestApp(app.wsgifunc(*middleware)) self.headers = {} if username != None and password != None: from base64 import b64encode base64string = b64encode("%s:%s" % (username, password)) self.headers = {"Authorization": "Basic %s" % base64string} return True
def main(): """<comment-ja> Web Application 起動処理 </comment-ja> <comment-en> TODO: English Comment </comment-en> """ # logging load karesansui.lib.log.logger.reload_conf(karesansui.config['application.log.config']) if karesansui.lib.log.logger.is_ready() is False: raise karesansui.lib.log.logger.KaresansuiLogError("""Warning!! Logging set initial startup failed. example : Does the log configuration file exist? The present file path : %s """ % karesansui.config['application.log.config']) logger = logging.getLogger('karesansui.app') logger_trace = logging.getLogger('karesansui_trace.app') if not os.popen("ps -eo cmd | grep -e ^libvirtd -e ^/usr/sbin/libvirtd").read(): logger.error('libvirtd not running."/etc/init.d/libvirtd start" Please start.') print >>sys.stderr, '[Error] libvirtd not running."/etc/init.d/libvirtd start" Please start.' sys.exit(1) if web.wsgi._is_dev_mode() is True and env.has_key('FCGI') is False: logger.info('Start Mode [development]') app = web.application(urls, globals(), autoreload=True) app.internalerror = web.debugerror sys.argv = [] # argv clear else: logger.info('Start Mode [fastcgi]') web.config.debug = False app = web.application(urls, globals(), autoreload=False) #sys.argv = [] # argv clear # load processor! # - karesansui database! app.add_processor(load_sqlalchemy_karesansui) logger.info('The load was added. - load_sqlalchemy_karesansui') # - pysilhouette database! app.add_processor(load_sqlalchemy_pysilhouette) logger.info('The load was added. - load_sqlalchemy_pysilhouette') # http://domain/(../..)/hoge if karesansui.config['application.url.prefix']: mapping = (karesansui.config['application.url.prefix'], app) app = web.subdir_application(mapping) try: if (not opts is None) and opts.shell is True: # shell mode!! shell() else: app.run() # Web Application Start! except Exception, e: logger_trace.critical(traceback.format_exc()) print >>sys.stderr, "[ERROR] %s" % str(e.args) print >>sys.stderr, traceback.format_exc() return 1
def wsgi_application(): """ Application factory to create, configure, and return a WSGI application using the web.py framework and custom Pulp middleware. @return: wsgi application callable """ application = web.subdir_application(URLS).wsgifunc() stack_components = [application, PostponedOperationMiddleware, ExceptionHandlerMiddleware] stack = reduce(lambda a, m: m(a), stack_components) _initialize_pulp() return stack
def setUpClass(cls): ServerTests.setUpClass() from pulp.server.webservices import application pulp_app = web.subdir_application(application.URLS).wsgifunc() pulp_stack_components = [ pulp_app, PostponedOperationMiddleware, ExceptionHandlerMiddleware ] pulp_stack = reduce(lambda a, m: m(a), pulp_stack_components) cls.TEST_APP = TestApp(pulp_stack) def request_info(key): if key == "REQUEST_URI": key = "PATH_INFO" return web.ctx.environ.get(key, None) cls.ORIG_HTTP_REQUEST_INFO = http.request_info http.request_info = request_info base64string = base64.encodestring('%s:%s' % cls.USER)[:-1] cls.HEADERS = {'Authorization': 'Basic %s' % base64string}
#!/usr/bin/env python # # yo_receiver # import web from apps import incoming_yo mapping = ( "/incoming_yo/.*", incoming_yo.index, ) web.config.db_printing = True web.config.debug = False if __name__ == "__main__": db = web.database(dbn='sqlite', db='yo_reciever.db') app = web.subdir_application(mapping) app.run()
urls = ( '/feed', feed.feed, '/topic', topic.app, '/link', link.app, '/tagged', tagged.app, '/user', user.app, '/favicon.ico', page.favicon, '/about', page.about, '/contact', page.contact, '/faq', page.faq, '/latest', page.latest, '/', page.index ) app = web.subdir_application(urls) def session_hook(): session = web.session.Session(app, web.session.DiskStore('sessions')) web.ctx.session = session app.add_processor(web.loadhook(session_hook)) app.add_processor(db.load_sqla) if __name__ == "__main__": app.run()
def wsgi_application(): Services.start() application = web.subdir_application(URLS) appfn = application.wsgifunc() return appfn
def main(): """<comment-ja> Web Application 起動処理 </comment-ja> <comment-en> TODO: English Comment </comment-en> """ # logging load karesansui.lib.log.logger.reload_conf( karesansui.config['application.log.config']) if karesansui.lib.log.logger.is_ready() is False: raise karesansui.lib.log.logger.KaresansuiLogError("""Warning!! Logging set initial startup failed. example : Does the log configuration file exist? The present file path : %s """ % karesansui.config['application.log.config']) logger = logging.getLogger('karesansui.app') logger_trace = logging.getLogger('karesansui_trace.app') if not os.popen( "ps -eo cmd | grep -e ^libvirtd -e ^/usr/sbin/libvirtd").read(): logger.error( 'libvirtd not running."/etc/init.d/libvirtd start" Please start.') print >> sys.stderr, '[Error] libvirtd not running."/etc/init.d/libvirtd start" Please start.' sys.exit(1) if web.wsgi._is_dev_mode() is True and env.has_key('FCGI') is False: logger.info('Start Mode [development]') app = web.application(urls, globals(), autoreload=True) app.internalerror = web.debugerror sys.argv = [] # argv clear else: logger.info('Start Mode [fastcgi]') web.config.debug = False app = web.application(urls, globals(), autoreload=False) #sys.argv = [] # argv clear # load processor! # - karesansui database! app.add_processor(load_sqlalchemy_karesansui) logger.info('The load was added. - load_sqlalchemy_karesansui') # - pysilhouette database! app.add_processor(load_sqlalchemy_pysilhouette) logger.info('The load was added. - load_sqlalchemy_pysilhouette') # http://domain/(../..)/hoge if karesansui.config['application.url.prefix']: mapping = (karesansui.config['application.url.prefix'], app) app = web.subdir_application(mapping) try: if (not opts is None) and opts.shell is True: # shell mode!! shell() else: app.run() # Web Application Start! except Exception, e: logger_trace.critical(traceback.format_exc()) print >> sys.stderr, "[ERROR] %s" % str(e.args) print >> sys.stderr, traceback.format_exc() return 1