本文整理匯總了Python中xpra.dotxpra.DotXpra類的典型用法代碼示例。如果您正苦於以下問題:Python DotXpra類的具體用法?Python DotXpra怎麽用?Python DotXpra使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DotXpra類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_stop
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")
示例2: client_sock
def client_sock(parser, opts, display_name):
if display_name.startswith("ssh:"):
sshspec = display_name[len("ssh:"):]
if ":" in sshspec:
(host, display) = sshspec.split(":", 1)
display_args = [":" + display]
else:
host = sshspec
display_args = []
(a, b) = socket.socketpair()
if opts.remote_xpra is not None:
remote_xpra = opts.remote_xpra.split()
else:
remote_xpra = ["$HOME/.xpra/run-xpra"]
p = subprocess.Popen(["ssh", host, "-e", "none"]
+ remote_xpra + ["_proxy"] + display_args,
stdin=b.fileno(), stdout=b.fileno(),
bufsize=0)
return a, False
elif display_name.startswith(":"):
sockdir = DotXpra()
sock = socket.socket(socket.AF_UNIX)
sock.connect(sockdir.socket_path(display_name))
return sock, True
elif display_name.startswith("tcp:"):
host_spec = display_name[4:]
(host, port) = host_spec.split(":", 1)
if host == "":
host = "127.0.0.1"
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, int(port)))
return sock, True
else:
parser.error("unknown format for display name")
示例3: run_stop
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"
示例4: __init__
def __init__(self):
dotxpra = DotXpra()
display = os.environ.get("DISPLAY")
from xpra.scripts.config import make_defaults_struct
opts = make_defaults_struct()
target = dotxpra.socket_path(display)
log.info("attempting to connect to socket: %s", target)
sock = socket.socket(socket.AF_UNIX)
sock.connect(target)
conn = SocketConnection(sock, sock.getsockname(), sock.getpeername(), target, "scroll-test")
log.info("successfully created our socket connection: %s", conn)
self.server = ServerMessenger(conn, opts)
self.vscroll_events = maxdeque(1000)
self.hscroll_events = maxdeque(1000)
browser = WebBrowser()
#hook some events:
browser.content_tabs.connect("focus-view-title-changed", self.title_changed)
vscroll_listeners.append(self.vscroll)
hscroll_listeners.append(self.hscroll)
#the things we tune:
self.quality = -1
self.speed = -1
self.encoding = None
self.strict = False
示例5: run_proxy
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
示例6: guess_xpra_display
def guess_xpra_display(socket_dir, socket_dirs):
dotxpra = DotXpra(socket_dir, socket_dirs)
results = dotxpra.sockets()
live = [display for state, display in results if state==DotXpra.LIVE]
if len(live)==0:
raise InitException("no existing xpra servers found")
if len(live)>1:
raise InitException("too many existing xpra servers found, cannot guess which one to use")
return live[0]
示例7: get_sessions
def get_sessions(self):
uid = self.get_uid()
gid = self.get_gid()
try:
sockdir = DotXpra(socket_dir, actual_username=self.username)
results = sockdir.sockets(check_uid=uid)
displays = [display for state, display in results if state==DotXpra.LIVE]
except Exception, e:
log.error("cannot get socker directory for %s: %s", self.username, e)
displays = []
示例8: get_sessions
def get_sessions(self):
uid = self.get_uid()
gid = self.get_gid()
try:
sockdir = DotXpra(socket_dir, socket_dirs, actual_username=self.username)
results = sockdir.sockets(check_uid=uid)
displays = [display for state, display in results if state==DotXpra.LIVE]
except Exception as e:
log.error("Error: cannot get socket directory for '%s':", self.username)
log.error(" %s", e)
displays = []
return uid, gid, displays, {}, {}
示例9: create_control_socket
def create_control_socket(self):
dotxpra = DotXpra(self.socket_dir)
name = "proxy-%s" % os.getpid()
sockpath = dotxpra.norm_make_path(name, dotxpra.sockdir())
state = dotxpra.get_server_state(sockpath)
if state in (DotXpra.LIVE, DotXpra.UNKNOWN):
log.warn("You already have a proxy server running at %s, the control socket will not be created!", sockpath)
return False
try:
sock = create_unix_domain_socket(sockpath, None)
sock.listen(5)
except Exception, e:
log.warn("failed to setup control socket %s: %s", sockpath, e)
return False
示例10: pick_display
def pick_display(parser, opts, extra_args):
if len(extra_args) == 0:
# Pick a default server
sockdir = DotXpra(opts.sockdir or get_default_socket_dir())
servers = sockdir.sockets()
live_servers = [display for (state, display) in servers if state is DotXpra.LIVE]
if len(live_servers) == 0:
parser.error("cannot find a live server to connect to")
elif len(live_servers) == 1:
return parse_display_name(parser, opts, live_servers[0])
else:
parser.error("there are multiple servers running, please specify")
elif len(extra_args) == 1:
return parse_display_name(parser, opts, extra_args[0])
else:
parser.error("too many arguments")
示例11: create_control_socket
def create_control_socket(self):
dotxpra = DotXpra(self.socket_dir)
name = "proxy-%s" % os.getpid()
sockpath = dotxpra.norm_make_path(name, dotxpra.sockdir())
state = dotxpra.get_server_state(sockpath)
if state in (DotXpra.LIVE, DotXpra.UNKNOWN):
log.warn("You already have a proxy server running at %s, the control socket will not be created!", sockpath)
return False
try:
sock = create_unix_domain_socket(sockpath, None, 0o600)
sock.listen(5)
except:
log.warn("failed to setup control socket %s", sockpath, exc_info=True)
return False
self.control_socket = sock
self.control_socket_path = sockpath
log.info("proxy instance now also available using unix domain socket: %s", self.control_socket_path)
return True
示例12: show_final_state
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
示例13: run_list
def run_list(parser, opts, extra_args):
if extra_args:
parser.error("too many arguments for mode")
sockdir = DotXpra()
results = sockdir.sockets()
if not results:
sys.stdout.write("No xpra sessions found\n")
else:
sys.stdout.write("Found the following xpra sessions:\n")
for state, display in results:
sys.stdout.write("\t%s session at %s" % (state, display))
if state is DotXpra.DEAD:
try:
os.unlink(sockdir.socket_path(display))
except OSError:
pass
else:
sys.stdout.write(" (cleaned up)")
sys.stdout.write("\n")
示例14: run_proxy
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
示例15: pick_display
def pick_display(parser, opts, extra_args):
if len(extra_args) == 0:
if not XPRA_LOCAL_SERVERS_SUPPORTED:
parser.error("need to specify a display")
# Pick a default server
sockdir = DotXpra()
servers = sockdir.sockets()
live_servers = [display
for (state, display) in servers
if state is DotXpra.LIVE]
if len(live_servers) == 0:
parser.error("cannot find a live server to connect to")
elif len(live_servers) == 1:
return parse_display_name(parser, opts, live_servers[0])
else:
parser.error("there are multiple servers running, please specify")
elif len(extra_args) == 1:
return parse_display_name(parser, opts, extra_args[0])
else:
parser.error("too many arguments")