当前位置: 首页>>代码示例>>Python>>正文


Python DotXpra.dir方法代码示例

本文整理汇总了Python中xpra.dotxpra.DotXpra.dir方法的典型用法代码示例。如果您正苦于以下问题:Python DotXpra.dir方法的具体用法?Python DotXpra.dir怎么用?Python DotXpra.dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xpra.dotxpra.DotXpra的用法示例。


在下文中一共展示了DotXpra.dir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_server

# 需要导入模块: from xpra.dotxpra import DotXpra [as 别名]
# 或者: from xpra.dotxpra.DotXpra import dir [as 别名]
def run_server(parser, opts, mode, xpra_file, extra_args):
    if len(extra_args) != 1:
        parser.error("need exactly 1 extra argument")
    display_name = extra_args.pop(0)

    if opts.exit_with_children and not opts.children:
        print("--exit-with-children specified without any children to spawn; exiting immediately")
        return

    atexit.register(run_cleanups)
    signal.signal(signal.SIGINT, deadly_signal)
    signal.signal(signal.SIGTERM, deadly_signal)

    assert mode in ("start", "upgrade")
    upgrading = (mode == "upgrade")

    dotxpra = DotXpra()

    # This used to be given a display-specific name, but now we give it a
    # single fixed name and if multiple servers are started then the last one
    # will clobber the rest.  This isn't great, but the tradeoff is that it
    # makes it possible to use bare 'ssh:hostname' display names and
    # autodiscover the proper numeric display name when only one xpra server
    # is running on the remote host.  Might need to revisit this later if
    # people run into problems or autodiscovery turns out to be less useful
    # than expected.
    scriptpath = os.path.join(dotxpra.dir(), "run-xpra")

    # Save the starting dir now, because we'll lose track of it when we
    # daemonize:
    starting_dir = os.getcwd()

    clobber = upgrading or opts.use_display
    # Daemonize:
    if opts.daemon:
        try:
            logpath = dotxpra.server_socket_path(display_name, clobber) + ".log"
        except ServerSockInUse:
            parser.error("You already have an xpra server running at %s\n"
                         "  (did you want 'xpra upgrade'?)"
                         % (display_name,))
        sys.stderr.write("Entering daemon mode; "
                         + "any further errors will be reported to:\n"
                         + ("  %s\n" % logpath))
        # Do some work up front, so any errors don't get lost.
        if os.path.exists(logpath):
            os.rename(logpath, logpath + ".old")
        logfd = os.open(logpath, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0666)
        assert logfd > 2
        os.chdir("/")

        if os.fork():
            os._exit(0)
        os.setsid()
        if os.fork():
            os._exit(0)
        close_all_fds(exceptions=[logfd])
        fd0 = os.open("/dev/null", os.O_RDONLY)
        if fd0 != 0:
            os.dup2(fd0, 0)
            os.close(fd0)
        os.dup2(logfd, 1)
        os.dup2(logfd, 2)
        os.close(logfd)
        # Make these line-buffered:
        sys.stdout = os.fdopen(1, "w", 1)
        sys.stderr = os.fdopen(2, "w", 1)

    # Write out a shell-script so that we can start our proxy in a clean
    # environment:
    scriptfile = open(scriptpath, "w")
    # Unix is a little silly sometimes:
    umask = os.umask(0)
    os.umask(umask)
    os.fchmod(scriptfile.fileno(), 0700 & ~umask)
    scriptfile.write(xpra_runner_shell_script(xpra_file, starting_dir))
    scriptfile.close()

    # Do this after writing out the shell script:
    os.environ["DISPLAY"] = display_name

    if not clobber:
        # We need to set up a new server environment
        xauthority = os.environ.get("XAUTHORITY",
                                    os.path.expanduser("~/.Xauthority"))
        xvfb_cmd = opts.xvfb.replace("$XAUTHORITY", xauthority).split()
        xvfb_executable = xvfb_cmd[0]
        xvfb_cmd[0] = "%s-for-Xpra-%s" % (xvfb_executable, display_name)
        try:
            xvfb = subprocess.Popen(xvfb_cmd+[display_name],
                                     executable=xvfb_executable)
        except OSError, e:
            sys.stderr.write("Error starting Xvfb: %s\n" % (e,))
            return
        raw_cookie = os.urandom(16)
        baked_cookie = raw_cookie.encode("hex")
        try:
            code = subprocess.call(["xauth", "add", display_name,
                                "MIT-MAGIC-COOKIE-1", baked_cookie])
            if code != 0:
#.........这里部分代码省略.........
开发者ID:jmesmon,项目名称:xpra,代码行数:103,代码来源:server.py


注:本文中的xpra.dotxpra.DotXpra.dir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。