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


Python os.lstat方法代码示例

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


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

示例1: stat

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def stat(self, follow_symlinks=True):
            if follow_symlinks:
                if self._stat is None:
                    if self.is_symlink():
                        # It's a symlink, call link-following stat()
                        self._stat = stat(self.path)
                    else:
                        # Not a symlink, stat is same as lstat value
                        if self._lstat is None:
                            self._lstat = find_data_to_stat(self._find_data)
                        self._stat = self._lstat
                return self._stat
            else:
                if self._lstat is None:
                    # Lazily convert to stat object, because it's slow
                    # in Python, and often we only need is_dir() etc
                    self._lstat = find_data_to_stat(self._find_data)
                return self._lstat 
开发者ID:DoTheEvo,项目名称:ANGRYsearch,代码行数:20,代码来源:scandir.py

示例2: copymode

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def copymode(src, dst, *, follow_symlinks=True):
    """Copy mode bits from src to dst.

    If follow_symlinks is not set, symlinks aren't followed if and only
    if both `src` and `dst` are symlinks.  If `lchmod` isn't available
    (e.g. Linux) this method does nothing.

    """
    if not follow_symlinks and os.path.islink(src) and os.path.islink(dst):
        if hasattr(os, 'lchmod'):
            stat_func, chmod_func = os.lstat, os.lchmod
        else:
            return
    elif hasattr(os, 'chmod'):
        stat_func, chmod_func = os.stat, os.chmod
    else:
        return

    st = stat_func(src)
    chmod_func(dst, stat.S_IMODE(st.st_mode)) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:22,代码来源:shutil.py

示例3: list_files

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def list_files(self, path):
        containing_dir_path = os.path.join(
            self.cache_directory, path.lstrip(os.path.sep))
        try:
            for root, _, files in os.walk(containing_dir_path):
                for filename in files:
                    if filename.startswith("@") and filename.endswith("@"):
                        generation = filename[1:-1]
                        subpath = "/" + os.path.relpath(
                            root, self.cache_directory)

                        s = os.lstat(os.path.join(root, filename))
                        yield dict(
                            created=s.st_ctime,
                            updated=s.st_mtime,
                            size=s.st_size,
                            generation=generation,
                            path=subpath)

        except (IOError, OSError):
            pass 
开发者ID:google,项目名称:rekall,代码行数:23,代码来源:cache.py

示例4: from_stat

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def from_stat(cls, filespec, session=None):
        filespec = FileSpec(filespec)
        result = FileInformation(filename=filespec, session=session)

        try:
            path = filespec.os_path()
            s = os.lstat(path)
        except (IOError, OSError) as e:
            return obj.NoneObject("Unable to stat %s", e)

        result.st_mode = Permissions(s.st_mode)
        result.st_ino = s.st_ino
        result.st_size = s.st_size
        result.st_dev = s.st_dev
        result.st_nlink = s.st_nlink
        result.st_uid = User.from_uid(s.st_uid)
        result.st_gid = Group.from_gid(s.st_gid)
        result.st_mtime = s.st_mtime
        result.st_atime = s.st_atime
        result.st_ctime = s.st_ctime

        return result 
开发者ID:google,项目名称:rekall,代码行数:24,代码来源:common.py

示例5: test_ismount_different_device

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def test_ismount_different_device(self):
        # Simulate the path being on a different device from its parent by
        # mocking out st_dev.
        save_lstat = os.lstat
        def fake_lstat(path):
            st_ino = 0
            st_dev = 0
            if path == ABSTFN:
                st_dev = 1
                st_ino = 1
            return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
        try:
            os.lstat = fake_lstat
            self.assertIs(posixpath.ismount(ABSTFN), True)
        finally:
            os.lstat = save_lstat 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_posixpath.py

示例6: _rmtree

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def _rmtree(path):
        try:
            shutil.rmtree(path)
            return
        except EnvironmentError:
            pass

        def _rmtree_inner(path):
            for name in _force_run(path, os.listdir, path):
                fullname = os.path.join(path, name)
                try:
                    mode = os.lstat(fullname).st_mode
                except EnvironmentError:
                    mode = 0
                if stat.S_ISDIR(mode):
                    _rmtree_inner(fullname)
                    _force_run(path, os.rmdir, fullname)
                else:
                    _force_run(path, os.unlink, fullname)
        _rmtree_inner(path)
        os.rmdir(path) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:__init__.py

示例7: discover_config_file_paths

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def discover_config_file_paths(accessed_since, config_file_set,
                               exclude_regex, root_dir):
    # Walk the directory hierarchy starting at 'root_dir' in BFS
    # order looking for config files.
    for (root_dirpath, dirs, files) in os.walk(root_dir):
        dirs[:] = [os.path.join(root_dirpath, d) for d in
                   dirs]
        dirs[:] = [d for d in dirs
                   if not re.match(exclude_regex, d)]
        files = [os.path.join(root_dirpath, f) for f in
                 files]
        files = [f for f in files
                 if not re.match(exclude_regex, f)]
        for fpath in files:
            if os.path.exists(fpath) \
                    and _is_config_file(fpath):
                lstat = os.lstat(fpath)
                if lstat.st_atime > accessed_since \
                        or lstat.st_ctime > accessed_since:
                    config_file_set.add(fpath) 
开发者ID:cloudviz,项目名称:agentless-system-crawler,代码行数:22,代码来源:config_utils.py

示例8: _get_file_stat

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def _get_file_stat(path, follow_symlinks=True, **kwargs):
    if path.startswith('//') or path.startswith('\\\\'):
        return smbclient_stat(path, follow_symlinks=follow_symlinks, **kwargs)
    else:
        # Source is a local path or accessible to the host, use the builtin os module to get the read only flag.
        if follow_symlinks:
            return os.stat(path)
        else:
            return os.lstat(path) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:11,代码来源:shutil.py

示例9: test_copymode_local_to_local_symlink_follow

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def test_copymode_local_to_local_symlink_follow(tmpdir):
    test_dir = tmpdir.mkdir('test')
    src_filename = "%s\\source.txt" % test_dir
    dst_filename = "%s\\target.txt" % test_dir

    with open(src_filename, mode='w') as fd:
        fd.write(u"content")
    os.chmod(src_filename, stat.S_IREAD)

    with open(dst_filename, mode='w') as fd:
        fd.write(u"content")

    src_link = "%s\\source-link.txt" % test_dir
    dst_link = "%s\\target-link.txt" % test_dir

    os.symlink(src_filename, src_link)
    os.symlink(dst_filename, dst_link)

    copymode(src_link, dst_link)

    actual_file = os.stat(dst_filename).st_mode
    assert stat.S_IMODE(actual_file) & stat.S_IWRITE == 0

    actual_link = os.lstat(dst_link).st_mode
    assert stat.S_IMODE(actual_link) & stat.S_IWRITE == stat.S_IWRITE

    os.chmod(src_filename, stat.S_IWRITE)  # Needed when running on Windows as os.remove will fail to remove.
    os.remove(src_filename)
    with open(src_filename, mode='w') as fd:
        fd.write(u"content")

    copymode(src_link, dst_link)

    actual_file = os.stat(dst_filename).st_mode
    assert stat.S_IMODE(actual_file) & stat.S_IWRITE == stat.S_IWRITE

    actual_link = os.lstat(dst_link).st_mode
    assert stat.S_IMODE(actual_link) & stat.S_IWRITE == stat.S_IWRITE 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:40,代码来源:test_smbclient_shutil.py

示例10: test_copystat_local_to_local_symlink_follow

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def test_copystat_local_to_local_symlink_follow(tmpdir):
    test_dir = tmpdir.mkdir('test')
    src_filename = "%s\\source.txt" % test_dir
    dst_filename = "%s\\target.txt" % test_dir

    with open(src_filename, mode='w') as fd:
        fd.write(u"content")
    os.chmod(src_filename, stat.S_IREAD)
    os.utime(src_filename, (1024, 1024))

    with open(dst_filename, mode='w') as fd:
        fd.write(u"content")

    src_link = "%s\\source-link.txt" % test_dir
    dst_link = "%s\\target-link.txt" % test_dir

    os.symlink(src_filename, src_link)
    os.symlink(dst_filename, dst_link)

    copystat(src_link, dst_link)

    actual_file = os.stat(dst_filename)
    assert actual_file.st_atime == 1024
    assert actual_file.st_mtime == 1024
    assert stat.S_IMODE(actual_file.st_mode) & stat.S_IWRITE == 0

    actual_link = os.lstat(dst_link)
    assert actual_link.st_atime != 1024
    assert actual_link.st_mtime != 1024
    assert stat.S_IMODE(actual_link.st_mode) & stat.S_IWRITE == stat.S_IWRITE 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:32,代码来源:test_smbclient_shutil.py

示例11: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def __init__(self, scandir_path, name, lstat):
                self._scandir_path = scandir_path
                self.name = name
                self._stat = None
                self._lstat = lstat
                self._path = None 
开发者ID:DoTheEvo,项目名称:ANGRYsearch,代码行数:8,代码来源:scandir.py

示例12: _rmtree_unsafe

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def _rmtree_unsafe(path, onerror):
    try:
        if os.path.islink(path):
            # symlinks to directories are forbidden, see bug #1669
            raise OSError("Cannot call rmtree on a symbolic link")
    except OSError:
        onerror(os.path.islink, path, sys.exc_info())
        # can't continue even if onerror hook returns
        return
    names = []
    try:
        names = os.listdir(path)
    except os.error:
        onerror(os.listdir, path, sys.exc_info())
    for name in names:
        fullname = os.path.join(path, name)
        try:
            mode = os.lstat(fullname).st_mode
        except os.error:
            mode = 0
        if stat.S_ISDIR(mode):
            _rmtree_unsafe(fullname, onerror)
        else:
            try:
                os.unlink(fullname)
            except os.error:
                onerror(os.unlink, fullname, sys.exc_info())
    try:
        os.rmdir(path)
    except os.error:
        onerror(os.rmdir, path, sys.exc_info())

# Version using fd-based APIs to protect against races 
开发者ID:war-and-code,项目名称:jawfish,代码行数:35,代码来源:shutil.py

示例13: dirname

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def dirname(p):
    """Returns the directory component of a pathname"""
    sep = _get_sep(p)
    i = p.rfind(sep) + 1
    head = p[:i]
    if head and head != sep*len(head):
        head = head.rstrip(sep)
    return head


# Is a path a symbolic link?
# This will always return false on systems where os.lstat doesn't exist. 
开发者ID:war-and-code,项目名称:jawfish,代码行数:14,代码来源:posixpath.py

示例14: islink

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def islink(path):
    """Test whether a path is a symbolic link"""
    try:
        st = os.lstat(path)
    except (os.error, AttributeError):
        return False
    return stat.S_ISLNK(st.st_mode)

# Being true for dangling symbolic links is also useful. 
开发者ID:war-and-code,项目名称:jawfish,代码行数:11,代码来源:posixpath.py

示例15: sameopenfile

# 需要导入模块: import os [as 别名]
# 或者: from os import lstat [as 别名]
def sameopenfile(fp1, fp2):
    """Test whether two open file objects reference the same file"""
    s1 = os.fstat(fp1)
    s2 = os.fstat(fp2)
    return samestat(s1, s2)


# Are two stat buffers (obtained from stat, fstat or lstat)
# describing the same file? 
开发者ID:war-and-code,项目名称:jawfish,代码行数:11,代码来源:posixpath.py


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