예제 #1
0
def get_prefs():
    global PREFS
    if PREFS is None:
        PREFS = {}
        from xpra.platform.paths import get_default_conf_dirs, get_system_conf_dirs, get_user_conf_dirs
        dirs = get_default_conf_dirs() + get_system_conf_dirs(
        ) + get_user_conf_dirs()
        log("get_prefs() will try to load cuda.conf from: %s", dirs)
        for d in dirs:
            conf_file = os.path.join(os.path.expanduser(d), "cuda.conf")
            if not os.path.exists(conf_file):
                log("get_prefs() '%s' does not exist!", conf_file)
                continue
            if not os.path.isfile(conf_file):
                log("get_prefs() '%s' is not a file!", conf_file)
                continue
            try:
                with open(conf_file, "rU") as f:
                    for line in f:
                        sline = line.strip().rstrip('\r\n').strip()
                        props = sline.split("=", 1)
                        if len(props) != 2:
                            continue
                        name = props[0].strip()
                        value = props[1].strip()
                        if name in ("blacklist", ):
                            PREFS.setdefault(name, []).append(value)
                        elif name in ("device-id", "device-name"):
                            PREFS[name] = value
            except Exception as e:
                log.error("Error: cannot read cuda configuration file '%s':",
                          conf_file)
                log.error(" %s", e)
    return PREFS
예제 #2
0
def read_xpra_defaults():
    """
        Reads the global <xpra_conf_filename> from the <conf_dir>
        and then the user-specific one.
        (the latter overrides values from the former)
        returns a dict with values as strings and arrays of strings.
        If the <conf_dir> is not specified, we figure out its location.
    """
    from xpra.platform.paths import get_default_conf_dirs, get_system_conf_dirs, get_user_conf_dirs
    # load config files in this order (the later ones override earlier ones):
    # * application defaults   (ie: "/Volumes/Xpra/Xpra.app/Contents/Resources/" on OSX)
    #                          (ie: "C:\Program Files\Xpra\" on win32)
    #                          (ie: None on others)
    # * system defaults        (ie: "/etc/xpra" on Posix - not on OSX)
    #                          (ie: "/Library/Application Support/Xpra" on OSX)
    #                          (ie: "C:\Documents and Settings\All Users\Application Data\Xpra" with XP)
    #                          (ie: "C:\ProgramData\Xpra" with Vista onwards)
    # * user config            (ie: "~/.xpra/" on all Posix, including OSX)
    #                          (ie: "C:\Documents and Settings\Username\Application Data\Xpra" with XP)
    #                          (ie: "C:\Users\<user name>\AppData\Roaming" with Visa onwards)
    dirs = get_default_conf_dirs() + get_system_conf_dirs(
    ) + get_user_conf_dirs()
    defaults = {}
    for d in dirs:
        if not d:
            continue
        ad = os.path.expanduser(d)
        if not os.path.exists(ad):
            debug("read_xpra_defaults: skipping %s", ad)
            continue
        defaults.update(read_xpra_conf(ad))
        debug("read_xpra_defaults: updated defaults with %s", ad)
    may_create_user_config()
    return defaults
예제 #3
0
파일: config.py 프로젝트: svn2github/Xpra
def read_xpra_defaults():
    """
        Reads the global <xpra_conf_filename> from the <conf_dir>
        and then the user-specific one.
        (the latter overrides values from the former)
        returns a dict with values as strings and arrays of strings.
        If the <conf_dir> is not specified, we figure out its location.
    """
    from xpra.platform.paths import get_default_conf_dirs, get_system_conf_dirs, get_user_conf_dirs
    # load config files in this order (the later ones override earlier ones):
    # * application defaults   (ie: "/Volumes/Xpra/Xpra.app/Contents/Resources/" on OSX)
    #                          (ie: "C:\Program Files\Xpra\" on win32)
    #                          (ie: None on others)
    # * system defaults        (ie: "/etc/xpra" on Posix - not on OSX)
    #                          (ie: "/Library/Application Support/Xpra" on OSX)
    #                          (ie: "C:\Documents and Settings\All Users\Application Data\Xpra" with XP)
    #                          (ie: "C:\ProgramData\Xpra" with Vista onwards)
    # * user config            (ie: "~/.xpra/" on all Posix, including OSX)
    #                          (ie: "C:\Documents and Settings\Username\Application Data\Xpra" with XP)
    #                          (ie: "C:\Users\<user name>\AppData\Roaming" with Visa onwards)
    dirs = get_default_conf_dirs() + get_system_conf_dirs() + get_user_conf_dirs()
    defaults = {}
    for d in dirs:
        if not d:
            continue
        ad = os.path.expanduser(d)
        if not os.path.exists(ad):
            debug("read_xpra_defaults: skipping %s", ad)
            continue
        defaults.update(read_xpra_conf(ad))
        debug("read_xpra_defaults: updated defaults with %s", ad)
    may_create_user_config()
    return defaults
예제 #4
0
def get_prefs():
    global PREFS
    if PREFS is None:
        PREFS = {}
        from xpra.platform.paths import get_default_conf_dirs, get_system_conf_dirs, get_user_conf_dirs
        dirs = get_default_conf_dirs() + get_system_conf_dirs() + get_user_conf_dirs()
        log("get_prefs() will try to load cuda.conf from: %s", dirs)
        for d in dirs:
            conf_file = os.path.join(os.path.expanduser(d), "cuda.conf")
            if not os.path.exists(conf_file):
                log("get_prefs() '%s' does not exist!", conf_file)
                continue
            if not os.path.isfile(conf_file):
                log("get_prefs() '%s' is not a file!", conf_file)
                continue
            try:
                with open(conf_file, "rU") as f:
                    for line in f:
                        sline = line.strip().rstrip('\r\n').strip()
                        props = sline.split("=", 1)
                        if len(props)!=2:
                            continue
                        name = props[0].strip()
                        value = props[1].strip()
                        if name in ("blacklist", ):
                            PREFS.setdefault(name, []).append(value)
                        elif name in ("device-id", "device-name"):
                            PREFS[name] = value
            except Exception as e:
                log.error("Error: cannot read cuda configuration file '%s':", conf_file)
                log.error(" %s", e)
    return PREFS
예제 #5
0
def get_license_keys(version=0, basefilename="nvenc"):
    global license_keys
    filename = "%s%s.keys" % (basefilename, version or "")
    keys = license_keys.get(filename)
    if keys is not None:
        return keys
    env_name = "XPRA_%s_CLIENT_KEY" % basefilename.upper()
    env_keys = os.environ.get(env_name, "")
    if env_keys:
        keys = [x.strip() for x in env_keys.split(",")]
        log("using %s keys from environment variable %s: %s", basefilename,
            env_name, csv(keys))
    else:
        #try to load the license file
        keys = []
        try:
            #see read_xpra_defaults for an explanation of paths
            from xpra.platform.paths import get_default_conf_dirs, get_system_conf_dirs, get_user_conf_dirs
            dirs = get_default_conf_dirs() + get_system_conf_dirs(
            ) + get_user_conf_dirs()
            for d in dirs:
                if not d:
                    continue
                keys_file = os.path.join(d, filename)
                keys_file = os.path.expanduser(keys_file)
                if not os.path.exists(keys_file):
                    log("get_license_keys(%s, %s) '%s' does not exist",
                        basefilename, version, keys_file)
                    continue
                log("loading %s version %s keys from %s", basefilename,
                    version, keys_file)
                with open(keys_file, "rb") as f:
                    fkeys = []
                    for line in f:
                        sline = bytestostr(
                            line.strip().rstrip(b'\r\n').strip())
                        if not sline:
                            log("skipping empty line")
                            continue
                        if sline[0] in ('!', '#'):
                            log("skipping comments")
                            continue
                        fkeys.append(sline)
                        log("added key: %s", sline)
                    log("added %i key%s from %s", len(fkeys), engs(fkeys),
                        keys_file)
                    keys += fkeys
        except Exception:
            log.error("Error loading %s license keys",
                      basefilename,
                      exc_info=True)
    license_keys[filename] = keys
    log("get_nvenc_license_keys(%s)=%s", version, keys)
    return keys
예제 #6
0
def get_nvenc_license_keys(nvenc_version=0):
    global nvenc_license_keys
    keys = nvenc_license_keys.get(nvenc_version)
    if keys is not None:
        return keys
    env_keys = os.environ.get("XPRA_NVENC_CLIENT_KEY", "")
    if env_keys:
        keys = [
            x.strip()
            for x in os.environ.get("XPRA_NVENC_CLIENT_KEY", "").split(",")
        ]
        log(
            "using nvenc keys from environment variable XPRA_NVENC_CLIENT_KEY: %s",
            nvenc_license_keys)
    else:
        #try the license file
        keys = []
        try:
            #see read_xpra_defaults for an explanation of paths
            from xpra.platform.paths import get_default_conf_dirs, get_system_conf_dirs, get_user_conf_dirs
            dirs = get_default_conf_dirs() + get_system_conf_dirs(
            ) + get_user_conf_dirs()
            for d in dirs:
                if not d:
                    continue
                keys_file = os.path.join(
                    d, "nvenc%s.keys" % (nvenc_version or ""))
                keys_file = os.path.expanduser(keys_file)
                if not os.path.exists(keys_file):
                    log("get_nvenc_license_keys(%s) '%s' does not exist",
                        nvenc_version, keys_file)
                    continue
                log("loading nvenc%s keys from %s", nvenc_version, keys_file)
                with open(keys_file, "rU") as f:
                    fkeys = []
                    for line in f:
                        sline = line.strip().rstrip('\r\n').strip()
                        if len(sline) == 0:
                            log("skipping empty line")
                            continue
                        if sline[0] in ('!', '#'):
                            log("skipping comments")
                            continue
                        fkeys.append(sline)
                        log("added key: %s", sline)
                    log("added %i key%s from %s", len(fkeys), engs(fkeys),
                        keys_file)
                    keys += fkeys
        except Exception as e:
            log.error("error loading nvenc license keys: %s", e, exc_info=True)
    nvenc_license_keys[nvenc_version] = keys
    log("get_nvenc_license_keys(%s)=%s", nvenc_version, keys)
    return keys
예제 #7
0
파일: nv_util.py 프로젝트: svn2github/Xpra
def get_nvenc_license_keys(nvenc_version=0):
    global nvenc_license_keys
    keys = nvenc_license_keys.get(nvenc_version)
    if keys is not None:
        return keys
    env_keys = os.environ.get("XPRA_NVENC_CLIENT_KEY", "")
    if env_keys:
        keys = [x.strip() for x in os.environ.get("XPRA_NVENC_CLIENT_KEY", "").split(",")]
        log("using nvenc keys from environment variable XPRA_NVENC_CLIENT_KEY: %s", nvenc_license_keys)
    else:
        #try the license file
        keys = []
        try:
            #see read_xpra_defaults for an explanation of paths
            from xpra.platform.paths import get_default_conf_dirs, get_system_conf_dirs, get_user_conf_dirs
            dirs = get_default_conf_dirs() + get_system_conf_dirs() + get_user_conf_dirs()
            for d in dirs:
                if not d:
                    continue
                keys_file = os.path.join(d, "nvenc%s.keys" % (nvenc_version or ""))
                keys_file = os.path.expanduser(keys_file)
                if not os.path.exists(keys_file):
                    log("get_nvenc_license_keys(%s) '%s' does not exist", nvenc_version, keys_file)
                    continue
                log("loading nvenc%s keys from %s", nvenc_version, keys_file)
                with open(keys_file, "rU") as f:
                    fkeys = []
                    for line in f:
                        sline = line.strip().rstrip('\r\n').strip()
                        if len(sline) == 0:
                            log("skipping empty line")
                            continue
                        if sline[0] in ( '!', '#' ):
                            log("skipping comments")
                            continue
                        fkeys.append(sline)
                        log("added key: %s", sline)
                    log("added %i key%s from %s", len(fkeys), engs(fkeys), keys_file)
                    keys += fkeys
        except Exception as e:
            log.error("error loading nvenc license keys: %s", e, exc_info=True)
    nvenc_license_keys[nvenc_version] = keys
    log("get_nvenc_license_keys(%s)=%s", nvenc_version, keys)
    return keys
예제 #8
0
def get_prefs():
    global PREFS
    if PREFS is None:
        PREFS = {}
        from xpra.platform.paths import get_default_conf_dirs, get_system_conf_dirs, get_user_conf_dirs
        dirs = get_default_conf_dirs() + get_system_conf_dirs(
        ) + get_user_conf_dirs()
        log("get_prefs() will try to load cuda.conf from: %s", dirs)
        for d in dirs:
            conf_file = os.path.join(os.path.expanduser(d), "cuda.conf")
            if not os.path.exists(conf_file):
                log("get_prefs() '%s' does not exist!", conf_file)
                continue
            if not os.path.isfile(conf_file):
                log("get_prefs() '%s' is not a file!", conf_file)
                continue
            try:
                c_prefs = {}
                with open(conf_file, "rb") as f:
                    for line in f:
                        sline = line.strip().rstrip(b'\r\n').strip().decode(
                            "latin1")
                        props = sline.split("=", 1)
                        if len(props) != 2:
                            continue
                        name = props[0].strip()
                        value = props[1].strip()
                        if name in ("enabled-devices", "disabled-devices"):
                            for v in value.split(","):
                                c_prefs.setdefault(name, []).append(v.strip())
                        elif name in ("device-id", "device-name",
                                      "load-balancing"):
                            c_prefs[name] = value
            except Exception as e:
                log.error("Error: cannot read cuda configuration file '%s':",
                          conf_file)
                log.error(" %s", e)
            log("get_prefs() '%s' : %s", conf_file, c_prefs)
            PREFS.update(c_prefs)
    return PREFS