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


Python stat.S_IFREG属性代码示例

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


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

示例1: test_lstat_on_file

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def test_lstat_on_file(smb_share):
    filename = ntpath.join(smb_share, 'file.txt')
    with smbclient.open_file(filename, mode='w') as fd:
        fd.write(u"Content")

    actual = smbclient.lstat(filename)
    assert isinstance(actual, smbclient.SMBStatResult)
    assert actual.st_atime == actual.st_atime_ns / 1000000000
    assert actual.st_mtime == actual.st_mtime_ns / 1000000000
    assert actual.st_ctime == actual.st_ctime_ns / 1000000000
    assert actual.st_chgtime == actual.st_chgtime_ns / 1000000000
    assert actual.st_dev is not None
    assert actual.st_file_attributes == FileAttributes.FILE_ATTRIBUTE_ARCHIVE
    assert actual.st_gid == 0
    assert actual.st_uid == 0
    assert actual.st_ino is not None
    assert actual.st_mode == stat.S_IFREG | 0o666
    assert actual.st_nlink == 1
    assert actual.st_size == 7
    assert actual.st_uid == 0
    assert actual.st_reparse_tag == 0 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:23,代码来源:test_smbclient_os.py

示例2: _check_cert

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def _check_cert(filename):
    """
    Does this certificate file look okay?

    Returns error message, or None if okay
    """
    try:
        st = os.stat(filename)
    except OSError:
        return filename + " doesn't exist"
    else:
        good_perm = stat.S_IFREG | stat.S_IRUSR # | stat.S_IWUSR
        if (st[stat.ST_UID], st[stat.ST_GID]) != (0,0):
            return 'not owned by root.root'
        perm = st[stat.ST_MODE]
        if good_perm != perm:
            return "expected permissions %o but found %o." % (good_perm, perm) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:panel.py

示例3: getattr

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def getattr(self, path, fh=None):
        path = "".join([self.root, path.lstrip("/")]).rstrip("/")
        try:
            info = self.fs.info(path)
        except FileNotFoundError:
            raise FuseOSError(ENOENT)
        data = {"st_uid": 1000, "st_gid": 1000}
        perm = 0o777

        if info["type"] != "file":
            data["st_mode"] = stat.S_IFDIR | perm
            data["st_size"] = 0
            data["st_blksize"] = 0
        else:
            data["st_mode"] = stat.S_IFREG | perm
            data["st_size"] = info["size"]
            data["st_blksize"] = 5 * 2 ** 20
            data["st_nlink"] = 1
        data["st_atime"] = time.time()
        data["st_ctime"] = time.time()
        data["st_mtime"] = time.time()
        return data 
开发者ID:intake,项目名称:filesystem_spec,代码行数:24,代码来源:fuse.py

示例4: getattr

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def getattr(self, path):
        # The path represents a pid.
        components = os.path.split(path)
        if len(components) > 2:
            return

        if len(components) == 2 and components[1] in self.tasks:
            s = make_stat(components[1])
            s.st_mode = stat.S_IFREG
            s.st_size = self.address_space_size

            return s

        elif components[0] == "/":
            s = make_stat(2)
            s.st_mode = stat.S_IFDIR

            return s 
开发者ID:google,项目名称:rekall,代码行数:20,代码来源:address_space_fuse.py

示例5: push

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def push(self, src, dst: str, mode: int = 0o755, filesize: int = None):
        # IFREG: File Regular
        # IFDIR: File Directory
        path = dst + "," + str(stat.S_IFREG | mode)
        total_size = 0
        with self._prepare_sync(path, "SEND") as c:
            r = src if hasattr(src, "read") else open(src, "rb")
            try:
                while True:
                    chunk = r.read(4096)
                    if not chunk:
                        mtime = int(datetime.datetime.now().timestamp())
                        c.conn.send(b"DONE" + struct.pack("<I", mtime))
                        break
                    c.conn.send(b"DATA" + struct.pack("<I", len(chunk)))
                    c.conn.send(chunk)
                    total_size += len(chunk)
                assert c.read(4) == _OKAY
            finally:
                if hasattr(r, "close"):
                    r.close()
        # wait until really pushed
        # if filesize:
        #     print("Read: %d Copied: %d" % (filesize, total_size), self.stat(dst)) 
开发者ID:openatx,项目名称:adbutils,代码行数:26,代码来源:__init__.py

示例6: cmp_sig

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def cmp_sig(cls, f1, s2):
        """Compare file f1 to signature s2.
        Arguments:
        f1 --  File name
        s2 -- stats as returned by sig

        Return value:
        True if the files are the same, False otherwise.
        """

        if not s2:
            return False

        s1 = cls._sig(os.stat(f1))

        if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG:
            return False
        return s1 == s2 
开发者ID:RhetTbull,项目名称:osxphotos,代码行数:20,代码来源:fileutil.py

示例7: get_git_object_default_stats

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def get_git_object_default_stats(self, ref, path):
        types = {
            GIT_FILEMODE_LINK: {"st_mode": S_IFLNK | 0o444},
            GIT_FILEMODE_TREE: {"st_mode": S_IFDIR | 0o555, "st_nlink": 2},
            GIT_FILEMODE_BLOB: {"st_mode": S_IFREG | 0o444},
            GIT_FILEMODE_BLOB_EXECUTABLE: {"st_mode": S_IFREG | 0o555},
        }

        if path == "/":
            return types[GIT_FILEMODE_TREE]

        obj_type = self.get_git_object_type(ref, path)
        if obj_type is None:
            return obj_type

        stats = types[obj_type]
        if obj_type in [GIT_FILEMODE_BLOB, GIT_FILEMODE_BLOB_EXECUTABLE]:
            stats["st_size"] = self.get_blob_size(ref, path)

        return stats 
开发者ID:presslabs,项目名称:gitfs,代码行数:22,代码来源:repository.py

示例8: test_git_obj_default_stats_with_valid_obj

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def test_git_obj_default_stats_with_valid_obj(self):
        mocked_repo = MagicMock()
        mocked_git_obj = MagicMock()
        mocked_size = MagicMock()

        mocked_git_obj.return_value = GIT_FILEMODE_BLOB
        mocked_size.return_value = 10

        repo = Repository(mocked_repo)
        repo.get_git_object_type = mocked_git_obj
        repo.get_blob_size = mocked_size

        assert repo.get_git_object_default_stats("ref", "/ups") == {
            "st_mode": S_IFREG | 0o444,
            "st_size": 10,
        }
        mocked_size.assert_called_once_with("ref", "/ups")
        mocked_git_obj.assert_called_once_with("ref", "/ups") 
开发者ID:presslabs,项目名称:gitfs,代码行数:20,代码来源:test_repository.py

示例9: stat

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def stat(self, name):
        ap = self.abspath(name)
        if ap in ("/", "/.", "./", "//", ""):
            bytes = 0
            isdir = True
        else:
            try:
                meta = self.client.files_get_metadata(ap)
            except dropbox.exceptions.ApiError as e:
                raise OperationFailure(e.message)
            if isinstance(meta, (dropbox.files.FolderMetadata, dropbox.sharing.SharedFolderMetadata)):
                bytes = 0
                isdir = True
            else:
                bytes = meta.size
                isdir = False

        type_ = (stat.S_IFDIR if isdir else stat.S_IFREG)
        m = calc_mode(type=type_)
        s = make_stat(size=bytes, mode=m)
        return s 
开发者ID:ywangd,项目名称:stash,代码行数:23,代码来源:DropBox.py

示例10: stat

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def stat(self, name):
        ap = self.abspath(name)
        self.log("stat: {ap}\n".format(ap=ap))
        isdir = self.isdir(name)
        isfile = self.isfile(name)
        if not (isdir or isfile):
            self.log("stat-target not found.\n")
            raise errors.OperationFailure("Not found!")
        if isdir:
            size = 1
            mtime = None
        else:
            zipinfo = self.zf.getinfo(ap)
            size = zipinfo.file_size
            timestamp = zipinfo.date_time
            dt = datetime.datetime(*timestamp)
            mtime = (dt - datetime.datetime(1970, 1, 1)).total_seconds()
        type_ = (stat.S_IFREG if isfile else stat.S_IFDIR)
        mode = base.calc_mode(type=type_)
        self.log("stat return\n")
        return base.make_stat(size=size, mtime=mtime, ctime=mtime, mode=mode) 
开发者ID:ywangd,项目名称:stash,代码行数:23,代码来源:zip.py

示例11: stat

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def stat(self, path):
        node = self.get_node(path)
        if node is None:
            raise FileNotFoundError
        else:
            if node.type == "file":
                size = len(node.content.getbuffer())
                mode = stat.S_IFREG | 0o666
            else:
                size = 0
                mode = stat.S_IFDIR | 0o777
            return MemoryPathIO.Stats(
                size,
                node.ctime,
                node.mtime,
                1,
                mode,
            ) 
开发者ID:aio-libs,项目名称:aioftp,代码行数:20,代码来源:pathio.py

示例12: getattr

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def getattr(self, path, fh=None):
        (uid, gid, pid) = fuse_get_context()
        entry = self._get_path_entry(path)

        if entry.is_directory():
            mode = (stat.S_IFDIR | PERMISSION_ALL_READ)
            nlink = 2
        else:
            mode = (stat.S_IFREG | PERMISSION_ALL_READ)
            nlink = 1

        return {
            "st_atime": unixtimestamp(entry.get_si_accessed_timestamp()),
            "st_ctime": unixtimestamp(entry.get_si_changed_timestamp()),
            "st_crtime": unixtimestamp(entry.get_si_created_timestamp()),
            "st_mtime": unixtimestamp(entry.get_si_modified_timestamp()),
            "st_size": entry.get_size(),
            "st_uid": uid,
            "st_gid": gid,
            "st_mode": mode,
            "st_nlink": nlink,
        } 
开发者ID:williballenthin,项目名称:python-ntfs,代码行数:24,代码来源:mount.py

示例13: stat

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def stat(self):
        if self.content_provider.get(self.path) is None:
            return SFTP_NO_SUCH_FILE

        mtime = calendar.timegm(datetime.now().timetuple())

        sftp_attrs = SFTPAttributes()
        sftp_attrs.st_size = self.content_provider.get_size(self.path)
        sftp_attrs.st_uid = 0
        sftp_attrs.st_gid = 0
        sftp_attrs.st_mode = (
            stat.S_IRWXO
            | stat.S_IRWXG
            | stat.S_IRWXU
            | (stat.S_IFDIR if self.content_provider.is_dir(self.path) else stat.S_IFREG)
        )
        sftp_attrs.st_atime = mtime
        sftp_attrs.st_mtime = mtime
        sftp_attrs.filename = posixpath.basename(self.path)
        return sftp_attrs 
开发者ID:ulope,项目名称:pytest-sftpserver,代码行数:22,代码来源:interface.py

示例14: _validate_keyfile_permissions

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def _validate_keyfile_permissions(self, path):
        """Check that file has permissions appropriate for a sensitive key

        Key files are extremely sensitive, they should be owned by the user
        who they relate to. They should be readable only (to avoid accidental
        changes). They should not be readable or writeable by any other user.

        :raises: KMIPSecretStoreError
        """
        expected = (stat.S_IRUSR | stat.S_IFREG)  # 0o100400
        st = os.stat(path)
        if st.st_mode != expected:
            raise KMIPSecretStoreError(
                u._('Bad key file permissions found, expected 400 '
                    'for path: {file_path}').format(file_path=path)
            ) 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:18,代码来源:kmip_secret_store.py

示例15: __init__

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFREG [as 别名]
def __init__(self, sn_api, sync_sec, ext, path='.'):
        self.item_manager = ItemManager(sn_api, ext)

        self.uid = os.getuid()
        self.gid = os.getgid()

        now = datetime.now().timestamp()
        self.dir_stat = dict(st_mode=(S_IFDIR | DIR_PERMISSIONS), st_ctime=now,
                             st_mtime=now, st_atime=now, st_nlink=2,
                             st_uid=self.uid, st_gid=self.gid)

        self.note_stat = dict(st_mode=(S_IFREG | FILE_PERMISSIONS), st_ctime=now,
                              st_mtime=now, st_atime=now, st_nlink=1,
                              st_uid=self.uid, st_gid=self.gid)

        self.sync_sec = sync_sec
        self.ext = ext
        self.run_sync = Event()
        self.stop_sync = Event()
        self.sync_thread = Thread(target=self._sync_thread) 
开发者ID:tannercollin,项目名称:standardnotes-fs,代码行数:22,代码来源:sn_fuse.py


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