Python Virtual File System: A spike test

holger krekel pyth at devel.trillke.net
Wed Jun 12 08:20:15 EDT 2002


Hi Mike,

[you wrote]
> Purpose:
> 
> A class for representing file system paths which supports both 
> method-based operations, and abstraction through object encapsulation to 
> eventually allow for Virtual File System operations (for instance, 
> transparently accessing the contents of zip files).
> 
> Status:
> 
> An initial implementation (spike test) exploring the viability of the 
> approach.  Implementation provides:
> 
> 	equality testing
> 	parent/child/ancestor/descendent retrieval/testing
> 	filesystem-role testing (file/dir/root)
> 	root retrieval and root comparisons
> 	"walking" (callback-based recursive iteration)
> 	listing (returning Paths which include their parent directory)
> 	fragment determination (i.e. c:\\temp\\test -> "c:\\", "temp", "test"
> 	recursive directory-tree removal (including files)
> 	open( ) method for path specifiers

Interesting. I have written a similar 'filename' class. 
It is not based on the str-type but accepts strings in many places. 
Also the filename class offers all of the methods found in 'os' or 'os.path'
under the exact name. I think this is important to make using it easy. 
Many people already know and use the stdlib-methods.

One of the nice features is that you can do stuff like:

fn=filename('/usr/src')
cfilter=filters.OR(filters.hasext('.cpp'), filters.hasext('c'))
mfilter=filters.rmatch('.*/[Mm]akefile.*')
recursefilter=rignore('.*/CVS')

for makefiles, cppfiles in fn.filterwalk([mfilter,cfilter], recursefilter):
    # work with list of makefiles
    # work with cppfiles

'filterwalk' is a generator which honors a recursion filter and one or
more filename-filter.  It allows to recurse once and get back categories of files
(as lists). No further checking like 'islink' etc. needed. You makeup
your filters and call filterwalk and afterwards work with the lists.

> Future:
> 
> If there is interest, I am planning on creating a new SourceForge 
> project with the eventual goal of creating a virtual file system package 
> with a consistent interface to most of the major file-and-directory 
> systems (zip files, FTP sites, local file systems) and hooks for adding 
> new systems.

Having an abstraction for 'Names'/URLs and working from there would 
be very interesting IMO. At the moment we only work with (relatively
untyped) strings which places the burden of calling the right methods
(urllib/httplib/urllib2/os.path/ftplib/webdav...) on the programmer
(who just has a string).  

> Request:
> 
> If you're interested in working on such a project (or even using it), 
> let me know, so I can decide whether to devote any more resources to it.
> You can find the module here:
> 
> http://members.rogers.com/mcfletch/programming/filepath.py

i am interested but we should discuss if our approaches/viewpoints 
work well together :-) 

cheers,

    holger





More information about the Python-list mailing list