oschmod
Python chmod that works on Windows and Linux
With oschmod, on Windows and Linux, you can use stat modes (permissions) for files and directories. Python's os.chmod()
does not work properly on Windows, only setting the read-only bit.
For example, on Linux, you can easily give a file owner read, write, and execute permissions, and deny the group and others any permissions (i.e., equivalent of 700
). You can do it like:
import os
import stat
os.chmod('myfile', stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
Running the same command on Windows does not achieve the same results, such as the group and others are not denied permissions.
However, using oschmod you can use the same command on Windows or Linux and get the same results:
import oschmod
oschmod.set_mode('myfile', stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
Installation
$ pip install oschmod