File Explorer

/proc/thread-self/root/proc/thread-self/root/proc/self/root/usr/lib64/python3.9

This explorer reads the filesystem of the server it runs on, so /workspace/user isn't present here. Browsing and the terminal still work against this server's own disk from /.

stat.py5.4 KB · 196 lines
"""Constants/functions for interpreting results of os.stat() and os.lstat(). Suggested usage: from stat import *""" # Indices for stat struct members in the tuple returned by os.stat() ST_MODE  = 0ST_INO   = 1ST_DEV   = 2ST_NLINK = 3ST_UID   = 4ST_GID   = 5ST_SIZE  = 6ST_ATIME = 7ST_MTIME = 8ST_CTIME = 9 # Extract bits from the mode def S_IMODE(mode):    """Return the portion of the file's mode that can be set by    os.chmod().    """    return mode & 0o7777 def S_IFMT(mode):    """Return the portion of the file's mode that describes the    file type.    """    return mode & 0o170000 # Constants used as S_IFMT() for various file types# (not all are implemented on all systems) S_IFDIR  = 0o040000  # directoryS_IFCHR  = 0o020000  # character deviceS_IFBLK  = 0o060000  # block deviceS_IFREG  = 0o100000  # regular fileS_IFIFO  = 0o010000  # fifo (named pipe)S_IFLNK  = 0o120000  # symbolic linkS_IFSOCK = 0o140000  # socket file# Fallbacks for uncommon platform-specific constantsS_IFDOOR = 0S_IFPORT = 0S_IFWHT = 0 # Functions to test for each file type def S_ISDIR(mode):    """Return True if mode is from a directory."""    return S_IFMT(mode) == S_IFDIR def S_ISCHR(mode):    """Return True if mode is from a character special device file."""    return S_IFMT(mode) == S_IFCHR def S_ISBLK(mode):    """Return True if mode is from a block special device file."""    return S_IFMT(mode) == S_IFBLK def S_ISREG(mode):    """Return True if mode is from a regular file."""    return S_IFMT(mode) == S_IFREG def S_ISFIFO(mode):    """Return True if mode is from a FIFO (named pipe)."""    return S_IFMT(mode) == S_IFIFO def S_ISLNK(mode):    """Return True if mode is from a symbolic link."""    return S_IFMT(mode) == S_IFLNK def S_ISSOCK(mode):    """Return True if mode is from a socket."""    return S_IFMT(mode) == S_IFSOCK def S_ISDOOR(mode):    """Return True if mode is from a door."""    return False def S_ISPORT(mode):    """Return True if mode is from an event port."""    return False def S_ISWHT(mode):    """Return True if mode is from a whiteout."""    return False # Names for permission bits S_ISUID = 0o4000  # set UID bitS_ISGID = 0o2000  # set GID bitS_ENFMT = S_ISGID # file locking enforcementS_ISVTX = 0o1000  # sticky bitS_IREAD = 0o0400  # Unix V7 synonym for S_IRUSRS_IWRITE = 0o0200 # Unix V7 synonym for S_IWUSRS_IEXEC = 0o0100  # Unix V7 synonym for S_IXUSRS_IRWXU = 0o0700  # mask for owner permissionsS_IRUSR = 0o0400  # read by ownerS_IWUSR = 0o0200  # write by ownerS_IXUSR = 0o0100  # execute by ownerS_IRWXG = 0o0070  # mask for group permissionsS_IRGRP = 0o0040  # read by groupS_IWGRP = 0o0020  # write by groupS_IXGRP = 0o0010  # execute by groupS_IRWXO = 0o0007  # mask for others (not in group) permissionsS_IROTH = 0o0004  # read by othersS_IWOTH = 0o0002  # write by othersS_IXOTH = 0o0001  # execute by others # Names for file flags UF_NODUMP    = 0x00000001  # do not dump fileUF_IMMUTABLE = 0x00000002  # file may not be changedUF_APPEND    = 0x00000004  # file may only be appended toUF_OPAQUE    = 0x00000008  # directory is opaque when viewed through a union stackUF_NOUNLINK  = 0x00000010  # file may not be renamed or deletedUF_COMPRESSED = 0x00000020 # OS X: file is hfs-compressedUF_HIDDEN    = 0x00008000  # OS X: file should not be displayedSF_ARCHIVED  = 0x00010000  # file may be archivedSF_IMMUTABLE = 0x00020000  # file may not be changedSF_APPEND    = 0x00040000  # file may only be appended toSF_NOUNLINK  = 0x00100000  # file may not be renamed or deletedSF_SNAPSHOT  = 0x00200000  # file is a snapshot file  _filemode_table = (    ((S_IFLNK,         "l"),     (S_IFSOCK,        "s"),  # Must appear before IFREG and IFDIR as IFSOCK == IFREG | IFDIR     (S_IFREG,         "-"),     (S_IFBLK,         "b"),     (S_IFDIR,         "d"),     (S_IFCHR,         "c"),     (S_IFIFO,         "p")),     ((S_IRUSR,         "r"),),    ((S_IWUSR,         "w"),),    ((S_IXUSR|S_ISUID, "s"),     (S_ISUID,         "S"),     (S_IXUSR,         "x")),     ((S_IRGRP,         "r"),),    ((S_IWGRP,         "w"),),    ((S_IXGRP|S_ISGID, "s"),     (S_ISGID,         "S"),     (S_IXGRP,         "x")),     ((S_IROTH,         "r"),),    ((S_IWOTH,         "w"),),    ((S_IXOTH|S_ISVTX, "t"),     (S_ISVTX,         "T"),     (S_IXOTH,         "x"))) def filemode(mode):    """Convert a file's mode to a string of the form '-rwxrwxrwx'."""    perm = []    for table in _filemode_table:        for bit, char in table:            if mode & bit == bit:                perm.append(char)                break        else:            perm.append("-")    return "".join(perm)  # Windows FILE_ATTRIBUTE constants for interpreting os.stat()'s# "st_file_attributes" member FILE_ATTRIBUTE_ARCHIVE = 32FILE_ATTRIBUTE_COMPRESSED = 2048FILE_ATTRIBUTE_DEVICE = 64FILE_ATTRIBUTE_DIRECTORY = 16FILE_ATTRIBUTE_ENCRYPTED = 16384FILE_ATTRIBUTE_HIDDEN = 2FILE_ATTRIBUTE_INTEGRITY_STREAM = 32768FILE_ATTRIBUTE_NORMAL = 128FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192FILE_ATTRIBUTE_NO_SCRUB_DATA = 131072FILE_ATTRIBUTE_OFFLINE = 4096FILE_ATTRIBUTE_READONLY = 1FILE_ATTRIBUTE_REPARSE_POINT = 1024FILE_ATTRIBUTE_SPARSE_FILE = 512FILE_ATTRIBUTE_SYSTEM = 4FILE_ATTRIBUTE_TEMPORARY = 256FILE_ATTRIBUTE_VIRTUAL = 65536  # If available, use C implementationtry:    from _stat import *except ImportError:    pass