
On Mon, Jan 11, 2016 at 1:02 PM, Ram Rachum <ram@rachum.com> wrote:
I spent some time thinking about this. I come up with a big and impressive API, then figured it's overkill, shelved it and made a simpler one :)
Here's my new preferred API. Assume that `path` is a `pathlib.Path` object.
Checking the chmod of the file: int(path.chmod) # Get an int 393 which in octal is 0o611 oct(path.chmod) # Get a string '0o611' str(path.chmod) # Get a string 'rw-r--r--' repr(path.chmod) # Get a string '<Chmod: rw-r--r-- / 0o611>
Modifying the chmod of the file: path.chmod(0o611) # Set chmod to 0o611 (for backward compatibility) path.chmod = 0o611 # Set chmod to 0o611 path.chmod = 393 # Set chmod to 0o611, which is 393 in decimal path.chmod = other_path.chmod # Set chmod to be the same as that of some other file path.chmod = 'rw-r--r--' # Set chmod to 0o611 path.chmod += '--x--x--x' # Add execute permission to everyone path.chmod -= '----rwx' # Remove all permissions from others
I've chosen += and -=, despite the fact they're not set operations, because Python doesn't have __inand__. On an unrelated note, maybe we should have __inand__? (I mean x ^~= y)
What do you think?
There is only one way...? ;) My proposal (used for some time in few private projects, but extracted as standalone few days ago): https://github.com/msztolcman/fileperms -- Marcin Sztolcman :: http://urzenia.net/ :: http://sztolcman.eu/