Pythonic filesystem abstractions: An overview of different filesystem(-like) APIs in Python and attempts for unifying them.
There's a lot of different filesystem(-like) APIs in Python. I intend to provide an overview of existing projects, their status and capabilities, and hopefully inspire you to work on improving things.
I intend to cover at least:
Spread all over the place, built-ins and miscellaneous stdlib
good idea, but don't use
limited-purpose reimplementation of part of twisted.vfs
async doesn't look like sync
Deferred not going to stdlib?
(for now) (but don't forget async)
(network still important)
Mock writing to /etc
See Petardfs for a generic FUSE fault injecting filesystem.
Not nice for unit tests, but maybe for system tests.
No .. from user
top = FilePath('toplevel') sub = top.child('foo') sub.createDirectory() p = sub.child('bar') with p.open('w') as f: f.write('foo bar\n')
f = self.fs.open("myfile")
implement needed part, KISS, croak on anything unwanted
wrap another implementation
p = self.fs.path("/my/safe/area") p = p.child(user_input)
self.fs = NoDotfilesFS(self.fs)
self.fs = ChrootFS( fs=self.fs, root="/my/safe/area", )
self.fs = AccessControlFS( fs=self.fs, acl=acl_rules, )
The path.py website at http://www.jorendorff.com/articles/python/path fails to load unless you do it on a full moon, in front of a mirror, and reload three times.
In the end, I don't think path.py is a suitable base for this:
It's probably a nice pragmatic helper, just not a good common API.
top = path('toplevel') sub = top / 'foo' sub.mkdir() p = sub / 'bar' with p.open('w') as f: f.write('foo bar\n')
POSIX: atomic replace of single-file
could do atomic-write-on-close
with self.fs.transact() as t: t.path("foo").rename("foo.old") with t.path("foo").open("w") as f: f.write("bar\n")