コード例 #1
0
def glibc_version_string_confstr():

    # type: () -> Optional[str]

    "Primary implementation of glibc_version_string using os.confstr."

    # os.confstr is quite a bit faster than ctypes.DLL. It's also less likely

    # to be broken or missing. This strategy is used in the standard library

    # platform module:

    # https://github.com/python/cpython/blob/fcf1d003bf4f0100c9d0921ff3d70e1127ca1b71/Lib/platform.py#L175-L183

    if sys.platform == "win32":

        return None

    try:

        # os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17":

        _, version = os.confstr("CS_GNU_LIBC_VERSION").split()

    except (AttributeError, OSError, ValueError):

        # os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)...

        return None

    return version
コード例 #2
0
ファイル: tags.py プロジェクト: wikieden/lumberyard
def _glibc_version_string_confstr():

    # type: () -> Optional[str]
    """

    Primary implementation of glibc_version_string using os.confstr.

    """

    # os.confstr is quite a bit faster than ctypes.DLL. It's also less likely

    # to be broken or missing. This strategy is used in the standard library

    # platform module.

    # https://github.com/python/cpython/blob/fcf1d003bf4f0100c9d0921ff3d70e1127ca1b71/Lib/platform.py#L175-L183

    try:

        # os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17".

        version_string = os.confstr(  # type: ignore[attr-defined] # noqa: F821
            "CS_GNU_LIBC_VERSION")

        assert version_string is not None

        _, version = version_string.split()  # type: Tuple[str, str]

    except (AssertionError, AttributeError, OSError, ValueError):

        # os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)...

        return None

    return version
コード例 #3
0
ファイル: interp_posix.py プロジェクト: mozillazg/pypy
def confstr(space, w_name):
    num = confname_w(space, w_name, os.confstr_names)
    try:
        res = os.confstr(num)
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.wrap(res)
コード例 #4
0
ファイル: interp_posix.py プロジェクト: zcxowwww/pypy
def confstr(space, w_name):
    num = confname_w(space, w_name, os.confstr_names)
    try:
        res = os.confstr(num)
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.newtext(res)
コード例 #5
0
def collect_environment_provenance():
    """Collect enviroment variables and operating system characteristics
    Return dict
    """
    environment = {}
    e = environment

    environment['OS_NAME'] = platform.system()
    # Unix environment
    try:
        for name in os.sysconf_names:
            try:
                environment[name] = os.sysconf(name)
            except ValueError:
                pass
        for name in os.confstr_names:
            environment[name] = os.confstr(name)
        environment['USER'] = os.getlogin()
        e['OS_NAME'], _, e['OS_RELEASE'], e['OS_VERSION'], _ = os.uname()
    except:
        pass
    # Windows environment
    if environment['OS_NAME'] == 'Windows':
        e['OS_RELEASE'], e['OS_VERSION'], _, _ = platform.win32_ver()

    # Both Unix and Windows
    environment.update(os.environ)
    environment['PWD'] = os.getcwd()
    environment['PID'] = os.getpid()
    environment['HOSTNAME'] = socket.gethostname()
    environment['ARCH'] = platform.architecture()[0]
    environment['PROCESSOR'] = platform.processor()
    environment['PYTHON_IMPLEMENTATION'] = platform.python_implementation()
    environment['PYTHON_VERSION'] = platform.python_version()
    return environment
コード例 #6
0
def find_executable(executable, path=None):
    """Tries to find 'executable' in the directories listed in 'path'.

    A string listing directories separated by 'os.pathsep'; defaults to
    os.environ['PATH'].  Returns the complete filename or None if not found.
    """
    _, ext = os.path.splitext(executable)
    if (sys.platform == 'win32') and (ext != '.exe'):
        executable = executable + '.exe'

    if os.path.isfile(executable):
        return executable

    if path is None:
        path = os.environ.get('PATH', None)
        if path is None:
            try:
                path = os.confstr("CS_PATH")
            except (AttributeError, ValueError):
                # os.confstr() or CS_PATH is not available
                path = os.defpath
        # bpo-35755: Don't use os.defpath if the PATH environment variable is
        # set to an empty string

    # PATH='' doesn't match, whereas PATH=':' looks in the current directory
    if not path:
        return None

    paths = path.split(os.pathsep)
    for p in paths:
        f = os.path.join(p, executable)
        if os.path.isfile(f):
            # the file exists, we have a shot at spawn working
            return f
    return None
コード例 #7
0
def collect_environment_provenance():
    environment = {}

    environment['OS_NAME'] = platform.system()
    # Unix environment
    try:
        for name in os.sysconf_names:
            try:
                environment[name] = os.sysconf(name)
            except:
                pass
        for name in os.confstr_names:
            environment[name] = os.confstr(name)
        environment['USER'] = os.getlogin()
        environment['OS_NAME'], _, environment['OS_RELEASE'], environment[
            'OS_VERSION'], _ = os.uname()
    except:
        pass
    # Windows environment
    if environment['OS_NAME'] == 'Windows':
        environment['OS_RELEASE'], environment[
            'OS_VERSION'], _, _ = platform.win32_ver()

    # Both Unix and Windows
    environment.update(os.environ)
    environment['PWD'] = os.getcwd()
    environment['PID'] = os.getpid()
    environment['HOSTNAME'] = socket.gethostname()
    environment['ARCH'] = platform.architecture()[0]
    environment['PROCESSOR'] = platform.processor()
    environment['PYTHON_IMPLEMENTATION'] = platform.python_implementation()
    environment['PYTHON_VERSION'] = platform.python_version()
    return environment
コード例 #8
0
def linux_get_libc_version():
    """
    If on linux, returns (libc_family, version), otherwise (None, None).
    """

    if not sys.platform.startswith('linux'):
        return None, None

    from os import confstr, confstr_names, readlink

    # Python 2.7 does not have either of these keys in confstr_names, so provide
    # hard-coded defaults and assert if the key is in confstr_names but differs.
    # These are defined by POSIX anyway so should never change.
    confstr_names_fallback = OrderedDict([('CS_GNU_LIBC_VERSION', 2),
                                          ('CS_GNU_LIBPTHREAD_VERSION', 3)])

    val = None
    for k, v in iteritems(confstr_names_fallback):
        assert k not in confstr_names or confstr_names[k] == v, (
            "confstr_names_fallback for %s is %s yet in confstr_names it is %s"
            "" % (k, confstr_names_fallback[k], confstr_names[k]))
        try:
            val = str(confstr(v))
        except Exception:  # pragma: no cover
            pass
        else:
            if val:
                break

    if not val:  # pragma: no cover
        # Weird, play it safe and assume glibc 2.5
        family, version = 'glibc', '2.5'
        log.warning("Failed to detect libc family and version, assuming %s/%s",
                    family, version)
        return family, version
    family, version = val.split(' ')

    # NPTL is just the name of the threading library, even though the
    # version refers to that of uClibc. readlink() can help to try to
    # figure out a better name instead.
    if family == 'NPTL':  # pragma: no cover
        clibs = glob('/lib/libc.so*')
        for clib in clibs:
            clib = readlink(clib)
            if exists(clib):
                if clib.startswith('libuClibc'):
                    if version.startswith('0.'):
                        family = 'uClibc'
                    else:
                        family = 'uClibc-ng'
                    return family, version
        # This could be some other C library; it is unlikely though.
        family = 'uClibc'
        log.warning("Failed to detect non-glibc family, assuming %s (%s)",
                    family, version)
        return family, version
    return family, version
コード例 #9
0
ファイル: platform.py プロジェクト: DamirAinullin/PTVS
def linux_get_libc_version():
    """
    If on linux, returns (libc_family, version), otherwise (None, None)
    """

    if not sys.platform.startswith('linux'):
        return None, None

    from os import confstr, confstr_names, readlink

    # Python 2.7 does not have either of these keys in confstr_names, so provide
    # hard-coded defaults and assert if the key is in confstr_names but differs.
    # These are defined by POSIX anyway so should never change.
    confstr_names_fallback = OrderedDict([('CS_GNU_LIBC_VERSION', 2),
                                          ('CS_GNU_LIBPTHREAD_VERSION', 3)])

    val = None
    for k, v in iteritems(confstr_names_fallback):
        assert k not in confstr_names or confstr_names[k] == v, (
            "confstr_names_fallback for %s is %s yet in confstr_names it is %s"
            "" % (k, confstr_names_fallback[k], confstr_names[k])
        )
        try:
            val = str(confstr(v))
        except:  # pragma: no cover
            pass
        else:
            if val:
                break

    if not val:  # pragma: no cover
        # Weird, play it safe and assume glibc 2.5
        family, version = 'glibc', '2.5'
        log.warning("Failed to detect libc family and version, assuming %s/%s", family, version)
        return family, version
    family, version = val.split(' ')

    # NPTL is just the name of the threading library, even though the
    # version refers to that of uClibc. readlink() can help to try to
    # figure out a better name instead.
    if family == 'NPTL':  # pragma: no cover
        clibs = glob('/lib/libc.so*')
        for clib in clibs:
            clib = readlink(clib)
            if exists(clib):
                if clib.startswith('libuClibc'):
                    if version.startswith('0.'):
                        family = 'uClibc'
                    else:
                        family = 'uClibc-ng'
                    return family, version
        # This could be some other C library; it is unlikely though.
        family = 'uClibc'
        log.warning("Failed to detect non-glibc family, assuming %s (%s)", family, version)
        return family, version
    return family, version
コード例 #10
0
 def _path_to_user_cache_directory(self, suffix=None):
     DIRHELPER_USER_DIR_SUFFIX = "DIRHELPER_USER_DIR_SUFFIX"
     saved_suffix = None
     if suffix is not None:
         saved_suffix = os.environ.get(DIRHELPER_USER_DIR_SUFFIX)
         os.environ[DIRHELPER_USER_DIR_SUFFIX] = suffix
     result = os.confstr(65538)  # _CS_DARWIN_USER_CACHE_DIR
     if saved_suffix is not None:
         os.environ[DIRHELPER_USER_DIR_SUFFIX] = saved_suffix
     return result
コード例 #11
0
ファイル: file.py プロジェクト: mthambipillai/ksconf
    def which(cmd, mode=os.F_OK | os.X_OK, path=None):
        """Given a command, mode, and a PATH string, return the path which
        conforms to the given mode on the PATH, or None if there is no such
        file.
        `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
        of os.environ.get("PATH"), or can be overridden with a custom search
        path.
        """
        def _access_check(fn, mode):
            return (os.path.exists(fn) and os.access(fn, mode)
                    and not os.path.isdir(fn))

        if os.path.dirname(cmd):
            if _access_check(cmd, mode):
                return cmd
            return None

        if path is None:
            path = os.environ.get("PATH", None)
            if path is None:
                try:
                    path = os.confstr("CS_PATH")
                except (AttributeError, ValueError):
                    # os.confstr() or CS_PATH is not available
                    path = os.defpath
        # PATH='' doesn't match, whereas PATH=':' looks in the current directory
        if not path:
            return None
        path = path.split(os.pathsep)

        if sys.platform == "win32":
            # The current directory takes precedence on Windows.
            if not os.curdir in path:
                path.insert(0, os.curdir)

            # PATHEXT is necessary to check on Windows.
            pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
            if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
                files = [cmd]
            else:
                files = [cmd + ext for ext in pathext]
        else:
            files = [cmd]

        seen = set()
        for dir in path:
            normdir = os.path.normcase(dir)
            if not normdir in seen:
                seen.add(normdir)
                for thefile in files:
                    name = os.path.join(dir, thefile)
                    if _access_check(name, mode):
                        return name
        return None
コード例 #12
0
def get_paths():
    path = os.environ.get(str("PATH"), None)
    if path is None:
        try:
            path = os.confstr("CS_PATH")
        except (AttributeError, ValueError):
            path = os.defpath
    if not path:
        paths = []
    else:
        paths = [p for p in path.split(os.pathsep) if os.path.exists(p)]
    return paths
コード例 #13
0
ファイル: path.py プロジェクト: ronin-gw/uge2slurm
def _get_command_paths(cmd, mode=os.F_OK | os.X_OK):
    """Based on the shutil.which"""

    path = os.environ.get("PATH", None)
    if path is None:
        try:
            path = os.confstr("CS_PATH")
        except (AttributeError, ValueError):
            path = os.defpath

    if not path:
        return []

    use_bytes = isinstance(cmd, bytes)

    if use_bytes:
        path = fsencode(path)
        path = path.split(fsencode(os.pathsep))
    else:
        path = fsdecode(path)
        path = path.split(os.pathsep)

    if sys.platform == "win32":
        curdir = os.curdir
        if use_bytes:
            curdir = fsencode(curdir)
        if curdir not in path:
            path.insert(0, curdir)

        pathext_source = os.getenv("PATHEXT") or _WIN_DEFAULT_PATHEXT
        pathext = [ext for ext in pathext_source.split(os.pathsep) if ext]

        if use_bytes:
            pathext = [fsencode(ext) for ext in pathext]
        if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
            files = [cmd]
        else:
            files = [cmd + ext for ext in pathext]
    else:
        files = [cmd]

    seen = set()
    found_paths = []
    for dir in path:
        normdir = os.path.normcase(dir)
        if normdir not in seen:
            seen.add(normdir)
            for thefile in files:
                name = os.path.join(dir, thefile)
                if access_check(name, mode):
                    found_paths.append(name)

    return found_paths
コード例 #14
0
ファイル: setup.py プロジェクト: tdryer/cbor2
def check_libc():
    "check that if we have glibc < 2.9 we should not build c ext"
    # Borrowed from pip internals
    # https://github.com/pypa/pip/blob/20.1.1/src/pip/_internal/utils/glibc.py#L21-L36
    try:
        # os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17":
        libc, version = os.confstr("CS_GNU_LIBC_VERSION").split()
    except (AttributeError, OSError, ValueError):
        # os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)...
        return True
    if libc != 'glibc':
        # Attempt to build with musl or other libc
        return True
    return parse_version(version) >= min_glibc
コード例 #15
0
def about_operating_system():
    """Show information about the operating system"""
    if parameters["Operating System"]:
        print("[Operating system]")
        print("os.name={}".format(os.name))
        print("platform.system()={}".format(platform.system()))
        print("platform.release()={}".format(platform.release()))
        print("sys.platform={}".format(sys.platform))
        print("sysconfig.get_platform()={}".format(sysconfig.get_platform()))
        print("platform.platform()={}".format(platform.platform()))
        print("platform.version()={}".format(platform.version()))
        print("platform.uname()={}".format(platform.uname()))
        if sys_type() == "Unix":
            print("os.uname().sysname={}".format(os.uname().sysname))
            print("os.uname().release={}".format(os.uname().release))
            print("os.uname().version={}".format(os.uname().version))
        elif sys_type() == "Windows":
            print("sys.getwindowsversion()={}".format(sys.getwindowsversion()))
            print("platform.win32_ver()={}".format(platform.win32_ver()))
            print("platform.win32_edition()={}".format(
                platform.win32_edition()))
            print("platform.win32_is_iot()={}".format(platform.win32_is_iot()))
        print()

        if sys_type() == "Unix":
            print("[Operating system/Configuration]")
            for name in os.confstr_names:
                try:
                    print("os.confstr('{}')={}".format(name, os.confstr(name)))
                except OSError as error:
                    print("os.confstr('{}')={}".format(name,
                                                       "Error: " + str(error)))
            for name in os.sysconf_names:
                try:
                    print("os.sysconf('{}')={}".format(name, os.sysconf(name)))
                except OSError as error:
                    print("os.sysconf('{}')={}".format(name,
                                                       "Error: " + str(error)))
            print()

        print("[Operating system/Portability]")
        print("os.curdir={}".format(os.curdir))
        print("os.pardir={}".format(os.pardir))
        print("os.sep={}".format(os.sep))
        print("os.altsep={}".format(os.altsep))
        print("os.extsep={}".format(os.extsep))
        print("os.pathsep={}".format(os.pathsep))
        print("os.defpath={}".format(os.defpath))
        print("os.devnull={}".format(os.devnull))
        print("os.linesep={}".format(os.linesep))
コード例 #16
0
ファイル: pyffle_stats.py プロジェクト: pyfbbs/pyffle
	def osDicts(self):
		names = os.sysconf_names
		self.data.util.println("\n%36sysonf%0")
		try:
			for name in names:
				self.data.util.println("%35" + name + "%0 => %37" + str(os.sysconf(name)))
		except:
			pass
		
		names = os.confstr_names
		self.data.util.println("\n%36confstr%0")
		try:
			for name in names:
				self.data.util.println("%35" + name + "%0 => %37" + str(os.confstr(name)))
		except:
			pass
		self.data.util.println("%0")
コード例 #17
0
ファイル: mac.py プロジェクト: QPanWeb/ENG-webkit
    def _path_to_user_cache_directory(self, suffix=None):
        DIRHELPER_USER_DIR_SUFFIX = 'DIRHELPER_USER_DIR_SUFFIX'
        CS_DARWIN_USER_CACHE_DIR = 65538

        # The environment variable DIRHELPER_USER_DIR_SUFFIX is only honored on systems with
        # System Integrity Protection disabled or with an Apple-Internal OS. To make this code
        # work for all system configurations we compute the path with respect to the suffix
        # by hand and temporarily unset the environment variable DIRHELPER_USER_DIR_SUFFIX (if set)
        # to avoid it influencing confstr() on systems that honor DIRHELPER_USER_DIR_SUFFIX.
        saved_suffix = None
        if DIRHELPER_USER_DIR_SUFFIX in os.environ:
            saved_suffix = os.environ[DIRHELPER_USER_DIR_SUFFIX]
            del os.environ[DIRHELPER_USER_DIR_SUFFIX]
        result = os.path.join(os.confstr(CS_DARWIN_USER_CACHE_DIR), suffix or '')
        if saved_suffix is not None:
            os.environ[DIRHELPER_USER_DIR_SUFFIX] = saved_suffix
        return result
コード例 #18
0
ファイル: mac.py プロジェクト: eocanha/webkit
    def _path_to_user_cache_directory(self, suffix=None):
        DIRHELPER_USER_DIR_SUFFIX = 'DIRHELPER_USER_DIR_SUFFIX'
        CS_DARWIN_USER_CACHE_DIR = 65538

        # The environment variable DIRHELPER_USER_DIR_SUFFIX is only honored on systems with
        # System Integrity Protection disabled or with an Apple-Internal OS. To make this code
        # work for all system configurations we compute the path with respect to the suffix
        # by hand and temporarily unset the environment variable DIRHELPER_USER_DIR_SUFFIX (if set)
        # to avoid it influencing confstr() on systems that honor DIRHELPER_USER_DIR_SUFFIX.
        saved_suffix = None
        if DIRHELPER_USER_DIR_SUFFIX in os.environ:
            saved_suffix = os.environ[DIRHELPER_USER_DIR_SUFFIX]
            del os.environ[DIRHELPER_USER_DIR_SUFFIX]
        result = os.path.join(os.confstr(CS_DARWIN_USER_CACHE_DIR), suffix or '')
        if saved_suffix is not None:
            os.environ[DIRHELPER_USER_DIR_SUFFIX] = saved_suffix
        return result
コード例 #19
0
ファイル: test_posix2.py プロジェクト: sczfaker/pypy
 def setup_class(cls):
     space = cls.space
     cls.w_runappdirect = space.wrap(cls.runappdirect)
     cls.w_posix = space.appexec([], GET_POSIX)
     cls.w_path = space.wrap(str(path))
     cls.w_path2 = space.wrap(str(path2))
     cls.w_path3 = space.wrap(str(path3))
     cls.w_pdir = space.wrap(str(pdir))
     cls.w_plat = space.wrap(sys.platform)
     try:
         cls.w_unicode_dir = space.wrap(
             str(unicode_dir).decode(sys.getfilesystemencoding()))
     except UnicodeDecodeError:
         # filesystem encoding is not good enough
         cls.w_unicode_dir = space.w_None
     if hasattr(os, 'getuid'):
         cls.w_getuid = space.wrap(os.getuid())
         cls.w_geteuid = space.wrap(os.geteuid())
     if hasattr(os, 'getgid'):
         cls.w_getgid = space.wrap(os.getgid())
     if hasattr(os, 'getgroups'):
         cls.w_getgroups = space.newlist(
             [space.wrap(e) for e in os.getgroups()])
     if hasattr(os, 'getpgid'):
         cls.w_getpgid = space.wrap(os.getpgid(os.getpid()))
     if hasattr(os, 'getsid'):
         cls.w_getsid0 = space.wrap(os.getsid(0))
     if hasattr(os, 'sysconf'):
         sysconf_name = os.sysconf_names.keys()[0]
         cls.w_sysconf_name = space.wrap(sysconf_name)
         cls.w_sysconf_value = space.wrap(os.sysconf_names[sysconf_name])
         cls.w_sysconf_result = space.wrap(os.sysconf(sysconf_name))
     if hasattr(os, 'confstr'):
         confstr_name = os.confstr_names.keys()[0]
         cls.w_confstr_name = space.wrap(confstr_name)
         cls.w_confstr_value = space.wrap(os.confstr_names[confstr_name])
         cls.w_confstr_result = space.wrap(os.confstr(confstr_name))
     cls.w_SIGABRT = space.wrap(signal.SIGABRT)
     cls.w_python = space.wrap(sys.executable)
     cls.w_platform = space.wrap(sys.platform)
     if hasattr(os, 'major'):
         cls.w_expected_major_12345 = space.wrap(os.major(12345))
         cls.w_expected_minor_12345 = space.wrap(os.minor(12345))
     cls.w_udir = space.wrap(str(udir))
コード例 #20
0
def find_executable(cmd):

    executable, options = split_exec_options(cmd)

    # shortcicuit is already a valid abs or rel path
    if os.path.dirname(executable):
        if is_executable(executable):
            return cmd
        return None

    path = os.environ.get("PATH", None)
    if path is None:
        try:
            path = os.confstr("CS_PATH")
        except (AttributeError, ValueError):
            path = os.defpath
    if not path:
        return None
    path = os.fsdecode(path)
    path = path.split(os.pathsep)

    if sys.platform == "win32":
        curdir = os.curdir
        if curdir not in path:
            path.insert(0, curdir)

        # Windows uses file extensions to determine excecutables
        pathext = os.environ.get("PATHEXT", "").lower().split(os.pathsep)
        if any(executable.lower().endswith(ext) for ext in pathext):
            filenames = [executable]
        else:
            filenames = [executable + ext for ext in pathext]
    else:
        filenames = [executable]

    seen = set()
    for dir in path:
        if not dir in seen:
            seen.add(dir)
            for filename in filenames:
                filepath = os.path.join(dir, filename)
                if is_executable(filepath):
                    return filepath + options
    return None
コード例 #21
0
ファイル: package.py プロジェクト: wrwilliams/spack
    def generate_environment(self):
        host_family = self.spec.target.family
        host_platform = self.spec.platform
        host_libc = os.confstr('CS_GNU_LIBC_VERSION').split()[1]
        target = '{0}-pc-{1}-gnu-libc{2}'.format(host_family, host_platform,
                                                 host_libc)
        headas_setup_file = join_path(self.spec.prefix, target, 'BUILD_DIR',
                                      'headas-setup')

        filter_file(r'(^headas_config=).*',
                    r'\1{0}'.format(join_path(self.prefix, 'headas-config_spack')),
                    headas_setup_file)

        filter_file(r'(^flavor.*\n)',
                    r'\1HEADAS={0}'.format(join_path(self.spec.prefix, target))
                    + "\n",
                    headas_setup_file)

        headas_setup = Executable(headas_setup_file)
        headas_setup('sh')
コード例 #22
0
ファイル: test_posix2.py プロジェクト: abhinavthomas/pypy
 def setup_class(cls):
     cls.space = space
     cls.w_runappdirect = space.wrap(cls.runappdirect)
     cls.w_posix = space.appexec([], GET_POSIX)
     cls.w_path = space.wrap(str(path))
     cls.w_path2 = space.wrap(str(path2))
     cls.w_pdir = space.wrap(str(pdir))
     try:
         cls.w_unicode_dir = space.wrap(
             str(unicode_dir).decode(sys.getfilesystemencoding()))
     except UnicodeDecodeError:
         # filesystem encoding is not good enough
         cls.w_unicode_dir = space.w_None
     if hasattr(os, 'getuid'):
         cls.w_getuid = space.wrap(os.getuid())
         cls.w_geteuid = space.wrap(os.geteuid())
     if hasattr(os, 'getgid'):
         cls.w_getgid = space.wrap(os.getgid())
     if hasattr(os, 'getgroups'):
         cls.w_getgroups = space.newlist([space.wrap(e) for e in os.getgroups()])
     if hasattr(os, 'getpgid'):
         cls.w_getpgid = space.wrap(os.getpgid(os.getpid()))
     if hasattr(os, 'getsid'):
         cls.w_getsid0 = space.wrap(os.getsid(0))
     if hasattr(os, 'sysconf'):
         sysconf_name = os.sysconf_names.keys()[0]
         cls.w_sysconf_name = space.wrap(sysconf_name)
         cls.w_sysconf_value = space.wrap(os.sysconf_names[sysconf_name])
         cls.w_sysconf_result = space.wrap(os.sysconf(sysconf_name))
     if hasattr(os, 'confstr'):
         confstr_name = os.confstr_names.keys()[0]
         cls.w_confstr_name = space.wrap(confstr_name)
         cls.w_confstr_value = space.wrap(os.confstr_names[confstr_name])
         cls.w_confstr_result = space.wrap(os.confstr(confstr_name))
     cls.w_SIGABRT = space.wrap(signal.SIGABRT)
     cls.w_python = space.wrap(sys.executable)
     if hasattr(os, 'major'):
         cls.w_expected_major_12345 = space.wrap(os.major(12345))
         cls.w_expected_minor_12345 = space.wrap(os.minor(12345))
     cls.w_udir = space.wrap(str(udir))
コード例 #23
0
    def _collect_environment_provenance(self):
        """Collect enviroment variables and operating system characteristics
        Return dict
        """
        attrs = self.metascript.environment_attrs_store

        attrs.add("OS_NAME", platform.system())
        # Unix environment
        try:
            for name in os.sysconf_names:
                try:
                    attrs.add(name, os.sysconf(name))
                except (ValueError, OSError):
                    pass
            for name in os.confstr_names:
                attrs.add(name, os.confstr(name))
        except AttributeError:
            pass

        os_name, _, os_release, os_version, _, _ = platform.uname()
        attrs.add("OS_NAME", os_name)
        attrs.add("OS_RELEASE", os_release)
        attrs.add("OS_VERSION", os_version)

        # Both Unix and Windows
        for attr, value in viewitems(os.environ):
            attrs.add(attr, value)

        attrs.add("USER", getpass.getuser())
        attrs.add("PWD", os.getcwd())
        attrs.add("PID", os.getpid())
        attrs.add("HOSTNAME", socket.gethostname())
        attrs.add("ARCH", platform.architecture()[0])
        attrs.add("PROCESSOR", platform.processor())
        attrs.add("PYTHON_IMPLEMENTATION", platform.python_implementation())
        attrs.add("PYTHON_VERSION", platform.python_version())

        attrs.add("NOWORKFLOW_VERSION", version())
コード例 #24
0
ファイル: deployment.py プロジェクト: gems-uff/noworkflow
    def _collect_environment_provenance(self):
        """Collect enviroment variables and operating system characteristics
        Return dict
        """
        attrs = self.metascript.environment_attrs_store

        attrs.add("OS_NAME", platform.system())
        # Unix environment
        try:
            for name in os.sysconf_names:
                try:
                    attrs.add(name, os.sysconf(name))
                except (ValueError, OSError):
                    pass
            for name in os.confstr_names:
                attrs.add(name, os.confstr(name))
        except AttributeError:
            pass

        os_name, _, os_release, os_version, _, _ = platform.uname()
        attrs.add("OS_NAME", os_name)
        attrs.add("OS_RELEASE", os_release)
        attrs.add("OS_VERSION", os_version)

        # Both Unix and Windows
        for attr, value in viewitems(os.environ):
            attrs.add(attr, value)

        attrs.add("USER", getpass.getuser())
        attrs.add("PWD", os.getcwd())
        attrs.add("PID", os.getpid())
        attrs.add("HOSTNAME", socket.gethostname())
        attrs.add("ARCH", platform.architecture()[0])
        attrs.add("PROCESSOR", platform.processor())
        attrs.add("PYTHON_IMPLEMENTATION", platform.python_implementation())
        attrs.add("PYTHON_VERSION", platform.python_version())

        attrs.add("NOWORKFLOW_VERSION", version())
コード例 #25
0
ファイル: test_posix2.py プロジェクト: Qointum/pypy
 def setup_class(cls):
     cls.space = space
     cls.w_runappdirect = space.wrap(cls.runappdirect)
     cls.w_posix = space.appexec([], GET_POSIX)
     cls.w_os = space.appexec([], "(): import os as m ; return m")
     cls.w_path = space.wrap(str(path))
     cls.w_path2 = space.wrap(str(path2))
     cls.w_pdir = space.wrap(str(pdir))
     cls.w_bytes_dir = space.wrapbytes(str(bytes_dir))
     cls.w_esurrogate_dir = space.wrapbytes(str(esurrogate_dir))
     if hasattr(os, 'getuid'):
         cls.w_getuid = space.wrap(os.getuid())
         cls.w_geteuid = space.wrap(os.geteuid())
     if hasattr(os, 'getgid'):
         cls.w_getgid = space.wrap(os.getgid())
     if hasattr(os, 'getgroups'):
         cls.w_getgroups = space.newlist(
             [space.wrap(e) for e in os.getgroups()])
     if hasattr(os, 'getpgid'):
         cls.w_getpgid = space.wrap(os.getpgid(os.getpid()))
     if hasattr(os, 'getsid'):
         cls.w_getsid0 = space.wrap(os.getsid(0))
     if hasattr(os, 'sysconf'):
         sysconf_name = os.sysconf_names.keys()[0]
         cls.w_sysconf_name = space.wrap(sysconf_name)
         cls.w_sysconf_value = space.wrap(os.sysconf_names[sysconf_name])
         cls.w_sysconf_result = space.wrap(os.sysconf(sysconf_name))
     if hasattr(os, 'confstr'):
         confstr_name = os.confstr_names.keys()[0]
         cls.w_confstr_name = space.wrap(confstr_name)
         cls.w_confstr_value = space.wrap(os.confstr_names[confstr_name])
         cls.w_confstr_result = space.wrap(os.confstr(confstr_name))
     cls.w_SIGABRT = space.wrap(signal.SIGABRT)
     cls.w_python = space.wrap(sys.executable)
     if hasattr(os, 'major'):
         cls.w_expected_major_12345 = space.wrap(os.major(12345))
         cls.w_expected_minor_12345 = space.wrap(os.minor(12345))
     cls.w_udir = space.wrap(str(udir))
コード例 #26
0
ファイル: test_posix2.py プロジェクト: Qointum/pypy
 def setup_class(cls):
     cls.space = space
     cls.w_runappdirect = space.wrap(cls.runappdirect)
     cls.w_posix = space.appexec([], GET_POSIX)
     cls.w_os = space.appexec([], "(): import os as m ; return m")
     cls.w_path = space.wrap(str(path))
     cls.w_path2 = space.wrap(str(path2))
     cls.w_pdir = space.wrap(str(pdir))
     cls.w_bytes_dir = space.wrapbytes(str(bytes_dir))
     cls.w_esurrogate_dir = space.wrapbytes(str(esurrogate_dir))
     if hasattr(os, "getuid"):
         cls.w_getuid = space.wrap(os.getuid())
         cls.w_geteuid = space.wrap(os.geteuid())
     if hasattr(os, "getgid"):
         cls.w_getgid = space.wrap(os.getgid())
     if hasattr(os, "getgroups"):
         cls.w_getgroups = space.newlist([space.wrap(e) for e in os.getgroups()])
     if hasattr(os, "getpgid"):
         cls.w_getpgid = space.wrap(os.getpgid(os.getpid()))
     if hasattr(os, "getsid"):
         cls.w_getsid0 = space.wrap(os.getsid(0))
     if hasattr(os, "sysconf"):
         sysconf_name = os.sysconf_names.keys()[0]
         cls.w_sysconf_name = space.wrap(sysconf_name)
         cls.w_sysconf_value = space.wrap(os.sysconf_names[sysconf_name])
         cls.w_sysconf_result = space.wrap(os.sysconf(sysconf_name))
     if hasattr(os, "confstr"):
         confstr_name = os.confstr_names.keys()[0]
         cls.w_confstr_name = space.wrap(confstr_name)
         cls.w_confstr_value = space.wrap(os.confstr_names[confstr_name])
         cls.w_confstr_result = space.wrap(os.confstr(confstr_name))
     cls.w_SIGABRT = space.wrap(signal.SIGABRT)
     cls.w_python = space.wrap(sys.executable)
     if hasattr(os, "major"):
         cls.w_expected_major_12345 = space.wrap(os.major(12345))
         cls.w_expected_minor_12345 = space.wrap(os.minor(12345))
     cls.w_udir = space.wrap(str(udir))
コード例 #27
0
ファイル: system.py プロジェクト: grubermeister/kamina-script
def get_thread_info(space):
    if not space.config.objspace.usemodules.thread:
        return None
    from rpython.rlib import rthread
    w_version = space.w_None
    if rthread.RPYTHREAD_NAME == "pthread":
        w_lock = space.newtext(
            "semaphore" if rthread.USE_SEMAPHORES else "mutex+cond")
        if rthread.CS_GNU_LIBPTHREAD_VERSION is not None:
            try:
                name = os.confstr(rthread.CS_GNU_LIBPTHREAD_VERSION)
            except OSError:
                pass
            else:
                w_version = space.newtext(name)
    else:
        w_lock = space.w_None
    info_w = [
        space.newtext(rthread.RPYTHREAD_NAME),
        w_lock,
        w_version,
    ]
    w_thread_info = app.wget(space, "thread_info")
    return space.call_function(w_thread_info, space.newtuple(info_w))
コード例 #28
0
ファイル: tasks.py プロジェクト: pycopia/ssh2-python3
from __future__ import annotations

import sys
import os
import shutil
import getpass
from glob import glob
from shutil import copy2

import semver
import keyring
from invoke import task, run, Exit

# local environment
LIBC = os.confstr('CS_GNU_LIBC_VERSION').replace(" ", "")

LIBSSH2_REMOTE = "https://github.com/kdart/libssh2.git"

# local user account name
SIGNERS = ["keithdart", "keith"]
CURRENT_USER = getpass.getuser()

PYTHONBIN = os.environ.get("PYTHONBIN", sys.executable)
# Put the path in quotes in case there is a space in it.
PYTHONBIN = f'"{PYTHONBIN}"'

GPG = "gpg2"


# Package repo location. Putting info here eliminates the need for user-private ~/.pypirc file.
コード例 #29
0
ファイル: test_posix2.py プロジェクト: abhinavthomas/pypy
 def test_os_confstr(self):
     os = self.posix
     assert os.confstr(self.confstr_value) == self.confstr_result
     assert os.confstr(self.confstr_name) == self.confstr_result
     assert os.confstr_names[self.confstr_name] == self.confstr_value
コード例 #30
0
ファイル: mac.py プロジェクト: rhythmkay/webkit
 def remove_cache_directory(self, name):
     self._filesystem.rmtree(os.confstr(65538) + name)
コード例 #31
0
ファイル: compat.py プロジェクト: dbv771/Xmacs
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
    """Given a command, mode, and a PATH string, return the path which
    conforms to the given mode on the PATH, or None if there is no such
    file.
    `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
    of os.environ.get("PATH"), or can be overridden with a custom search
    path.
    """
    # If we're given a path with a directory part, look it up directly rather
    # than referring to PATH directories. This includes checking relative to the
    # current directory, e.g. ./script
    if os.path.dirname(cmd):
        if _access_check(cmd, mode):
            return cmd
        return None

    use_bytes = isinstance(cmd, bytes)

    if path is None:
        path = os.environ.get("PATH", None)
        if path is None:
            try:
                path = os.confstr("CS_PATH")
            except (AttributeError, ValueError):
                # os.confstr() or CS_PATH is not available
                path = os.defpath
        # bpo-35755: Don't use os.defpath if the PATH environment variable is
        # set to an empty string

    # PATH='' doesn't match, whereas PATH=':' looks in the current directory
    if not path:
        return None

    if use_bytes:
        path = fsencode(path)
        path = path.split(fsencode(os.pathsep))
    else:
        path = fsdecode(path)
        path = path.split(os.pathsep)

    if sys.platform == "win32":
        # The current directory takes precedence on Windows.
        curdir = os.curdir
        if use_bytes:
            curdir = fsencode(curdir)
        if curdir not in path:
            path.insert(0, curdir)

        # PATHEXT is necessary to check on Windows.
        pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
        if use_bytes:
            pathext = [fsencode(ext) for ext in pathext]
        # See if the given file matches any of the expected path extensions.
        # This will allow us to short circuit when given "python.exe".
        # If it does match, only test that one, otherwise we have to try
        # others.
        if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
            files = [cmd]
        else:
            files = [cmd + ext for ext in pathext]
    else:
        # On other platforms you don't have things like PATHEXT to tell you
        # what file suffixes are executable, so just pass on cmd as-is.
        files = [cmd]

    seen = set()
    for dir in path:
        normdir = os.path.normcase(dir)
        if not normdir in seen:
            seen.add(normdir)
            for thefile in files:
                name = os.path.join(dir, thefile)
                if _access_check(name, mode):
                    return name
    return None
コード例 #32
0
ファイル: test_os.py プロジェクト: pogigroo/py3k-__format__
import signal
import subprocess
import time
import shutil
from test import support
import contextlib
import mmap
import uuid

# Detect whether we're on a Linux system that uses the (now outdated
# and unmaintained) linuxthreads threading library.  There's an issue
# when combining linuxthreads with a failed execv call: see
# http://bugs.python.org/issue4970.
if (hasattr(os, "confstr_names") and
    "CS_GNU_LIBPTHREAD_VERSION" in os.confstr_names):
    libpthread = os.confstr("CS_GNU_LIBPTHREAD_VERSION")
    USING_LINUXTHREADS= libpthread.startswith("linuxthreads")
else:
    USING_LINUXTHREADS= False

# Tests creating TESTFN
class FileTests(unittest.TestCase):
    def setUp(self):
        if os.path.exists(support.TESTFN):
            os.unlink(support.TESTFN)
    tearDown = setUp

    def test_access(self):
        f = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
        os.close(f)
        self.assertTrue(os.access(support.TESTFN, os.W_OK))
コード例 #33
0
def libc_ver(executable=None, lib='', version='', chunksize=16384):
    """ Tries to determine the libc version that the file executable
        (which defaults to the Python interpreter) is linked against.

        Returns a tuple of strings (lib,version) which default to the
        given parameters in case the lookup fails.

        Note that the function has intimate knowledge of how different
        libc versions add symbols to the executable and thus is probably
        only useable for executables compiled using gcc.

        The file is read and scanned in chunks of chunksize bytes.

    """
    if executable is None:
        try:
            ver = os.confstr('CS_GNU_LIBC_VERSION')
            # parse 'glibc 2.28' as ('glibc', '2.28')
            parts = ver.split(maxsplit=1)
            if len(parts) == 2:
                return tuple(parts)
        except (AttributeError, ValueError, OSError):
            # os.confstr() or CS_GNU_LIBC_VERSION value not available
            pass

        executable = sys.executable

    V = _comparable_version
    if hasattr(os.path, 'realpath'):
        # Python 2.2 introduced os.path.realpath(); it is used
        # here to work around problems with Cygwin not being
        # able to open symlinks for reading
        executable = os.path.realpath(executable)
    with open(executable, 'rb') as f:
        binary = f.read(chunksize)
        pos = 0
        while pos < len(binary):
            if b'libc' in binary or b'GLIBC' in binary:
                m = _libc_search.search(binary, pos)
            else:
                m = None
            if not m or m.end() == len(binary):
                chunk = f.read(chunksize)
                if chunk:
                    binary = binary[max(pos, len(binary) - 1000):] + chunk
                    pos = 0
                    continue
                if not m:
                    break
            libcinit, glibc, glibcversion, so, threads, soversion = [
                s.decode('latin1') if s is not None else s for s in m.groups()
            ]
            if libcinit and not lib:
                lib = 'libc'
            elif glibc:
                if lib != 'glibc':
                    lib = 'glibc'
                    version = glibcversion
                elif V(glibcversion) > V(version):
                    version = glibcversion
            elif so:
                if lib != 'glibc':
                    lib = 'libc'
                    if soversion and (not version
                                      or V(soversion) > V(version)):
                        version = soversion
                    if threads and version[-len(threads):] != threads:
                        version = version + threads
            pos = m.end()
    return lib, version
コード例 #34
0
ファイル: platform.py プロジェクト: adrian17/cpython
def libc_ver(executable=None, lib='', version='', chunksize=16384):

    """ Tries to determine the libc version that the file executable
        (which defaults to the Python interpreter) is linked against.

        Returns a tuple of strings (lib,version) which default to the
        given parameters in case the lookup fails.

        Note that the function has intimate knowledge of how different
        libc versions add symbols to the executable and thus is probably
        only useable for executables compiled using gcc.

        The file is read and scanned in chunks of chunksize bytes.

    """
    if executable is None:
        try:
            ver = os.confstr('CS_GNU_LIBC_VERSION')
            # parse 'glibc 2.28' as ('glibc', '2.28')
            parts = ver.split(maxsplit=1)
            if len(parts) == 2:
                return tuple(parts)
        except (AttributeError, ValueError, OSError):
            # os.confstr() or CS_GNU_LIBC_VERSION value not available
            pass

        executable = sys.executable

    V = _comparable_version
    if hasattr(os.path, 'realpath'):
        # Python 2.2 introduced os.path.realpath(); it is used
        # here to work around problems with Cygwin not being
        # able to open symlinks for reading
        executable = os.path.realpath(executable)
    with open(executable, 'rb') as f:
        binary = f.read(chunksize)
        pos = 0
        while pos < len(binary):
            if b'libc' in binary or b'GLIBC' in binary:
                m = _libc_search.search(binary, pos)
            else:
                m = None
            if not m or m.end() == len(binary):
                chunk = f.read(chunksize)
                if chunk:
                    binary = binary[max(pos, len(binary) - 1000):] + chunk
                    pos = 0
                    continue
                if not m:
                    break
            libcinit, glibc, glibcversion, so, threads, soversion = [
                s.decode('latin1') if s is not None else s
                for s in m.groups()]
            if libcinit and not lib:
                lib = 'libc'
            elif glibc:
                if lib != 'glibc':
                    lib = 'glibc'
                    version = glibcversion
                elif V(glibcversion) > V(version):
                    version = glibcversion
            elif so:
                if lib != 'glibc':
                    lib = 'libc'
                    if soversion and (not version or V(soversion) > V(version)):
                        version = soversion
                    if threads and version[-len(threads):] != threads:
                        version = version + threads
            pos = m.end()
    return lib, version
コード例 #35
0
import subprocess
import time
import shutil
from test import support
import contextlib
import mmap
import uuid
from test.script_helper import assert_python_ok

# Detect whether we're on a Linux system that uses the (now outdated
# and unmaintained) linuxthreads threading library.  There's an issue
# when combining linuxthreads with a failed execv call: see
# http://bugs.python.org/issue4970.
if (hasattr(os, "confstr_names")
        and "CS_GNU_LIBPTHREAD_VERSION" in os.confstr_names):
    libpthread = os.confstr("CS_GNU_LIBPTHREAD_VERSION")
    USING_LINUXTHREADS = libpthread.startswith("linuxthreads")
else:
    USING_LINUXTHREADS = False


# Tests creating TESTFN
class FileTests(unittest.TestCase):
    def setUp(self):
        if os.path.exists(support.TESTFN):
            os.unlink(support.TESTFN)

    tearDown = setUp

    def test_access(self):
        f = os.open(support.TESTFN, os.O_CREAT | os.O_RDWR)
コード例 #36
0
ファイル: test_posix2.py プロジェクト: Qointum/pypy
 def test_os_confstr(self):
     os = self.posix
     assert os.confstr(self.confstr_value) == self.confstr_result
     assert os.confstr(self.confstr_name) == self.confstr_result
     assert os.confstr_names[self.confstr_name] == self.confstr_value
コード例 #37
0
ファイル: gnumed.py プロジェクト: ncqgm/gnumed
def log_startup_info():
    global _pre_log_buffer
    if len(_pre_log_buffer) > 0:
        _log.info('early startup log buffer:')
    for line in _pre_log_buffer:
        _log.info(' ' + line)
    del _pre_log_buffer
    _log.info('GNUmed client version [%s] on branch [%s]',
              current_client_version, current_client_branch)
    _log.info('Platform: %s', platform.uname())
    _log.info(('Python %s on %s (%s)' %
               (sys.version, sys.platform, os.name)).replace('\n', '<\\n>'))
    try:
        import lsb_release
        _log.info('lsb_release: %s', lsb_release.get_distro_information())
    except ImportError:
        pass
    _log.info('module <sys> info:')
    attrs2skip = ['__doc__', 'copyright', '__name__', '__spec__']
    for attr_name in dir(sys):
        if attr_name in attrs2skip:
            continue
        if attr_name.startswith('set'):
            continue
        attr = getattr(sys, attr_name)
        if not attr_name.startswith('get'):
            _log.info('%s: %s', attr_name.rjust(30), attr)
            continue
        if callable(attr):
            try:
                _log.info('%s: %s', attr_name.rjust(30), attr())
            except Exception:
                _log.exception('%s: <cannot log>', attr_name.rjust(30))
            continue
    _log.info('module <platform> info:')
    attrs2skip = [
        '__doc__', '__copyright__', '__name__', '__spec__', '__cached__',
        '__builtins__'
    ]
    for attr_name in dir(platform):
        if attr_name in attrs2skip:
            continue
        if attr_name.startswith('set'):
            continue
        attr = getattr(platform, attr_name)
        if callable(attr):
            if attr_name.startswith('_'):
                _log.info('%s: %s', attr_name.rjust(30), attr)
                continue
            try:
                _log.info('%s: %s', attr_name.rjust(30), attr())
            except Exception:
                _log.exception('%s: <cannot log>', attr_name.rjust(30))
            continue
        _log.info('%s: %s', attr_name.rjust(30), attr)
        continue
    _log.info('module <os> info:')
    for n in os.confstr_names:
        _log.info('%s: %s', ('confstr[%s]' % n).rjust(40), os.confstr(n))
    for n in os.sysconf_names:
        try:
            _log.info('%s: %s', ('sysconf[%s]' % n).rjust(40), os.sysconf(n))
        except Exception:
            _log.exception('%s: <invalid> ??', ('sysconf[%s]' % n).rjust(30))
    os_attrs = [
        'name', 'ctermid', 'getcwd', 'get_exec_path', 'getegid', 'geteuid',
        'getgid', 'getgroups', 'getlogin', 'getpgrp', 'getpid', 'getppid',
        'getresuid', 'getresgid', 'getuid', 'supports_bytes_environ', 'uname',
        'get_terminal_size', 'pathconf_names', 'times', 'cpu_count', 'curdir',
        'pardir', 'sep', 'altsep', 'extsep', 'pathsep', 'defpath', 'linesep',
        'devnull'
    ]
    for attr_name in os_attrs:
        attr = getattr(os, attr_name)
        if callable(attr):
            try:
                _log.info('%s: %s', attr_name.rjust(40), attr())
            except Exception as exc:
                _log.error('%s: a callable, but call failed (%s)',
                           attr_name.rjust(40), exc)
            continue
        _log.info('%s: %s', attr_name.rjust(40), attr)
    _log.info('process environment:')
    for key, val in os.environ.items():
        _log.info(' %s: %s' % (('${%s}' % key).rjust(40), val))
    import sysconfig
    _log.info('module <sysconfig> info:')
    _log.info(' platform [%s] -- python version [%s]',
              sysconfig.get_platform(), sysconfig.get_python_version())
    _log.info(' sysconfig.get_paths():')
    paths = sysconfig.get_paths()
    for path in paths:
        _log.info('%s: %s', path.rjust(40), paths[path])
    _log.info(' sysconfig.get_config_vars():')
    conf_vars = sysconfig.get_config_vars()
    for var in conf_vars:
        _log.info('%s: %s', var.rjust(45), conf_vars[var])
コード例 #38
0
def getshell_var(s):
	if os.confstr(s):
		return os.environ[s]
	return None
	
コード例 #39
0
    screen = turtle.Screen()
    screen.setup(1000, 1000)
    screen.bgpic('under_the_clouds.png')

    # html file generation
    header = '<!DOCTYPE html>\n<html>\n'
    cssInsert = '<head>\n<link rel=\"stylesheet\" href=\"base.css\">'
    gglTextInsert = '\n<link href=\"https://fonts.googleapis.com/css?family=Aclonica\" rel=\"stylesheet\">\n</head>\n<body>'
    footer = '\n</body>\n</html>'
    usrname = turtle.textinput("Name", "What is your name?")
    htmlFile = usrname + '.html'
    generatedFile = open(htmlFile, 'wt')
    # getting PATH and setting perm directory to use for temp stuff.
    # boom, cross platform, and a rotating log.
    try:
        if os.confstr('CS_PATH') != OSError or os.confstr(
                'CS_PATH') != ValueError:
            # the os.confstr is only avail on linux/unix systems. SO! this will always be true
            # so long as the system is a unix based system! clever little work around imo.
            try:
                linux = os.mkdir('./gui_logs/')
                if linux != OSError or linux != PermissionError:
                    os.chdir('./gui_logs/')
                    logfile = open('gui_use_log.log', 'a')
                    logfile.write('\nUnix based systems have been selected!\n')
                    linUX = './gui_logs/'

            except FileExistsError as err:
                logfile = open('gui_use_log.log', 'a')
                defo = {
                    ' \nSelected Unix based system and file already exists, continuing.',
コード例 #40
0
ファイル: test_posix.py プロジェクト: Darriall/pypy
 def f(i):
     try:
         return os.confstr(i)
     except OSError:
         return "oooops!!"
コード例 #41
0
                          b'(GLIBC_([0-9.]+))'
                          b'|'
                          br'(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)', re.ASCII)
def libc_ver(executable=None, lib='', version='', chunksize=16384):
    """ Tries to determine the libc version that the file executable
        (which defaults to the Python interpreter) is linked against.
        Returns a tuple of strings (lib,version) which default to the
        given parameters in case the lookup fails.
        Note that the function has intimate knowledge of how different
        libc versions add symbols to the executable and thus is probably
        only useable for executables compiled using gcc.
        The file is read and scanned in chunks of chunksize bytes.
    """
    if executable is None:
        try:
            ver = os.confstr('CS_GNU_LIBC_VERSION')
            # parse 'glibc 2.28' as ('glibc', '2.28')
            parts = ver.split(maxsplit=1)
            if len(parts) == 2:
                return tuple(parts)
        except (AttributeError, ValueError, OSError):
            # os.confstr() or CS_GNU_LIBC_VERSION value not available
            pass
        executable = sys.executable
    V = _comparable_version
    if hasattr(os.path, 'realpath'):
        # Python 2.2 introduced os.path.realpath(); it is used
        # here to work around problems with Cygwin not being
        # able to open symlinks for reading
        executable = os.path.realpath(executable)
    with open(executable, 'rb') as f:
コード例 #42
0
    # setup journal file for certification, if needed

    JOURNAL = 'journal.lsbcmdchk'
    if OPTS.nojournal:
        JOURNAL = '/dev/null'
    if OPTS.journal:
        JOURNAL = OPTS.journal
    JOURNAL = tetj.Journal(JOURNAL, 'lsbcmdchk.py')
    if not JOURNAL.journal:
        sys.stderr.write('Could not open journal file')
        sys.exit(1)
    JOURNAL.add_config('VSX_NAME=lsbcmdchk.py %s (%s)' %
                       (LSBCMDCHK_VERSION, JOURNAL.machine))
    JOURNAL.add_config('LSB_VERSION=%s' % LSBVERSION)
    JOURNAL.add_config('search prefix is [%s]' % OPTS.prefix)
    JOURNAL.config_end()

    # Look in POSIX-standard path, but also add paths for sysadmin utilities

    BINPATHS = os.confstr('CS_PATH').split(os.pathsep)
    BINPATHS = BINPATHS + ['/sbin', '/usr/sbin']

    DB = parse_cmds('cmdlist')
    JOURNAL.scenario_info('"total tests in cmdchk %d"' % len(DB.cmds))
    for CMD in DB.cmds:
        check_cmd(JOURNAL, CMD)
    if OPTS.extras:
        check_extras(DB)
    JOURNAL.close()
    sys.exit(0)
コード例 #43
0
 def remove_cache_directory(self, name):
     self._filesystem.rmtree(os.confstr(65538) + name)
コード例 #44
0
 def test_confstr(self):
   return
   for name in os.confstr_names:
     print name, " = ",os.confstr(name)
コード例 #45
0
 def test_confstr(self):
     return
     for name in os.confstr_names:
         print name, " = ", os.confstr(name)