You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
1.8 KiB

36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
  1. """Constants/functions for interpreting results of os.stat() and os.lstat().
  2. Suggested usage: from stat import *
  3. """
  4. # Indices for stat struct members in the tuple returned by os.stat()
  5. ST_MODE = 0
  6. ST_INO = 1
  7. ST_DEV = 2
  8. ST_NLINK = 3
  9. ST_UID = 4
  10. ST_GID = 5
  11. ST_SIZE = 6
  12. ST_ATIME = 7
  13. ST_MTIME = 8
  14. ST_CTIME = 9
  15. # Extract bits from the mode
  16. def S_IMODE(mode):
  17. return mode & 07777
  18. def S_IFMT(mode):
  19. return mode & 0170000
  20. # Constants used as S_IFMT() for various file types
  21. # (not all are implemented on all systems)
  22. S_IFDIR = 0040000
  23. S_IFCHR = 0020000
  24. S_IFBLK = 0060000
  25. S_IFREG = 0100000
  26. S_IFIFO = 0010000
  27. S_IFLNK = 0120000
  28. S_IFSOCK = 0140000
  29. # Functions to test for each file type
  30. def S_ISDIR(mode):
  31. return S_IFMT(mode) == S_IFDIR
  32. def S_ISCHR(mode):
  33. return S_IFMT(mode) == S_IFCHR
  34. def S_ISBLK(mode):
  35. return S_IFMT(mode) == S_IFBLK
  36. def S_ISREG(mode):
  37. return S_IFMT(mode) == S_IFREG
  38. def S_ISFIFO(mode):
  39. return S_IFMT(mode) == S_IFIFO
  40. def S_ISLNK(mode):
  41. return S_IFMT(mode) == S_IFLNK
  42. def S_ISSOCK(mode):
  43. return S_IFMT(mode) == S_IFSOCK
  44. # Names for permission bits
  45. S_ISUID = 04000
  46. S_ISGID = 02000
  47. S_ENFMT = S_ISGID
  48. S_ISVTX = 01000
  49. S_IREAD = 00400
  50. S_IWRITE = 00200
  51. S_IEXEC = 00100
  52. S_IRWXU = 00700
  53. S_IRUSR = 00400
  54. S_IWUSR = 00200
  55. S_IXUSR = 00100
  56. S_IRWXG = 00070
  57. S_IRGRP = 00040
  58. S_IWGRP = 00020
  59. S_IXGRP = 00010
  60. S_IRWXO = 00007
  61. S_IROTH = 00004
  62. S_IWOTH = 00002
  63. S_IXOTH = 00001
  64. # Names for file flags
  65. UF_NODUMP = 0x00000001
  66. UF_IMMUTABLE = 0x00000002
  67. UF_APPEND = 0x00000004
  68. UF_OPAQUE = 0x00000008
  69. UF_NOUNLINK = 0x00000010
  70. UF_COMPRESSED = 0x00000020 # OS X: file is hfs-compressed
  71. UF_HIDDEN = 0x00008000 # OS X: file should not be displayed
  72. SF_ARCHIVED = 0x00010000
  73. SF_IMMUTABLE = 0x00020000
  74. SF_APPEND = 0x00040000
  75. SF_NOUNLINK = 0x00100000
  76. SF_SNAPSHOT = 0x00200000