[Gug-cvs] gug/fuse gugfs.py,NONE,1.1
Status: Planning
Brought to you by:
szferi
From: Gergo C. <cs...@us...> - 2007-05-14 08:18:49
|
Update of /cvsroot/gug/gug/fuse In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv15993/fuse Added Files: gugfs.py Log Message: Test implementation of gugfs-fuse --- NEW FILE: gugfs.py --- #!/usr/bin/env python from gug.common.config import Config, find_config_file from gug.client.storage import Storage from gug.common.exception import * import os, stat, errno # some spaghetti to make it usable without fuse-py being installed for i in True, False: try: import fuse from fuse import Fuse except ImportError: if i: try: import _find_fuse_parts except ImportError: pass else: raise if not hasattr(fuse, '__version__'): raise RuntimeError, \ "your fuse-py doesn't know of fuse.__version__, probably it's too old." # This setting is optional, but it ensures that this class will keep # working after a future API revision fuse.fuse_python_api = (0, 2) class MyStat(fuse.Stat): def __init__(self): self.st_mode = 0 self.st_ino = 0 self.st_dev = 0 self.st_nlink = 0 self.st_uid = 0 self.st_gid = 0 self.st_size = 0 self.st_atime = 0 self.st_mtime = 0 self.st_ctime = 0 class GugFS(Fuse): def __init__(self, *args, **kw): Fuse.__init__(self, *args, **kw) self.ncount = 0 def gisinit(self): config = Config(self.cmdline[0].clientconf) gis_peers = config.get_content("/ClientConfig/GISPeers/GIS") file("/tmp/gugfsgis", "w").write(str(gis_peers)) self.storage = Storage(gis_peers, False) def getattr(self, path): file("/tmp/gugfsgetattr", "a").write("%i %s\n" % (self.ncount, path)) st = MyStat() if path == '/': st.st_mode = stat.S_IFDIR | 0755 st.st_nlink = 2 else: file("/tmp/gugfsgetattr", "a").write("4: %i, %s\n" % (self.ncount, path)) xsts = self.storage.exists('/grid' + path) file("/tmp/gugfsgetattr", "a").write("5: %i, %s\n" % (self.ncount, str(xsts))) if not xsts: return -errno.ENOENT try: gugstat = self.storage.stat('/grid' + path) file("/tmp/gugfsgetattr", "a").write("6: %i %s\n" % (self.ncount, path)) except e: file("/tmp/gugfsgetattr", "a").write("7: %i %s\n" % (self.ncount, path) + "exception: " + str(e) + "\n") return -errno.ENOENT file("/tmp/gugfsgetattr", "a").write("8: %i %s\n" % (self.ncount, path) + "gugstat: " + str(gugstat) + "\n") st.st_mtime = int(gugstat['created']) st.st_ctime = int(gugstat['created']) if gugstat['dirlike']: st.st_mode = stat.S_IFDIR | 0755 st.st_nlink = 1 else: st.st_mode = stat.S_IFREG | 0444 st.st_nlink = 1 st.st_size = int(gugstat['size']) self.ncount += 1 return st def readdir(self, path, offset): file("/tmp/gugfsreaddir","a").write("%i %s\n" % (self.ncount, path)) self.ncount += 1 try: lfn = self.storage.glob("/grid" + path) except LFNNotFoundException, lfn: return except InvalidLFNException, lfn: return yield fuse.Direntry(".") yield fuse.Direntry("..") dirlen = len("/grid" + path) if path[-1:] != "/": dirlen += 1 for dir, lines in self.storage.ls("/grid" + path, False): for line in lines: fnam = line['lfn'][dirlen:] if line['dirlike']: file("/tmp/gugfsreaddir","a").write("dirlike: %s\n" % (str(fnam))) yield fuse.Direntry(str(fnam)) else: file("/tmp/gugfsreaddir","a").write("filelike: %s\n" % (str(fnam))) yield fuse.Direntry(str(fnam)) def unlink(self, path): file("/tmp/gugfsunlink", "a").write("%i %s\n" % (self.ncount, path)) self.ncount += 1 self.storage.rm("/grid" + path) def rmdir(self, path): file("/tmp/gugfsrmdir", "a").write("%i %s\n" % (self.ncount, path)) self.ncount += 1 self.storage.rmdir("/grid" + path) #def rename(self, path, path1): # os.rename("." + path, "." + path1) #def truncate(self, path, len): # f = open("." + path, "a") # f.truncate(len) # f.close() def mkdir(self, path, mode): file("/tmp/gugfsmkdir", "a").write("%i %s\n" % (self.ncount, path)) try: self.storage.mkdir("/grid" + path) except e: file("/tmp/gugfsmkdir", "a").write("%i %s\n" % (self.ncount, str(e))) self.ncount += 1 def main(): usage=""" Userspace GUG filesystem """ + Fuse.fusage server = GugFS(version="%prog " + fuse.__version__, usage=usage, dash_s_do='setsingle') cfgfile = find_config_file("client.conf") server.parser.add_option(mountopt="clientconf", metavar="PATH", default=cfgfile, help="Path of GUG Client config file [default: %default]") server.parse(errex=1) server.gisinit() server.main() if __name__ == '__main__': main() |