예제 #1
0
파일: main.py 프로젝트: rudresh2319/Xpra
def run_proxy(parser, opts, script_file, args, start_server=False):
    from xpra.proxy import XpraProxy
    assert "gtk" not in sys.modules
    if start_server:
        assert len(args) == 1
        display_name = args[0]
        #we must use a subprocess to avoid messing things up - yuk
        cmd = [script_file, "start"] + args
        if opts.start_child and len(opts.start_child) > 0:
            for x in opts.start_child:
                cmd.append("--start-child=%s" % x)
        if opts.exit_with_children:
            cmd.append("--exit-with-children")

        def setsid():
            os.setsid()

        Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=setsid)
        dotxpra = DotXpra()
        start = time.time()
        while dotxpra.server_state(display_name, 1) != DotXpra.LIVE:
            if time.time() - start > 5:
                warn("server failed to start after %.1f seconds - sorry!" %
                     (time.time() - start))
                return
            time.sleep(0.10)
    server_conn = connect_or_fail(pick_display(parser, opts, args))
    app = XpraProxy(
        TwoFileConnection(sys.stdout, sys.stdin, info="stdin/stdout"),
        server_conn)
    signal.signal(signal.SIGINT, app.quit)
    signal.signal(signal.SIGTERM, app.quit)
    app.run()
    return 0
예제 #2
0
def run_stop(parser, opts, extra_args):
    assert "gtk" not in sys.modules
    magic_string = bencode(
        ["hello", {
            "__prerelease_version": xpra.__version__
        }]) + bencode(["shutdown-server"])

    display_desc = pick_display(parser, opts, extra_args)
    conn = connect_or_fail(display_desc)
    while magic_string:
        magic_string = magic_string[conn.write(magic_string):]
    while conn.read(4096):
        pass
    if display_desc["local"]:
        sockdir = DotXpra()
        for _ in xrange(6):
            final_state = sockdir.server_state(display_desc["display"])
            if final_state is DotXpra.LIVE:
                time.sleep(0.5)
            else:
                break
        if final_state is DotXpra.DEAD:
            print("xpra at %s has exited." % display_desc["display"])
            sys.exit(0)
        elif final_state is DotXpra.UNKNOWN:
            print("How odd... I'm not sure what's going on with xpra at %s" %
                  display_desc["display"])
            sys.exit(1)
        elif final_state is DotXpra.LIVE:
            print("Failed to shutdown xpra at %s" % display_desc["display"])
            sys.exit(1)
        else:
            assert False
    else:
        print("Sent shutdown command")
예제 #3
0
파일: main.py 프로젝트: svn2github/Xpra
def run_stop(parser, opts, extra_args):
    assert "gtk" not in sys.modules
    magic_string = bencode(["hello", {"__prerelease_version": xpra.__version__}]) + bencode(["shutdown-server"])

    display_desc = pick_display(parser, opts, extra_args)
    conn = connect_or_fail(display_desc)
    while magic_string:
        magic_string = magic_string[conn.write(magic_string):]
    while conn.read(4096):
        pass
    if display_desc["local"]:
        sockdir = DotXpra(opts.sockdir)
        for _ in xrange(6):
            final_state = sockdir.server_state(display_desc["display"])
            if final_state is DotXpra.LIVE:
                break
            time.sleep(0.5)
        if final_state is DotXpra.DEAD:
            print("xpra at %s has exited." % display_desc["display"])
            sys.exit(0)
        elif final_state is DotXpra.UNKNOWN:
            print("How odd... I'm not sure what's going on with xpra at %s"
                   % display_desc["display"])
            sys.exit(1)
        elif final_state is DotXpra.LIVE:
            print("Failed to shutdown xpra at %s" % display_desc["display"])
            sys.exit(1)
        else:
            assert False, "invalid state: %s" % final_state
    else:
        print("Sent shutdown command")
예제 #4
0
파일: main.py 프로젝트: svn2github/Xpra
def run_proxy(parser, opts, script_file, args, start_server=False):
    from xpra.proxy import XpraProxy
    assert "gtk" not in sys.modules
    if start_server:
        assert len(args)==1
        display_name = args[0]
        #we must use a subprocess to avoid messing things up - yuk
        cmd = [script_file, "start"]+args
        if opts.start_child and len(opts.start_child)>0:
            for x in opts.start_child:
                cmd.append("--start-child=%s" % x)
        if opts.exit_with_children:
            cmd.append("--exit-with-children")
        def setsid():
            os.setsid()
        Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=setsid)
        dotxpra = DotXpra()
        start = time.time()
        while dotxpra.server_state(display_name, 1)!=DotXpra.LIVE:
            if time.time()-start>5:
                warn("server failed to start after %.1f seconds - sorry!" % (time.time()-start))
                return
            time.sleep(0.10)
    server_conn = connect_or_fail(pick_display(parser, opts, args))
    app = XpraProxy(TwoFileConnection(sys.stdout, sys.stdin, info="stdin/stdout"), server_conn)
    signal.signal(signal.SIGINT, app.quit)
    signal.signal(signal.SIGTERM, app.quit)
    app.run()
    return  0
예제 #5
0
파일: main.py 프로젝트: dmgerman/hacking
def run_stop(parser, opts, extra_args):
    magic_string = bencode(["hello", []]) + bencode(["shutdown-server"])

    display_name = pick_display(parser, extra_args)
    sock, local = client_sock(parser, opts, display_name)
    sock.sendall(magic_string)
    while sock.recv(4096):
        pass
    if local:
        sockdir = DotXpra()
        for i in xrange(6):
            final_state = sockdir.server_state(display_name)
            if final_state is DotXpra.LIVE:
                time.sleep(0.5)
            else:
                break
        if final_state is DotXpra.DEAD:
            print "xpra at %s has exited." % display_name
            sys.exit(0)
        elif final_state is DotXpra.UNKNOWN:
            print ("How odd... I'm not sure what's going on with xpra at %s"
                   % display_name)
            sys.exit(1)
        elif final_state is DotXpra.LIVE:
            print "Failed to shutdown xpra at %s" % display_name
            sys.exit(1)
        else:
            assert False
    else:
        print "Sent shutdown command"
예제 #6
0
파일: main.py 프로젝트: rudresh2319/Xpra
def run_list(parser, opts, extra_args):
    assert "gtk" not in sys.modules
    if extra_args:
        parser.error("too many arguments for mode")
    sockdir = DotXpra(opts.socket_dir)
    results = sockdir.sockets()
    if not results:
        sys.stdout.write("No xpra sessions found\n")
        return 1
    sys.stdout.write("Found the following xpra sessions:\n")
    for state, display in results:
        may_cleanup_socket(sockdir, state, display)
    #now, re-probe the "unknown" ones:
    unknown = [
        display for state, display in results if state == DotXpra.UNKNOWN
    ]
    if len(unknown) > 0:
        sys.stdout.write("Re-probing unknown sessions: %s\n" %
                         (", ".join(unknown)))
    counter = 0
    while len(unknown) > 0 and counter < 5:
        time.sleep(1)
        counter += 1
        probe_list = list(unknown)
        unknown = []
        for display in probe_list:
            state = sockdir.server_state(display)
            if state is DotXpra.DEAD:
                may_cleanup_socket(sockdir, state, display)
            elif state is DotXpra.UNKNOWN:
                unknown.append(display)
            else:
                sys.stdout.write("\t%s session at %s\n" % (state, display))
    #now cleanup those still unknown:
    clean_states = [DotXpra.DEAD, DotXpra.UNKNOWN]
    for display in unknown:
        state = sockdir.server_state(display)
        may_cleanup_socket(sockdir, state, display, clean_states=clean_states)
    return 0
예제 #7
0
파일: main.py 프로젝트: svn2github/Xpra
def run_list(parser, opts, extra_args):
    assert "gtk" not in sys.modules
    if extra_args:
        parser.error("too many arguments for mode")
    sockdir = DotXpra(opts.socket_dir)
    results = sockdir.sockets()
    if not results:
        sys.stdout.write("No xpra sessions found\n")
        return  1
    sys.stdout.write("Found the following xpra sessions:\n")
    for state, display in results:
        may_cleanup_socket(sockdir, state, display)
    #now, re-probe the "unknown" ones:
    unknown = [display for state, display in results if state==DotXpra.UNKNOWN]
    if len(unknown)>0:
        sys.stdout.write("Re-probing unknown sessions: %s\n" % (", ".join(unknown)))
    counter = 0
    while len(unknown)>0 and counter<5:
        time.sleep(1)
        counter += 1
        probe_list = list(unknown)
        unknown = []
        for display in probe_list:
            state = sockdir.server_state(display)
            if state is DotXpra.DEAD:
                may_cleanup_socket(sockdir, state, display)
            elif state is DotXpra.UNKNOWN:
                unknown.append(display)
            else:
                sys.stdout.write("\t%s session at %s\n" % (state, display))
    #now cleanup those still unknown:
    clean_states = [DotXpra.DEAD, DotXpra.UNKNOWN]
    for display in unknown:
        state = sockdir.server_state(display)
        may_cleanup_socket(sockdir, state, display, clean_states=clean_states)
    return 0
예제 #8
0
파일: main.py 프로젝트: svn2github/Xpra
 def show_final_state(display):
     sockdir = DotXpra(opts.sockdir)
     for _ in range(6):
         final_state = sockdir.server_state(display)
         if final_state is DotXpra.LIVE:
             time.sleep(0.5)
     if final_state is DotXpra.DEAD:
         print("xpra at %s has exited." % display)
         return 0
     elif final_state is DotXpra.UNKNOWN:
         print("How odd... I'm not sure what's going on with xpra at %s" % display)
         return 1
     elif final_state is DotXpra.LIVE:
         print("Failed to shutdown xpra at %s" % display)
         return 1
     else:
         assert False, "invalid state: %s" % final_state
         return 1
예제 #9
0
 def show_final_state(display):
     sockdir = DotXpra(opts.sockdir)
     for _ in range(6):
         final_state = sockdir.server_state(display)
         if final_state is DotXpra.LIVE:
             time.sleep(0.5)
     if final_state is DotXpra.DEAD:
         print("xpra at %s has exited." % display)
         return 0
     elif final_state is DotXpra.UNKNOWN:
         print("How odd... I'm not sure what's going on with xpra at %s" % display)
         return 1
     elif final_state is DotXpra.LIVE:
         print("Failed to shutdown xpra at %s" % display)
         return 1
     else:
         assert False, "invalid state: %s" % final_state
         return 1
예제 #10
0
def run_proxy(parser, opts, script_file, args, mode):
    from xpra.server.proxy import XpraProxy
    assert "gtk" not in sys.modules
    if mode in ("_proxy_start", "_shadow_start"):
        #we must use a subprocess to avoid messing things up - yuk
        cmd = [script_file]
        if mode=="_proxy_start":
            cmd.append("start")
            assert len(args)==1, "proxy/shadow-start: expected 1 argument but got %s" % len(args)
            display_name = args[0]
        else:
            assert mode=="_shadow_start"
            cmd.append("shadow")
            if len(args)==1:
                #display_name was provided:
                display_name = args[0]
            else:
                display_name = guess_X11_display()
        cmd += args
        if opts.start_child and len(opts.start_child)>0:
            for x in opts.start_child:
                cmd.append("--start-child=%s" % x)
        if opts.exit_with_children:
            cmd.append("--exit-with-children")
        if opts.exit_with_client or mode=="_shadow_start":
            cmd.append("--exit-with-client")
        def setsid():
            os.setsid()
        Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=setsid)
        dotxpra = DotXpra()
        start = time.time()
        while dotxpra.server_state(display_name, 1)!=DotXpra.LIVE:
            if time.time()-start>5:
                warn("server failed to start after %.1f seconds - sorry!" % (time.time()-start))
                return
            time.sleep(0.10)
    server_conn = connect_or_fail(pick_display(parser, opts, args))
    app = XpraProxy(TwoFileConnection(sys.stdout, sys.stdin, info="stdin/stdout"), server_conn)
    signal.signal(signal.SIGINT, app.quit)
    signal.signal(signal.SIGTERM, app.quit)
    app.run()
    return  0