csm-adapt / sagittariidae

Data and file management interface.
0 stars 1 forks source link

Utility functions to check the state of files and directories #19

Closed bkappes closed 8 years ago

bkappes commented 8 years ago

The construct open('filename').close() checks both the existence and readability of a file, but using this construct, these two properties become inseparable; filename may exist, but not be readable due to file permission issues. These utility functions address that by separating existence from readability and writability.

sinistral commented 8 years ago

The interface feels a bit cumbersome ... What if the module simply exposed exists(), isfile(), isdir(), isreadable() and iswritable() and allowed the user to combine them to achieve the aggregate checks? It simplifies the interface (since we don't have to handle every permutation) without losing the clarity that hiding the details of F_* brings.

An aside: consider using squash or fixup to collapse these into a single commit. I don't think there's much value to be gained from merging this feature as multiple commits.

bkappes commented 8 years ago

Good suggestion. Done -- both the condensed interface and the commit cleanup. Hopefully I did that correctly.

Consider the following use case:

exists = "/path/to/file/that/exists.txt"
nope="/path/to/file/that/does_not.txt"

Where exists is readable/writable by the user. Obviously, isreadable(exists) should return True and isreadable(nope) should return False.

As it is currently implemented, iswritable(exists) would return True, as it should, but iswritable(nope) would return False, because nope doesn't exist. I think iswritable(nope) should return True because it could be written. Do you agree?