Python stat.S_IFMT Examples
The following are 30
code examples of stat.S_IFMT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
stat
, or try the search function
.
Example #1
Source File: test_stat.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #2
Source File: test_stat.py From ironpython2 with Apache License 2.0 | 6 votes |
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))
Example #3
Source File: plugin.py From phpsploit with GNU General Public License v3.0 | 6 votes |
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 "???"
Example #4
Source File: test_stat.py From oss-ftp with MIT License | 6 votes |
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))
Example #5
Source File: structs.py From deplicate with MIT License | 6 votes |
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)
Example #6
Source File: t3_fsck.py From s3ql with GNU General Public License v3.0 | 6 votes |
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)
Example #7
Source File: filecmp.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #8
Source File: osfs.py From pyfilesystem2 with MIT License | 5 votes |
def _get_type_from_stat(cls, _stat): # type: (os.stat_result) -> ResourceType """Get the resource type from an `os.stat_result` object. """ st_mode = _stat.st_mode st_type = stat.S_IFMT(st_mode) return cls.STAT_TO_RESOURCE_TYPE.get(st_type, ResourceType.unknown) # -------------------------------------------------------- # Required Methods # --------------------------------------------------------
Example #9
Source File: filecmp.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #10
Source File: filecmp.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #11
Source File: filecmp.py From canape with GNU General Public License v3.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #12
Source File: filecmp.py From android_universal with MIT License | 5 votes |
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)
Example #13
Source File: filecmp.py From android_universal with MIT License | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #14
Source File: filecmp.py From medicare-demo with Apache License 2.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #15
Source File: filecmp.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #16
Source File: target.py From law with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _s_isdir(self, st_mode): # some WLCG file protocols do not return standard st_mode values in stat requests, # e.g. srm returns file type bits 0o50000 for directories instead of 0o40000, # these differences are rather distinct and can be taken into account here, # see http://man7.org/linux/man-pages/man7/inode.7.html for info on st_mode values return stat.S_ISDIR(st_mode) or stat.S_IFMT(st_mode) == 0o50000 # try to set the default fs instance
Example #17
Source File: wheelfile.py From coffeegrindsize with MIT License | 5 votes |
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)
Example #18
Source File: filesystem.py From oswatcher with GNU General Public License v3.0 | 5 votes |
def inode_type(self): return InodeType(stat.S_IFMT(self.status['st_mode']))
Example #19
Source File: filecmp.py From unity-python with MIT License | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #20
Source File: builder.py From shiv with BSD 2-Clause "Simplified" License | 5 votes |
def _write_to_zipapp( arhive: zipfile.ZipFile, arcname: str, data_source: Union[Path, bytes], date_time: Tuple[int, int, int, int, int, int], compression: int, contents_hash: hashlib.sha3_256, ) -> None: """Write a file or a bytestring to a ZipFile as a separate entry and update contents_hash as a side effect The approach is borrowed from 'wheel' code. """ if isinstance(data_source, Path): with data_source.open("rb") as f: data = f.read() st: Optional[os.stat_result] = os.fstat(f.fileno()) else: data = data_source st = None contents_hash.update(data) zinfo = zipfile.ZipInfo(arcname, date_time=date_time) zinfo.compress_type = compression if st is not None: zinfo.external_attr = (stat.S_IMODE(st.st_mode) | stat.S_IFMT(st.st_mode)) << 16 arhive.writestr(zinfo, data)
Example #21
Source File: py7zr.py From py7zr with GNU Lesser General Public License v2.1 | 5 votes |
def st_fmt(self) -> Optional[int]: """ :return: Return the portion of the file mode that describes the file type """ e = self._get_unix_extension() if e is not None: return stat.S_IFMT(e) return None
Example #22
Source File: filecmp.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #23
Source File: t3_fsck.py From s3ql with GNU General Public License v3.0 | 5 votes |
def test_unix_nomode_reg(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)) self._link(b'test-entry', 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_IFREG)
Example #24
Source File: filecmp.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #25
Source File: filecmp.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #26
Source File: filecmp.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #27
Source File: sftpstorage.py From django-storages with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _isdir_attr(self, item): # Return whether an item in sftp.listdir_attr results is a directory if item.st_mode is not None: return stat.S_IFMT(item.st_mode) == stat.S_IFDIR else: return False
Example #28
Source File: filecmp.py From datafari with Apache License 2.0 | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)
Example #29
Source File: test_stat.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #30
Source File: filecmp.py From meddle with MIT License | 5 votes |
def _sig(st): return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime)