objectfs API

Note

The code documentation is in progress. Right now the best documentation is the code itself.

pyvfs.vfs – abstract VFS layer

Internal VFS protocol. You can use this module to build your own filesystems.

exception pyvfs.vfs.Edebug[source]
exception pyvfs.vfs.Eexist(target=None)[source]
exception pyvfs.vfs.Eperm[source]
class pyvfs.vfs.Inode(name, parent=None, mode=0, storage=None, **kwarg)[source]

VFS inode

create(name, mode=0, klass=None, **kwarg)[source]

Create a child in a directory

remove(inode)[source]

Remove a child from a directory

rename(old_name, new_name)[source]

Rename a child

class pyvfs.vfs.Storage(inode=<class 'pyvfs.vfs.Inode'>, **kwarg)[source]

High-level storage insterface. Implements a simple protocol for the file management and file lookup dictionary.

Should be provided with root ‘inode’ class on init. The ‘inode’ class MUST support the interface… that should be defined :)

create(name, parent, mode=0)[source]

Create an inode

register(inode)[source]

Register a new inode in the dictionary

unregister(inode)[source]

Remove an inode from the dictionary

pyvfs.utils – utility classes

Utility classes for VFS

class pyvfs.utils.Server(fs=None)[source]

The main interface to create and start a filesystem.

The filesystem will be exported with the protocol you will choose. Supported protocols now are 9p and fuse. For 9p you should have py9p installed, for fuse, respectively, fuse-python binding. With 9p you will be able to mount the FS with mount(8) or with any other 9p implementation:

mount -t 9p -o ro,port=10001 127.0.0.1 /mnt/debugfs

In the case of fuse protocol, the FS will be mounted immediately with the script startup. You can configure the behaviour with environment variables:

  • PYVFS_PROTO9p (default) or fuse

  • PYVFS_PORT – tcp port for TCP sockets and access mode for UNIX sockets (9p only, default: 10001)

  • PYVFS_ADDRESS – IPv4 address, use 0.0.0.0 to allow public access (9p only, default: 127.0.0.1)

  • PYVFS_MOUNTPOINT – the mountpoint (fuse only, default: ./mnt)

  • PYVFS_DEBUG – turn on stderr debug output of the FS protocol

  • PYVFS_LOG – create /log inode

  • PYVFS_ALLOW_ROOT – allow root to access the mountpoint (fuse only, default: False)

  • PYVFS_ALLOW_OTHER – allow other users to access the mountpoint, requires user_allow_other in /etc/fuse.conf (fuse only, default: False)

  • AUTHMODE – authentication mode for 9p, can be pki (9p only, default: none)

  • KEYFILES – map of user public key files (9p only, default: none)

Warning

No authentication for 9p is used in this library yet. Do not expose the socket to the public access unless you completely understand what are you doing.

The typical code should look like that:

from pyvfs.utils import Server

server = Server()
server.start()

To run server in the backgroung, use start(), in the foreground – run() method.

If you want to use some custom storage, you can derive a class from pyvfs.vfs.Storage, and use an instance of it as an argument in the Server constructor:

from somewhere import CustomStorage
from pyvfs.utils import Server

server = Server(CustomStorage())
server.start()
class pyvfs.utils.indexInode(name, parent=None, mode=0, storage=None, **kwarg)[source]

An inode that lists full storage file index. Can be used for debugging purposes.

class pyvfs.utils.logInode(name, parent, maxlen=30)[source]

Deque-based log file. Should be read-only on the filesystem. Can be used as a stream for Python logging.StreamHandler() objects. Stores maxlen of records, addition of records above maxlen at the same time discards discards old records.

flush()[source]

Does nothing.

write(value)[source]

Write bytes to file.

Return the number of bytes written.