Ejemplo n.º 1
0
def make_app():
    application = URLDispatcher()
    js_app = DirectoryApp(os.path.join(here, 'static/js'))
    css_app = DirectoryApp(os.path.join(here, 'static/css'))
    img_app = DirectoryApp(os.path.join(here, 'static/img'))

    application.add_url('js', '/js/*', js_app)
    application.add_url('css', '/css/*', css_app)
    application.add_url('img', '/img/*', img_app)
    application.add_url('page', '/{page_name}', page_view)
    application.add_url('page_edit', '/{page_name}/edit', page_edit)
    application.add_url('top', '/', HTTPFound(location='FrontPage'))
    return application
Ejemplo n.º 2
0
def wsgi_factory():  # pragma: no cover
    morepath.autoscan()

    if os.getenv("RUN_ENV") == "production":
        ProductionApp.commit()
        app = ProductionApp()
    elif os.getenv("RUN_ENV") == "test":
        TestApp.commit()
        app = TestApp()
    else:
        App.commit()
        app = App()

    index = FileApp("build/index.html")
    static = DirectoryApp("build", index_page=None)

    setup_db(app)

    @webob.dec.wsgify
    def morepath_with_static_absorb(request):
        popped = request.path_info_pop()
        if popped == "api":
            return request.get_response(app)
        elif popped == "static":
            return request.get_response(static)
        else:
            return request.get_response(index)

    return morepath_with_static_absorb
Ejemplo n.º 3
0
def make_staticdir(global_conf, path, index_page='index.html',
                   hide_index_with_redirect=False):
    """
    Return a WSGI application that serves a directory (configured
    with path)
    """
    return DirectoryApp(path=path, index_page='index.html',
                        hide_index_with_redirect=False)
Ejemplo n.º 4
0
def main():
    from paste import httpserver
    from paste.cascade import Cascade
    from webob.static import DirectoryApp, FileApp

# Create a cascade that looks for static files first, then tries the webapp
    static_app = DirectoryApp("static")
    fullapp = Cascade([static_app, app])
    httpserver.serve(fullapp, host='localhost', port='8070')
Ejemplo n.º 5
0
    def register_statics(self, module_name, plugged):
        if plugged['modules'][module_name]['statics'] is None:
            statics_app = DirectoryApp(self.public_path)

            static_middlewares = self.options.get('static_middlewares', [])
            for middleware in static_middlewares:
                statics_app = middleware(statics_app, self.public_path)

            plugged['modules'][module_name]['statics'] = statics_app
Ejemplo n.º 6
0
    def __init__(self, req, link, data, **config):
        super(NMaaS_Network_Controller_RESTAPI,
              self).__init__(req, link, data, **config)
        self.nmaas_network_controller_app = data[
            nmaas_network_controller_instance_name]

        path = "%s/html/" % PATH
        print path
        self.static_app = DirectoryApp(path)
Ejemplo n.º 7
0
    def __init__(self, req, link, data, **config):
        super(NMaaS_RESTAPI, self).__init__(req, link, data, **config)
        self.nmaas_network_controller_app = data[
            nmaas_network_controller_instance_name]

        path = "%s/html/" % PATH
        print path
        self.static_app = DirectoryApp(path)
        self.nmaas = self.nmaas_network_controller_app
        self.log = l.getLogger(self.__class__.__name__, self.nmaas.debug_level)
Ejemplo n.º 8
0
class StaticsController(TGController):
    _directory_app = DirectoryApp(STATICS_PATH)

    @expose()
    def _default(self, *args):
        new_req = request.copy()
        to_pop = len(new_req.path_info.strip('/').split('/')) - len(args)
        for i in range(to_pop):
            new_req.path_info_pop()
        return new_req.get_response(self._directory_app)
Ejemplo n.º 9
0
 def add_static_route(self, route, static_dir):
     """
     Add a static directory as a route
     """
     if route not in self.static_routes:
         static_path = AppLocation.get_section_data_path('remotes') / static_dir
         if not static_path.exists():
             log.error('Static path "%s" does not exist. Skipping creating static route/', static_path)
             return
         self.static_routes[route] = DirectoryApp(str(static_path.resolve()))
Ejemplo n.º 10
0
def application():
    """TODO"""

    mount_points = {
        'index': PREFFIX,
        'assets': '/'.join([PREFFIX, 'assets']),
        'packages':  '/'.join([PREFFIX, 'packages']),
    }

    paths = {
        'asssets': ASSETS_PATH,
        'packages': PACKAGES_PATH,
        'templates': TEMPLATES_PATH
    }

    index = Index(paths['templates'])

    filters = {
        # filter packages by extension
        'packages': re.compile(
            r'\.({})$'.format(PACKAGES_EXT.replace('.', r'\.')), re.I),
        # filter static files by extension
        'assets': re.compile(
            r'\.({})$'.format(ASSETS_EXT.replace('.', r'\.')), re.I),
    }

    handlers = {
        'index': FancyCollectionHandler(index, mount_points, paths),
        'packages': filter_path(  # pylint: disable=no-value-for-parameter
            DirectoryApp(paths['packages'], index_page=None),
            filters['packages']),
        'assets': filter_path(  # pylint: disable=no-value-for-parameter
            DirectoryApp(paths['assets'], index_page=None),
            filters['assets']),
    }

    routes = [
        (route, {'GET':  handlers[resource]})
        for resource, route in mount_points.items()
    ]

    return Selector(mappings=routes)
Ejemplo n.º 11
0
    def __init__(self, req, link, data, **config):
        super(GUIServerController, self).__init__(req, link, data, **config)

        #Get reference to Web app to redirect
        path = "%s/html/" % PATH
        self.static_app = DirectoryApp(path)

        #Get reference to Proxy instance
        self.proxy = data['Proxy']

        self.mainapp = data['app']
Ejemplo n.º 12
0
def command_serve(parser, options, ags):
    '''Starts a local server'''

    static_app = DirectoryApp("static", index_page=None)
    
    # Create a cascade that looks for static files first, 
    #  then tries the other apps
    cascade_app = ExceptionMiddleware(Cascade([static_app, fever_app, frontend_app]))
    
    httpd = make_server('localhost', options.port, cascade_app)
    print 'Serving on http://localhost:%s' % options.port
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        print 'Interrupted by user'    
Ejemplo n.º 13
0
def main():
    options, args = parser.parse_args()
    if options.clear:
        if os.path.exists(options.dir):
            print 'Deleting %s' % options.dir
            shutil.rmtree(options.dir)
    from cutout.sync import Application
    db_app = Application(dir=options.dir, include_syncclient=True)
    from webob.static import DirectoryApp
    from paste.urlmap import URLMap
    map = URLMap()
    map['/'] = DirectoryApp(os.path.join(here, 'cutout', 'tests',
                                         'syncclient'))
    map['/db'] = TestAuthMiddleware(db_app)
    from paste.httpserver import serve
    serve(map, host=options.host, port=int(options.port))
Ejemplo n.º 14
0
 def command_serve(self, options, args):
     '''Starts a local server'''
 
     static_app = DirectoryApp("static", index_page=None)
     
     # Create a cascade that looks for static files first, 
     #  then tries the other apps
     cascade_app = ExceptionMiddleware(cascade.Cascade([static_app, fever.setup_app(), frontend.setup_app()]))
     
     address = '0.0.0.0' if options.allow_remote_access else 'localhost'        
     httpd = make_server(address, options.port, cascade_app)
     print 'Serving on http://%s:%s' % (address, options.port)
     try:
         httpd.serve_forever()
     except KeyboardInterrupt:
         print 'Interrupted by user'            
Ejemplo n.º 15
0
def main():
    options, args = parser.parse_args()
    if options.clear:
        if os.path.exists(options.dir):
            print 'Deleting %s' % options.dir
            shutil.rmtree(options.dir)
    mapper = URLMap()
    for arg in args:
        if '=' in arg:
            path, dir = arg.split('=', 1)
        else:
            path, dir = '/', arg
        mapper[path] = DirectoryApp(dir)
    from cutout.sync import Application
    db_app = Application(dir=options.dir, include_syncclient=True)
    mapper['/sync'] = db_app
    serve(mapper, host=options.host, port=int(options.port))
Ejemplo n.º 16
0
def run():  # pragma: no cover
    morepath.autoscan()

    index = FileApp('static/index.html')
    static = DirectoryApp('static')
    app = App()

    @webob.dec.wsgify
    def morepath_with_static_absorb(request):
        popped = request.path_info_pop()
        if popped == 'api':
            return request.get_response(app)
        elif popped == 'static':
            return request.get_response(static)
        else:
            return request.get_response(index)

    morepath.run(morepath_with_static_absorb)
Ejemplo n.º 17
0
    def __call__(self, req):
        if req.path_info_peek() != "static":
            return req.get_response(self.app)

        # strip "/static"
        req.path_info_pop()

        # statically serve the directory
        if isinstance(self.static, string_types):
            return req.get_response(DirectoryApp(self.static))

        # otherwise, load resource from package
        package, resource_path = self.static
        resource = os.path.join(resource_path, *req.path_info.split('/'))
        if not pkg_resources.resource_exists(package, resource):
            return HTTPNotFound(req.path_info)

        content_type, content_encoding = mimetypes.guess_type(resource)
        return Response(body=pkg_resources.resource_string(package, resource),
                        content_type=content_type,
                        content_encoding=content_encoding)
Ejemplo n.º 18
0
def server():
    graphql = graphql_wsgi(StarWarsSchema)
    static = DirectoryApp('build', index_page=None)
    index = FileApp('index.html')
    graphiql = FileApp('graphiql.html')

    @wsgify
    def mount_graphql(request):
        if request.path_info_peek() == '':
            return request.get_response(index)
        if request.path_info_peek() == 'graphiql':
            return request.get_response(graphiql)
        popped = request.path_info_pop()
        if popped == 'graphql':
            return request.get_response(graphql)
        elif popped == 'static':
            return request.get_response(static)
        raise HTTPNotFound()

    server = make_server('127.0.0.1', 5000, mount_graphql)
    print "Python GraphQL server running on http://127.0.0.1:5000/graphql"
    print "React with Relay UI available on http://127.0.0.1:5000"
    server.serve_forever()
Ejemplo n.º 19
0
    def __init__(self, req, link, data, **config):
        super(WSController, self).__init__(req, link, data, **config)
        self.main_app = data[main_app_instance_name]

        path = "%s/html/" % PATH
        self.static_app = DirectoryApp(path)
Ejemplo n.º 20
0
 def __init__(self, req, link, data, **config):
     super(GUIServerController, self).__init__(req, link, data, **config)
     path = "%s/html/" % PATH
     self.static_app = DirectoryApp(path)
Ejemplo n.º 21
0
 def __init__(self, req, link, data, **config):
     super(NetworkMonitorController, self).__init__(req, link, data,
                                                    **config)
     path = "%s/gui/" % PATH
     self.static_app = DirectoryApp(path)
     self.multipath_app = data['multipath_app']
Ejemplo n.º 22
0
 def register_statics(self, module_name, plugged):
     if plugged['modules'][module_name]['statics'] is None:
         plugged['modules'][module_name]['statics'] = DirectoryApp(
             self.public_path)
Ejemplo n.º 23
0
 def __init__(self, req, link, data, **config):
     super(PortStatsController, self).__init__(req, link, data, **config)
     self.port_stats_app = data['port_stats_app']
     self.static_app = DirectoryApp(os.path.dirname(__file__) + '/public/')
Ejemplo n.º 24
0
def main():
  static_app = DirectoryApp(".", index_page=None)

  # Create a cascade that looks for static files first, then tries the webapp
  app = Cascade([static_app, web_app])
  httpserver.serve(app, host='127.0.0.1', port='8080')
Ejemplo n.º 25
0
from webob.static import DirectoryApp

app = DirectoryApp(".")
Ejemplo n.º 26
0
 def __init__(self, req, link, data, **config):
     super(GUIServerController, self).__init__(req, link, data, **config)
     path = '%s/html/' % os.path.dirname(__file__)
     self.static_app = DirectoryApp(path)
Ejemplo n.º 27
0
 def __init__(self, req, link, data, **config):
     super(HaecController, self).__init__(req, link, data, **config)
     self.haec_api_app = data['haec_api_app']
     path = "%s/html/" % PATH
     self.static_app = DirectoryApp(path)
Ejemplo n.º 28
0
from wsgiref.simple_server import make_server
from webob.dec import wsgify
from webob.static import DirectoryApp
import urlparse
import imp
import os

path_httpd_root = ""

# serve files for /
path_httpd_root = os.path.abspath(path_httpd_root)
directory_root_app = DirectoryApp(path_httpd_root)
# serve files for /_webhdf
path_test = os.path.dirname(os.path.abspath(__file__))
path_webhdf = os.path.normpath(os.path.join(path_test, "..", "webhdf"))
directory_webhdf_app = DirectoryApp(path_webhdf)
# serve webhdf application
webhdf = imp.load_source("webhdf", os.path.join(path_webhdf, "webhdf.wsgi"))
webhdf.root_local = path_httpd_root
webhdf.url_webhdf = "/_webhdf/webhdf.wsgi"
webhdf_app = webhdf.application

# main application
@wsgify
def application(req):
    path_url = req.path_info
    path_local = os.path.normpath(os.path.join(path_httpd_root, req.path_info.lstrip('/')))
    if path_url == webhdf.url_webhdf:
        return webhdf_app
    elif path_url.startswith("/_webhdf"):
        req.path_info = path_url[len("/_webhdf"):]
Ejemplo n.º 29
0
 def front_end(self):
     """
     All of the single-page application assets are delivered using
     WebOb's DirectoryApp.
     """
     return DirectoryApp(static_dir)
Ejemplo n.º 30
0
Archivo: rt.py Proyecto: xaviet/repo
 def __init__(self, req, link, data, **config):
     super(exctrl, self).__init__(req, link, data, **config)
     self.static_app = DirectoryApp('%s/html/' % PATH)
     self.exapp = data[ex_instance_name]