All pastes #431303 Raw Edit

Stuff

public python v1 · immutable
·published 2007-04-09 16:09 UTC
rendered paste body
#!/usr/bin/pythonfrom fuse import Fusefrom time import timeimport stat    # for file propertiesimport os      # for filesystem modes (O_RDONLY, etc)import errno   # for error number codes (ENOENT, etc)               # - note: these must be returned as negativesdef dirFromList(list):    """    Return a properly formatted list of items suitable to a directory listing.    ['a', 'b', 'c'] => [('a', 0), ('b', 0), ('c', 0)]    """    return [(x, 0) for x in list]def getDepth(path):    """    Return the depth of a given path, zero-based from root ('/')    """    if path == '/':        return 0    else:        return path.count('/')def getParts(path):    """    Return the slash-separated parts of a given path as a list    """    if path == '/':        return ['/']    else:        return path.split('/')class NullFS(Fuse):    """    """    basepath = ""    fds = {}    def __init__(self, *args, **kw):        Fuse.__init__(self, *args, **kw)	self.basepath = self.optlist[0]	print self.basepath        print 'Init complete.'    def getattr(self, path):        """        - st_mode (protection bits)        - st_ino (inode number)        - st_dev (device)        - st_nlink (number of hard links)        - st_uid (user ID of owner)        - st_gid (group ID of owner)        - st_size (size of file, in bytes)        - st_atime (time of most recent access)        - st_mtime (time of most recent content modification)        - st_ctime (platform dependent; time of most recent metadata change on Unix,                    or the time of creation on Windows).        """        #print '*** getattr', path        depth = getDepth(path) # depth of path, zero-based from root        pathparts = getParts(path) # the actual parts of the path	return (os.lstat(self.basepath+path))        #return -errno.ENOSYS    def getdir(self, path):	filelist = []	for file in (os.listdir(self.basepath+path)):		filelist.append((file, 0))	return filelist        #print '*** getdir', path        #-errno.ENOSYS    def mythread ( self ):        print '*** mythread'        -errno.ENOSYS    def chmod ( self, path, mode ):        print '*** chmod', path, oct(mode)        -errno.ENOSYS    def chown ( self, path, uid, gid ):        print '*** chown', path, uid, gid        -errno.ENOSYS    def fsync ( self, path, isFsyncFile ):        print '*** fsync', path, isFsyncFile        -errno.ENOSYS    def link ( self, targetPath, linkPath ):        print '*** link', targetPath, linkPath        -errno.ENOSYS    def mkdir ( self, path, mode ):        print '*** mkdir', path, oct(mode)        -errno.ENOSYS    def mknod ( self, path, mode, dev ):        print '*** mknod', path, oct(mode), dev        -errno.ENOSYS    def open ( self, path, flags ):        print '*** open', path, flags	fd = os.open(self.basepath+path,flags)	fh = os.fdopen(fd)	if (fh > 0):		self.fds[path] = fh		return 0	else:		return -errno.ENOSYS    def read ( self, path, length, offset ):        print '*** read', path, length, offset	self.fds[path].seek(offset)	return (self.fds[path].read(length))    def readlink ( self, path ):        print '*** readlink', path        -errno.ENOSYS    def release ( self, path, flags ):        print '*** release', path, flags	self.fds[path].close()	del self.fds[path]        -errno.ENOSYS    def rename ( self, oldPath, newPath ):        print '*** rename', oldPath, newPath        -errno.ENOSYS    def rmdir ( self, path ):        print '*** rmdir', path        -errno.ENOSYS    def statfs ( self ):        print '*** statfs'        -errno.ENOSYS    def symlink ( self, targetPath, linkPath ):        print '*** symlink', targetPath, linkPath        -errno.ENOSYS    def truncate ( self, path, size ):        print '*** truncate', path, size        -errno.ENOSYS    def unlink ( self, path ):        print '*** unlink', path        -errno.ENOSYS    def utime ( self, path, times ):        print '*** utime', path, times        -errno.ENOSYS    def write ( self, path, buf, offset ):        print '*** write', path, buf, offset        -errno.ENOSYSif __name__ == '__main__':    fs = NullFS()    fs.flags = 0    fs.multithreaded = 0    fs.main()