示例#1
0
文件: paths.py 项目: ljmljz/xpra
def do_get_app_dir():
    from xpra.platform.paths import get_resources_dir
    rsc = get_resources_dir()
    CONTENTS = "/Contents/"
    i = rsc.rfind(CONTENTS)
    if i>0:
        rsc = rsc[:i+len(CONTENTS)]
    debug("get_app_dir()=%s", rsc)
    return rsc  #hope for the best..
示例#2
0
文件: about.py 项目: ljmljz/xpra
def load_license():
    global GPL2
    if GPL2 is None:
        from xpra.platform.paths import get_resources_dir
        gpl2_file = os.path.join(get_resources_dir(), "COPYING")
        if os.path.exists(gpl2_file):
            with open(gpl2_file, mode='rb') as f:
                GPL2 = f.read().decode('latin1')
    return GPL2
示例#3
0
文件: about.py 项目: svn2github/Xpra
def load_license():
	global GPL2
	if GPL2 is None:
		from xpra.platform.paths import get_resources_dir
		gpl2_file = os.path.join(get_resources_dir(), "COPYING")
		if os.path.exists(gpl2_file):
			try:
				f = open(gpl2_file, mode='rb')
				GPL2 = f.read()
			finally:
				if f:
					f.close()
	return GPL2
示例#4
0
文件: about.py 项目: rudresh2319/Xpra
def load_license():
    global GPL2
    if GPL2 is None:
        from xpra.platform.paths import get_resources_dir
        gpl2_file = os.path.join(get_resources_dir(), "COPYING")
        if os.path.exists(gpl2_file):
            try:
                f = open(gpl2_file, mode='rb')
                GPL2 = f.read()
            finally:
                if f:
                    f.close()
    return GPL2
示例#5
0
 def new_stream(self, sound_source, codec):
     if NEW_STREAM_SOUND:
         try:
             from xpra.platform.paths import get_resources_dir
             sample = os.path.join(get_resources_dir(), "bell.wav")
             log("new_stream(%s, %s) sample=%s, exists=%s", sound_source, codec, sample, os.path.exists(sample))
             if os.path.exists(sample):
                 if POSIX:
                     sink = "alsasink"
                 else:
                     sink = "autoaudiosink"
                 cmd = [
                     "gst-launch-1.0", "-q",
                     "filesrc", "location=%s" % sample,
                     "!", "decodebin",
                     "!", "audioconvert",
                     "!", sink]
                 import subprocess
                 proc = subprocess.Popen(cmd)
                 log("Popen(%s)=%s", cmd, proc)
                 from xpra.child_reaper import getChildReaper
                 getChildReaper().add_process(proc, "new-stream-sound", cmd, ignore=True, forget=True)
                 def stop_new_stream_notification():
                     if self.new_stream_timers.pop(proc, None):
                         self.stop_new_stream_notification(proc)
                 timer = self.timeout_add(NEW_STREAM_SOUND_STOP*1000, stop_new_stream_notification)
                 self.new_stream_timers[proc] = timer
         except Exception as e:
             log("new_stream(%s, %s) error playing new stream sound", sound_source, codec, exc_info=True)
             log.error("Error playing new-stream bell sound:")
             log.error(" %s", e)
     log("new_stream(%s, %s)", sound_source, codec)
     if self.sound_source!=sound_source:
         log("dropping new-stream signal (current source=%s, signal source=%s)", self.sound_source, sound_source)
         return
     codec = codec or sound_source.codec
     sound_source.codec = codec
     #tell the client this is the start:
     self.send("sound-data", codec, "",
               {
                "start-of-stream"    : True,
                "codec"              : codec,
                "sequence"           : sound_source.sequence,
                })
     update_av_sync = getattr(self, "update_av_sync_delay_total", None)
     if update_av_sync:
         update_av_sync()  #pylint: disable=not-callable
         #run it again after 10 seconds,
         #by that point the source info will actually be populated:
         from gi.repository import GLib
         GLib.timeout_add(10*1000, update_av_sync)
示例#6
0
 def new_stream(self, sound_source, codec):
     if NEW_STREAM_SOUND:
         try:
             from xpra.platform.paths import get_resources_dir
             sample = os.path.join(get_resources_dir(), "bell.wav")
             log("new_stream(%s, %s) sample=%s, exists=%s", sound_source,
                 codec, sample, os.path.exists(sample))
             if os.path.exists(sample):
                 if POSIX:
                     sink = "alsasink"
                 else:
                     sink = "autoaudiosink"
                 cmd = [
                     "gst-launch-1.0", "-q", "filesrc",
                     "location=%s" % sample, "!", "decodebin", "!",
                     "audioconvert", "!", sink
                 ]
                 import subprocess
                 proc = subprocess.Popen(cmd, close_fds=True)
                 log("Popen(%s)=%s", cmd, proc)
                 from xpra.child_reaper import getChildReaper
                 getChildReaper().add_process(proc,
                                              "new-stream-sound",
                                              cmd,
                                              ignore=True,
                                              forget=True)
         except:
             pass
     log("new_stream(%s, %s)", sound_source, codec)
     if self.sound_source != sound_source:
         log(
             "dropping new-stream signal (current source=%s, signal source=%s)",
             self.sound_source, sound_source)
         return
     codec = codec or sound_source.codec
     sound_source.codec = codec
     #tell the client this is the start:
     self.send(
         "sound-data", codec, "", {
             "start-of-stream": True,
             "codec": codec,
             "sequence": sound_source.sequence,
         })
     self.update_av_sync_delay_total()
示例#7
0
def get_CUDA_function(device_id, function_name):
    """
        Returns the compiled kernel for the given device
        and kernel key.
    """
    global KERNELS
    data = KERNELS.get(function_name)
    if data is None:
        from xpra.platform.paths import get_resources_dir
        cubin_file = os.path.join(get_resources_dir(), "cuda",
                                  "%s.fatbin" % function_name)
        log("get_CUDA_function(%s, %s) cubin file=%s", device_id,
            function_name, cubin_file)
        data = load_binary_file(cubin_file)
        if not data:
            log.error("Error: failed to load CUDA bin file '%s'", cubin_file)
            return None
        log(" loaded %s bytes", len(data))
        KERNELS[function_name] = data
    #now load from cubin:
    start = monotonic_time()
    try:
        mod = driver.module_from_buffer(data)
    except Exception as e:
        log("module_from_buffer(%s)", data, exc_info=True)
        log.error("Error: failed to load module from buffer for '%s'",
                  function_name)
        log.error(" %s", e)
        return None
    log("get_CUDA_function(%s, %s) module=%s", device_id, function_name, mod)
    try:
        fn = function_name
        CUDA_function = mod.get_function(fn)
    except driver.LogicError as e:
        raise Exception("failed to load '%s' from %s: %s" %
                        (function_name, mod, e)) from None
    end = monotonic_time()
    log("loading function %s from pre-compiled cubin took %.1fms",
        function_name, 1000.0 * (end - start))
    return CUDA_function
示例#8
0
def load_css(provider):
    css_dir = os.path.join(get_resources_dir(), "css")
    if not os.path.exists(css_dir) or not os.path.isdir(css_dir):
        log.error("Error: cannot find directory '%s'", css_dir)
        return None
    filename = None

    def parsing_error(_css_provider, _section, error):
        log.error("Error: CSS parsing error on")
        log.error(" '%s'", filename)
        log.error(" %s", error)

    provider.connect("parsing-error", parsing_error)
    for f in sorted(os.listdir(css_dir)):
        filename = os.path.join(css_dir, f)
        try:
            provider.load_from_path(filename)
            log(" - loaded '%s'", filename)
        except Exception as e:
            log("load_from_path(%s)", filename, exc_info=True)
            log.error("Error: CSS loading error on")
            log.error(" '%s'", filename)
            log.error(" %s", e)
示例#9
0
def do_get_icon_dir():
    from xpra.platform.paths import get_resources_dir
    i = os.path.join(get_resources_dir(), "share", "xpra", "icons")
    debug("get_icon_dir()=%s", i)
    return i
示例#10
0
文件: paths.py 项目: svn2github/Xpra
def do_get_app_dir():
    from xpra.platform.paths import get_resources_dir
    return get_resources_dir()
示例#11
0
def do_get_app_dir():
    from xpra.platform.paths import get_resources_dir
    return get_resources_dir()
示例#12
0
文件: paths.py 项目: svn2github/Xpra
def do_get_default_conf_dirs():
    # the default config file we install into the Resources folder:
    # ie: /Volumes/Xpra/Xpra.app/Contents/Resources/etc
    from xpra.platform.paths import get_resources_dir

    return [os.path.join(get_resources_dir(), "etc")]
示例#13
0
文件: paths.py 项目: svn2github/Xpra
def do_get_icon_dir():
    from xpra.platform.paths import get_resources_dir

    i = os.path.join(get_resources_dir(), "share", "xpra", "icons")
    debug("get_icon_dir()=%s", i)
    return i
示例#14
0
文件: server.py 项目: svn2github/Xpra
def start_websockify(child_reaper, opts, tcp_sockets):
    # start websockify?
    if not opts.html:
        return
    html = opts.html
    if type(html)==str:
        html = html.lower()
    from xpra.scripts.config import FALSE_OPTIONS, TRUE_OPTIONS
    if html in FALSE_OPTIONS:
        #html disabled
        return
    if opts.tcp_proxy:
        raise Exception("cannot use tcp-proxy mode with html, use one or the other")
        return 1
    from xpra.platform.paths import get_resources_dir
    www_dir = os.path.abspath(os.path.join(get_resources_dir(), "www"))
    if not os.path.exists(www_dir):
        raise Exception("cannot find xpra's html directory (not found in '%s')" % www_dir)
    import websockify           #@UnresolvedImport
    assert websockify
    html_port = -1
    html_host = "127.0.0.1"
    if html not in TRUE_OPTIONS:
        #we expect either HOST:PORT, or just PORT
        if html.find(":")>=0:
            html_host, html = html.split(":", 1)
        try:
            html_port = int(html)
        except Exception as e:
            raise Exception("invalid html port: %s" % e)
        #we now have the host and port (port may be -1 to mean auto..)
    if html_port==-1:
        #try to find a free port and hope that websockify can then use it..
        html_port = get_free_tcp_port()
    if len(tcp_sockets)<1:
        raise Exception("html web server requires at least one tcp socket, see 'bind-tcp'")
    #use the first tcp socket for websockify to talk back to us:
    _, xpra_tcp_port = list(tcp_sockets)[0]
    from xpra.log import Logger
    log = Logger("server")
    websockify_command = ["websockify", "--web", www_dir, "%s:%s" % (html_host, html_port), "127.0.0.1:%s" % xpra_tcp_port]
    log("websockify_command: %s", websockify_command)
    websockify_proc = subprocess.Popen(websockify_command, close_fds=True)
    websockify_proc._closed = False
    start_time = time.time()
    def websockify_ended(proc):
        elapsed = time.time()-start_time
        log("websockify_ended(%s) after %i seconds", elapsed)
        if not websockify_proc._closed:
            log.warn("Warning: websockify has terminated, the html web server will not be available.")
            log.warn(" command used: %s", " ".join(websockify_command))
        return False
    child_reaper.add_process(websockify_proc, "websockify", websockify_command, ignore=True, callback=websockify_ended)
    log.info("websockify started, serving %s on %s:%s", www_dir, html_host, html_port)
    def cleanup_websockify():
        log("cleanup_websockify() process.poll()=%s, pid=%s", websockify_proc.poll(), websockify_proc.pid)
        if websockify_proc.poll() is None and not websockify_proc._closed:
            log.info("stopping websockify with pid %s", websockify_proc.pid)
            try:
                websockify_proc._closed = True
                websockify_proc.terminate()
            except:
                log.warn("error trying to stop websockify", exc_info=True)
    _cleanups.append(cleanup_websockify)
    opts.tcp_proxy = "%s:%s" % (html_host, html_port)
示例#15
0
def do_get_default_conf_dirs():
    #the default config file we install into the Resources folder:
    #ie: /Volumes/Xpra/Xpra.app/Contents/Resources/etc
    from xpra.platform.paths import get_resources_dir
    return [os.path.join(get_resources_dir(), "etc", "xpra")]
示例#16
0
文件: paths.py 项目: frostbane/xpra
def do_get_icon_dir():
    from xpra.platform.paths import get_resources_dir
    return os.path.join(get_resources_dir(), "icons")
示例#17
0
def start_websockify(child_reaper, opts, tcp_sockets):
    # start websockify?
    if not opts.html:
        return
    html = opts.html
    if type(html) == str:
        html = html.lower()
    from xpra.scripts.config import FALSE_OPTIONS, TRUE_OPTIONS
    if html in FALSE_OPTIONS:
        #html disabled
        return
    if opts.tcp_proxy:
        raise InitException(
            "cannot use tcp-proxy mode with html, use one or the other")
        return 1
    from xpra.platform.paths import get_resources_dir
    www_dir = os.path.abspath(os.path.join(get_resources_dir(), "www"))
    if not os.path.exists(www_dir):
        raise InitException(
            "cannot find xpra's html directory (not found in '%s')" % www_dir)
    import websockify  #@UnresolvedImport
    assert websockify
    html_port = -1
    html_host = "127.0.0.1"
    if html not in TRUE_OPTIONS:
        #we expect either HOST:PORT, or just PORT
        if html.find(":") >= 0:
            html_host, html = html.split(":", 1)
        try:
            html_port = int(html)
        except Exception as e:
            raise InitException("invalid html port: %s" % e)
        #we now have the host and port (port may be -1 to mean auto..)
    from xpra.log import Logger
    log = Logger("server")
    if html_port == -1:
        #try to find a free port and hope that websockify can then use it..
        html_port = get_free_tcp_port()
    elif os.name == "posix" and html_port < 1024 and os.geteuid() != 0:
        log.warn(
            "Warning: the html port specified may require special privileges (%s:%s)",
            html_host, html_port)
    if len(tcp_sockets) < 1:
        raise InitException(
            "html web server requires at least one tcp socket, see 'bind-tcp'")
    #use the first tcp socket for websockify to talk back to us:
    _, xpra_tcp_port = list(tcp_sockets)[0]
    websockify_command = [
        "websockify", "--web", www_dir,
        "%s:%s" % (html_host, html_port),
        "127.0.0.1:%s" % xpra_tcp_port
    ]
    log("websockify_command: %s", websockify_command)
    websockify_proc = subprocess.Popen(websockify_command, close_fds=True)
    websockify_proc._closed = False
    start_time = time.time()

    def websockify_ended(proc):
        elapsed = time.time() - start_time
        log("websockify_ended(%s) after %i seconds", proc, elapsed)
        if not websockify_proc._closed:
            log.warn(
                "Warning: websockify has terminated, the html web server will not be available."
            )
            log.warn(" command used: %s", " ".join(websockify_command))
        return False

    child_reaper.add_process(websockify_proc,
                             "websockify",
                             websockify_command,
                             ignore=True,
                             callback=websockify_ended)
    log.info("websockify started, serving %s on %s:%s", www_dir, html_host,
             html_port)

    def cleanup_websockify():
        log("cleanup_websockify() process.poll()=%s, pid=%s",
            websockify_proc.poll(), websockify_proc.pid)
        if websockify_proc.poll() is None and not websockify_proc._closed:
            log.info("stopping websockify with pid %s", websockify_proc.pid)
            try:
                websockify_proc._closed = True
                websockify_proc.terminate()
            except:
                log.warn("error trying to stop websockify", exc_info=True)

    _cleanups.append(cleanup_websockify)
    opts.tcp_proxy = "%s:%s" % (html_host, html_port)