예제 #1
0
 def __call__(self, args):
     if sys.version_info >= (3, 0, 0):
         print("yt mapserver is disabled for Python 3.")
         return -1
     ds = args.ds
     if args.axis == 4:
         print("Doesn't work with multiple axes!")
         return
     if args.projection:
         p = ProjectionPlot(ds,
                            args.axis,
                            args.field,
                            weight_field=args.weight)
     else:
         p = SlicePlot(ds, args.axis, args.field)
     from yt.visualization.mapserver.pannable_map import PannableMapServer
     PannableMapServer(p.data_source, args.field)
     import yt.extern.bottle as bottle
     bottle.debug(True)
     bottle_dir = os.path.dirname(bottle.__file__)
     sys.path.append(bottle_dir)
     if args.host is not None:
         colonpl = args.host.find(":")
         if colonpl >= 0:
             port = int(args.host.split(":")[-1])
             args.host = args.host[:colonpl]
         else:
             port = 8080
         bottle.run(server='rocket', host=args.host, port=port)
     else:
         bottle.run(server='rocket')
     sys.path.remove(bottle_dir)
 def __call__(self, args):
     if sys.version_info >= (3,0,0):
         print("yt mapserver is disabled for Python 3.")
         return -1
     ds = args.ds
     if args.axis == 4:
         print("Doesn't work with multiple axes!")
         return
     if args.projection:
         p = ProjectionPlot(ds, args.axis, args.field, weight_field=args.weight)
     else:
         p = SlicePlot(ds, args.axis, args.field)
     from yt.gui.reason.pannable_map import PannableMapServer
     mapper = PannableMapServer(p.data_source, args.field)
     import yt.extern.bottle as bottle
     bottle.debug(True)
     if args.host is not None:
         colonpl = args.host.find(":")
         if colonpl >= 0:
             port = int(args.host.split(":")[-1])
             args.host = args.host[:colonpl]
         else:
             port = 8080
         bottle.run(server='rocket', host=args.host, port=port)
     else:
         bottle.run(server='rocket')
예제 #3
0
def uuid_serve_functions(pre_routed=None,
                         open_browser=False,
                         port=9099,
                         repl=None,
                         token=None):
    if pre_routed == None: pre_routed = route_functions
    debug(mode=True)
    if token is None: token = uuid.uuid1()
    for r in pre_routed:
        args, kwargs, f = pre_routed[r]
        if r[0] == "/": r = r[1:]
        rp = "/%s/%s" % (token, r)
        func_name = getattr(f, 'func_name', str(f))
        print("Routing from %s => %s" % (rp, func_name))
        route(rp, *args, **kwargs)(f)
    for w in route_watchers:
        if not hasattr(w, "_route_prefix"):
            print(
                "WARNING: %s has no _route_prefix attribute.  Not notifying.")
            continue
            w._route_prefix = token
    repl._global_token = token
    repl.activate()
    repl.execution_thread.wait()
    print()
    print()
    print(
        "============================================================================="
    )
    print(
        "============================================================================="
    )
    print("Greetings, and welcome to Reason!")
    print("Your private token is %s ." % token)
    print("DO NOT SHARE THIS TOKEN.")
    print()
    print("Please direct your browser to:")
    print()
    print("     http://localhost:%s/%s/" % (port, token))
    print()
    print(
        "============================================================================="
    )
    print()
    print(
        "If you are currently ssh'd into a remote machine, you should be able")
    print("to create a new SSH tunnel by typing or copy/pasting this text")
    print(
        "verbatim, while waiting to see the 'ssh>' prompt after the first line."
    )
    print()
    print("~C")
    print("-L%s:localhost:%s" % (port, port))
    print()
    print(
        "and then pointing a web browser on your local machine to the above URL."
    )
    print()
    print(
        "============================================================================="
    )
    print(
        "============================================================================="
    )
    print()
    print()
    if open_browser:
        # We do some fancy footwork so that we can open the browser while the
        # server starts up.  I got this from some recipe whose URL escapes me.
        # Thank you, to whoever wrote it!
        def local_browse():
            """Start a browser after waiting for half a second."""
            import webbrowser, threading

            def _local_browse():
                webbrowser.open('http://localhost:%s/%s/' % (port, token))

            thread = threading.Timer(0.5, _local_browse)
            thread.start()

        local_browse()
    try:
        import yt.extern.rocket as rocket
        server_type = YTRocketServer
        log = logging.getLogger('Rocket')
        log.setLevel(logging.WARNING)
        kwargs = {'timeout': 600, 'max_threads': 2}
        if repl is not None:
            repl.server = YTRocketServer.server_info
    except ImportError:
        server_type = server_names.get("wsgiref")
        kwargs = {}
    server = server_type(host='localhost', port=port, **kwargs)
    mylog.info("Starting up the server.")
    run(server=server)
def uuid_serve_functions(pre_routed = None, open_browser=False, port=9099,
                         repl = None, token = None):
    if pre_routed == None: pre_routed = route_functions
    debug(mode=True)
    if token is None: token = uuid.uuid1()
    for r in pre_routed:
        args, kwargs, f = pre_routed[r]
        if r[0] == "/": r = r[1:]
        rp = "/%s/%s" % (token, r)
        func_name = getattr(f, 'func_name', str(f))
        print("Routing from %s => %s" % (rp, func_name))
        route(rp, *args, **kwargs)(f)
    for w in route_watchers:
        if not hasattr(w, "_route_prefix"):
            print("WARNING: %s has no _route_prefix attribute.  Not notifying.")
            continue
            w._route_prefix = token
    repl._global_token = token
    repl.activate()
    repl.execution_thread.wait()
    print()
    print()
    print("=============================================================================")
    print("=============================================================================")
    print("Greetings, and welcome to Reason!")
    print("Your private token is %s ." % token)
    print("DO NOT SHARE THIS TOKEN.")
    print()
    print("Please direct your browser to:")
    print()
    print("     http://localhost:%s/%s/" % (port, token))
    print()
    print("=============================================================================")
    print()
    print("If you are currently ssh'd into a remote machine, you should be able")
    print("to create a new SSH tunnel by typing or copy/pasting this text")
    print("verbatim, while waiting to see the 'ssh>' prompt after the first line.")
    print()
    print("~C")
    print("-L%s:localhost:%s" % (port, port))
    print()
    print("and then pointing a web browser on your local machine to the above URL.")
    print()
    print("=============================================================================")
    print("=============================================================================")
    print()
    print()
    if open_browser:
        # We do some fancy footwork so that we can open the browser while the
        # server starts up.  I got this from some recipe whose URL escapes me.
        # Thank you, to whoever wrote it!
        def local_browse():
            """Start a browser after waiting for half a second."""
            import webbrowser, threading
            def _local_browse():
                webbrowser.open('http://localhost:%s/%s/' % (port, token))
            thread = threading.Timer(0.5, _local_browse)
            thread.start()
        local_browse()
    try:
        import yt.extern.rocket as rocket
        server_type = YTRocketServer
        log = logging.getLogger('Rocket')
        log.setLevel(logging.WARNING)
        kwargs = {'timeout': 600, 'max_threads': 2}
        if repl is not None:
            repl.server = YTRocketServer.server_info
    except ImportError:
        server_type = server_names.get("wsgiref")
        kwargs = {}
    server = server_type(host='localhost', port=port, **kwargs)
    mylog.info("Starting up the server.")
    run(server=server)