當前位置: 首頁>>代碼示例>>Python>>正文


Python stat.S_IFMT屬性代碼示例

本文整理匯總了Python中stat.S_IFMT屬性的典型用法代碼示例。如果您正苦於以下問題:Python stat.S_IFMT屬性的具體用法?Python stat.S_IFMT怎麽用?Python stat.S_IFMT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在stat的用法示例。


在下文中一共展示了stat.S_IFMT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: assertS_IS

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def assertS_IS(self, name, mode):
        # test format, lstrip is for S_IFIFO
        fmt = getattr(stat, "S_IF" + name.lstrip("F"))
        self.assertEqual(stat.S_IFMT(mode), fmt)
        # test that just one function returns true
        testname = "S_IS" + name
        for funcname in self.format_funcs:
            func = getattr(stat, funcname, None)
            if func is None:
                if funcname == testname:
                    raise ValueError(funcname)
                continue
            if funcname == testname:
                self.assertTrue(func(mode))
            else:
                self.assertFalse(func(mode)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_stat.py

示例2: mode_filetype

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def mode_filetype(mode):
    mode = stat.S_IFMT(mode)
    dic = {
            stat.S_ISFIFO: "fifo file",
            stat.S_ISCHR: "character device",
            stat.S_ISDIR: "directory",
            stat.S_ISBLK: "block device",
            stat.S_ISREG: "regular file",
            stat.S_ISLNK: "symbolic link",
            stat.S_ISSOCK: "socket",
            stat.S_ISDOOR: "door",
            }
    for test_func, name in dic.items():
        if test_func(mode):
            return name
    return "???" 
開發者ID:nil0x42,項目名稱:phpsploit,代碼行數:18,代碼來源:plugin.py

示例3: __new

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def __new(cls, name, path, st):

        dirname, filename = os.path.split(name)
        mode = st.st_mode
        ifmt = S_IFMT(mode)
        inode = st.st_ino
        dev = st.st_dev
        try:
            mtime = st.st_mtime_ns
        except AttributeError:
            mtime = st.st_mtime
        size = st.st_size
        fileid = (ifmt, size)

        global _counter
        _counter += 1

        new = super(FileInfo, cls).__new__
        return new(cls, _counter, fileid, path, filename, dirname, mode, inode,
                   dev, mtime, size) 
開發者ID:deplicate,項目名稱:deplicate,代碼行數:22,代碼來源:structs.py

示例4: test_unix_nomode_dir

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def test_unix_nomode_dir(self):

        perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IROTH | stat.S_IRGRP
        stamp = time_ns()
        inode = self.db.rowid("INSERT INTO inodes (mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) "
                              "VALUES (?,?,?,?,?,?,?)",
                              (perms, os.getuid(), os.getgid(), stamp, stamp, stamp, 1))
        inode2 = self.db.rowid("INSERT INTO inodes (mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) "
                              "VALUES (?,?,?,?,?,?,?)",
                              (perms | stat.S_IFREG, os.getuid(), os.getgid(), stamp,
                               stamp, stamp, 1))

        self._link(b'test-entry', inode)
        self._link(b'subentry', inode2, inode)

        self.assert_fsck(self.fsck.check_unix)

        newmode = self.db.get_val('SELECT mode FROM inodes WHERE id=?', (inode,))
        self.assertEqual(stat.S_IMODE(newmode), perms)
        self.assertEqual(stat.S_IFMT(newmode), stat.S_IFDIR) 
開發者ID:s3ql,項目名稱:s3ql,代碼行數:22,代碼來源:t3_fsck.py

示例5: _sig

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def _sig(st):
    return (stat.S_IFMT(st.st_mode),
            st.st_size,
            st.st_mtime) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:6,代碼來源:filecmp.py

示例6: test_mode

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def test_mode(self):
        with open(TESTFN, 'w'):
            pass
        if os.name == 'posix':
            os.chmod(TESTFN, 0o700)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IMODE(st_mode),
                             stat.S_IRWXU)

            os.chmod(TESTFN, 0o070)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IMODE(st_mode),
                             stat.S_IRWXG)

            os.chmod(TESTFN, 0o007)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IMODE(st_mode),
                             stat.S_IRWXO)

            os.chmod(TESTFN, 0o444)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IMODE(st_mode), 0o444)
        else:
            os.chmod(TESTFN, 0o700)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IFMT(st_mode),
                             stat.S_IFREG) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:34,代碼來源:test_stat.py

示例7: is_device

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def is_device(mode):
    mode = stat.S_IFMT(mode)
    return stat.S_ISCHR(mode) or stat.S_ISBLK(mode) 
開發者ID:nil0x42,項目名稱:phpsploit,代碼行數:5,代碼來源:plugin.py

示例8: _filecheck

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def _filecheck(fileinfo, minsize, maxsize, included_match, excluded_match,
               scanempties, scansystem, scanarchived, scanhidden):

    _sizecheck(fileinfo.size, minsize, maxsize, scanempties)
    _rulecheck(fileinfo.path, included_match, excluded_match)
    _attrcheck(fileinfo.path, scansystem, scanarchived, scanhidden)

    return S_IFMT(fileinfo.mode), fileinfo.size 
開發者ID:deplicate,項目名稱:deplicate,代碼行數:10,代碼來源:core.py

示例9: write

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def write(self, filename, arcname=None, compress_type=None):
        with open(filename, 'rb') as f:
            st = os.fstat(f.fileno())
            data = f.read()

        zinfo = ZipInfo(arcname or filename, date_time=get_zipinfo_datetime(st.st_mtime))
        zinfo.external_attr = (stat.S_IMODE(st.st_mode) | stat.S_IFMT(st.st_mode)) << 16
        zinfo.compress_type = ZIP_DEFLATED
        self.writestr(zinfo, data, compress_type) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:11,代碼來源:wheelfile.py

示例10: _sig

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def _sig(st):
        return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime) 
開發者ID:RhetTbull,項目名稱:osxphotos,代碼行數:4,代碼來源:fileutil.py

示例11: cal_mode

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def cal_mode(mode):
    if stat.S_ISLNK(mode):
        return stat.S_IFLNK
    elif stat.S_ISDIR(mode):
        return stat.S_IFDIR
    elif stat.S_IFMT(mode) == S_IFGITLINK:
        return S_IFGITLINK
    ret = stat.S_IFREG | 0o644
    ret |= (mode & 0o111)
    return ret 
開發者ID:lizherui,項目名稱:git-in-python,代碼行數:12,代碼來源:utils.py

示例12: phase2

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def phase2(self): # Distinguish files, directories, funnies
        self.common_dirs = []
        self.common_files = []
        self.common_funny = []

        for x in self.common:
            a_path = os.path.join(self.left, x)
            b_path = os.path.join(self.right, x)

            ok = 1
            try:
                a_stat = os.stat(a_path)
            except OSError as why:
                # print('Can\'t stat', a_path, ':', why.args[1])
                ok = 0
            try:
                b_stat = os.stat(b_path)
            except OSError as why:
                # print('Can\'t stat', b_path, ':', why.args[1])
                ok = 0

            if ok:
                a_type = stat.S_IFMT(a_stat.st_mode)
                b_type = stat.S_IFMT(b_stat.st_mode)
                if a_type != b_type:
                    self.common_funny.append(x)
                elif stat.S_ISDIR(a_type):
                    self.common_dirs.append(x)
                elif stat.S_ISREG(a_type):
                    self.common_files.append(x)
                else:
                    self.common_funny.append(x)
            else:
                self.common_funny.append(x) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:36,代碼來源:filecmp.py

示例13: get_file_info

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def get_file_info(system, path, verbose=False):
    fullpath = get_fullpath(system, path)
    if fullpath == IO_ERROR:
        return IO_ERROR
    
    result = {}    
    if system.startswith('/'): # local or sub
        if can_read(system, path):
            # TODO platform-specific
            stats = os.stat(fullpath)
            stm = stats.st_mode
            result['type'] = get_file_type_char(stat.S_IFMT(stm))
            result['permissions'] = '%o' % (stat.S_IMODE(stm))
            result['UID'] = stats[stat.ST_UID]
            result['GID'] = stats[stat.ST_GID]
            result['ATIME'] = stats[stat.ST_ATIME]
            result['MTIME'] = stats[stat.ST_MTIME]
            result['CTIME'] = stats[stat.ST_CTIME] # actually mtime on UNIX, TODO
        else:
            if verbose:
                log.info('File \'%s\' is not accessible.' % (fullpath))
            result['type'] = None
            result['permissions'] =  None
            result['UID'] = None
            result['GID'] = None
            result['ATIME'] = None
            result['MTIME'] = None
            result['CTIME'] = None
        return result

    else: # SSH/FTP/TFTP/HTTP
        # TODO NOT IMPLEMENTED
        return IO_ERROR 
開發者ID:lightfaith,項目名稱:locasploit,代碼行數:35,代碼來源:io.py

示例14: path_mode

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def path_mode(self, path):
		if not self.path_mod.exists(path):
			return 0
		return stat.S_IFMT(self.stat(path).st_mode) 
開發者ID:rsmusllp,項目名稱:king-phisher-plugins,代碼行數:6,代碼來源:directory.py

示例15: write

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFMT [as 別名]
def write(self, filename, arcname=None, compress_type=None):
        with open(filename, 'rb') as f:
            st = os.fstat(f.fileno())
            data = f.read()

        zinfo = ZipInfo(arcname or filename, date_time=get_zipinfo_datetime(st.st_mtime))
        zinfo.external_attr = (stat.S_IMODE(st.st_mode) | stat.S_IFMT(st.st_mode)) << 16
        zinfo.compress_type = compress_type or self.compression
        self.writestr(zinfo, data, compress_type) 
開發者ID:ali5h,項目名稱:rules_pip,代碼行數:11,代碼來源:wheelfile.py


注:本文中的stat.S_IFMT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。