[svn r58375] some updates on the filesystem front

--HG--
branch : trunk
This commit is contained in:
hpk 2008-09-23 12:41:22 +02:00
parent 863fff7042
commit 0974aa784a
2 changed files with 94 additions and 1 deletions

79
py/doc/draft_pyfs Normal file
View File

@ -0,0 +1,79 @@
Let's do a walk through a memory filesystem.
.. >>> import py
working with directories
---------------------------------
Let's create some directories and list them from memory::
>>> fs = py.fs.MemoryFS()
>>> fs.mkdir("x")
>>> fs.mkdir("y")
>>> fs.listdir()
['x', 'y']
Creating, removing and reading files
---------------------------------------------
>>> f = fs.open('x/file', 'w')
>>> f.write("hello world")
>>> f.close()
>>> fs.listdir("x")
['file']
>>> f = fs.open("x/file", 'r')
>>> f.readlines()
['hello world']
>>> f.seek(6)
>>> f.read(3)
"wor"
>>> f.read()
"ld"
>>> f.close()
>>> fs.remove("y")
>>> fs.listdir()
['x']
>>> fs.remove("non-existent")
py.error.ENOENT
stat / checking for meta information
---------------------------------------
>>> stat = memory.stat("x")
>>> stat.isdir()
True
>>> stat.isfile()
False
>>> stat.exists()
True
>>> stat.islink()
False
Linking to other objects
--------------------------------------------------------
First an example how to link internally, i.e. within the
filesystem.
>>> fs.link("newitem", "x")
>>> fs.stat("newitem").islink()
True
>>> fs.stat("newitem").isfile()
True
>>> fs.remove("newitem") # only deletes the link itself
>>> fs.stat("x").exists()
cross-filesystem references
---------------------------------
>>> otherfs = py.fs.MemoryFS()
XXX
>>> fs.setproxy("newitem", otherfs, "otheritem")
>>> fs.stat("newitem").exists()
False
>>> otherfs.mkdir("otheritem")

View File

@ -90,7 +90,7 @@ decreased considerably.
Refactor path implementations to use a Filesystem Abstraction
=============================================================
It seems like a good idea to refactor all python implementations to
It seems like a good idea to refactor all `py.path`_ Path implementations to
use an internal Filesystem abstraction. The current code base
would be transformed to have Filesystem implementations for e.g.
local, subversion and subversion "working copy" filesystems. Today
@ -110,6 +110,20 @@ even become interesting to think about interfacing to
`reiserfs v4 features`_ at the Filesystem level but that
is a can of subsequent worms).
Also interesting to check out is Will McGugan's work on
his `fs package`_.
I think the main question is what the very fundamental
filesystem API should look like. Here are some doctests
on how a `draft py.fs`_ could look like. There also
is Matthew Scotts `dictproxy patch`_ which adds
``py.path.dict`` and ``py.path.proxy``.
.. _`dictproxy patch`: http://codespeak.net/pipermail/py-dev/attachments/20050128/d9595512/virtual1-0001.bin
.. _`draft py.fs`: draft_pyfs
.. _`py.path`: http://codespeak.net/py/dist/path.html
.. _`fs package`: http://www.willmcgugan.com/2008/09/21/announcing-fs-010-a-python-file-system/#comment-60276
.. _`memoryfs`: http://codespeak.net/svn/user/arigo/hack/pyfuse/memoryfs.py
.. _`dictfs`: http://codespeak.net/pipermail/py-dev/2005-January/000191.html
.. _`pylufs`: http://codespeak.net/svn/user/arigo/hack/pylufs/