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 share.

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()
13.10.2009 16:46:07
If you try chmod from an OS X command window, does it work? If not, it might be a limitation of the networking interoperation.
Mark Ransom 13.10.2009 16:59:16

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.

13.10.2009 17:07:14