How do you make a shared network file read-only using Python?
Using Python, what's the correct way to set a file to be read-only when the file is located on a network share (being served from a Windows 2003 Server)?
I'm running Python 2.6.2 in OS X (10.6.1).
The following code throws an exception (as expected) when path is local, but os.chmod
appears to have no effect when path points to a Windows shar开发者_StackOverflowe.
import os, stat
path = '/Volumes/Temp/test.txt'
# Create a test file.
open(path, 'w').close()
# Make the file read-only.
os.chmod(path, stat.S_IREAD)
# Try writing to it again. This should fail.
open(path, 'w').close()
I am pretty sure you must have the proper settings on your local SAMBA server (/etc/samba/smb.conf) to make this behave the way you intend. There is many ways to go around permission checking if smb.conf isn't set correctly.
精彩评论