Interesting to know that it's a more common pattern. I will have to think a bit on where that may go. I had always shot down any "value" with "it's just a thin transformation on top of path.join". (yay self-deprecation or something?)
>>> p = PurePath('/etc') >>> p PurePosixPath('/etc') >>> p / 'init.d' / 'apache2' PurePosixPath('/etc/init.d/apache2')
And yeah, this uses operator overload. However it does look quite nice.
with (Path.home() / '.config' / '1234.conf').open() as fd:
print('Hello', file=fd)
Granted, with / precedence you'll often need parens to group / before .You can also do this with PyFilesystem...
fs.gettext('/home/amyjess/stuff/foo.txt')
fs.settext('/home/amyjess/stuff/foo.txt', bar)
There are equivalent bytes methods.It basically mounts a dict on a filesystem, the exact opposite of what you want :)
The ansible setup module returns the system information in json, and if you mount it with the --realtime flag, when you open a "file" like ram for instance, ansible fetches the current value for you. That way you have your infrastructure mounted so to speak. Sort of a /proc filesystem for your linux infrastructure.
I never got further than a working poc though. It works, but there are some bugs and there is no regard for security.
This would insert "bar/baz.txt" from filesystem "foo" in to a template:
${.fs.foo.bar.baz.txt}
A while back, I had an idea for modelling a filesystem as a dict, so maybe this will inspire me to get off my ass and actually write it.
Basically, the idea is that this:
would be equivalent to this: I really want to implement that now.