8 import stat # for file properties
9 import os # for filesystem modes (O_RDONLY, etc)
10 import errno # for error number codes (ENOENT, etc)
11 # - note: these must be returned as negatives
13 fuse.fuse_python_api = (0, 2)
15 machines = ['moo17', 'remus']
16 realpath = "/home/machines/"
19 def dirFromList(list):
21 Return a properly formatted list of items suitable to a directory listing.
22 ['a', 'b', 'c'] => [('a', 0), ('b', 0), ('c', 0)]
24 return [(x, 0) for x in list]
28 Return the depth of a given path, zero-based from root ('/')
33 return path.count('/')
37 Return the slash-separated parts of a given path as a list
42 return path[1:].split('/')
58 return (self.st_mode, self.st_ino, self.st_dev, self.st_nlink, self.st_uid, self.st_gid, self.st_size, self.st_atime, self.st_mtime, self.st_ctime)
60 class ConsoleFS(Fuse):
64 def __init__(self, *args, **kw):
65 Fuse.__init__(self, *args, **kw)
66 print 'Init complete.'
68 def mirrorPath(self, path):
69 return realpath + "/".join(getParts(path)[1:])
71 def getattr(self, path):
73 - st_mode (protection bits)
74 - st_ino (inode number)
76 - st_nlink (number of hard links)
77 - st_uid (user ID of owner)
78 - st_gid (group ID of owner)
79 - st_size (size of file, in bytes)
80 - st_atime (time of most recent access)
81 - st_mtime (time of most recent content modification)
82 - st_ctime (platform dependent; time of most recent metadata change on Unix,
83 or the time of creation on Windows).
86 print "*** getattr: " + path
88 depth = getDepth(path)
89 parts = getParts(path)
93 st.st_mode = stat.S_IFDIR | 0755
96 if parts[-1] in machines:
97 st.st_mode = stat.S_IFDIR | 0755
101 elif depth == 2 and parts[-1] == '.k5login':
102 st.st_mode = stat.S_IFREG | 0444
106 st = os.lstat(self.mirrorPath(path))
109 def readdir(self, path, offset):
110 print '*** readdir', path, offset
112 for r in ['.', '..']+machines:
113 yield fuse.Direntry(r)
114 elif getDepth(path) == 1:
115 for r in set(os.listdir(self.mirrorPath(path)) + ['.k5login']):
116 yield fuse.Direntry(r)
118 for r in os.listdir(self.mirrorPath(path)):
119 yield fuse.Direntry(r)
121 def read ( self, path, length, offset ):
122 print '*** read', path, length, offset
124 if getDepth(path) < 2:
126 elif getParts(path)[1:] == ['.k5login']:
129 fname = self.mirrorPath(path)
130 if not os.path.isfile(fname):
135 return f.read(length)
137 if __name__ == '__main__':
139 ConsoleFS [mount_path]