コード例 #1
0
ファイル: sympafs.py プロジェクト: dnet/sympa-python-api
class SympaFS(LoggingMixIn, Operations):
    def __init__(self, url, email, passwd, mlist):
        self.sympa = Sympa(url)
        self.email = email
        self.passwd = passwd
        t = time()
        self.attr_cache = {'/': dict(st_mode=(S_IFDIR | READ_ONLY), st_nlink=2,
            st_ctime=t, st_mtime=t, st_atime=t)}
        self.list_cache = {}
        self.content_cache = {}
        self.sympa_login()
        self.mlist = self.sympa.lists[mlist]

    def __del__(self):
        if self.sympa is not None:
            self.sympa.log_out()

    def sympa_login(self):
        self.sympa.log_in(self.email, self.passwd)

    def getattr(self, path, fh=None):
        return self.attr_cache.get(path, self.query_attr(path))

    def query_attr(self, path):
        self.readdir(path.rsplit('/', 1)[0], None)
        try:
            return self.attr_cache[path]
        except KeyError:
            raise FuseOSError(ENOENT)

    def readdir(self, path, fh):
        try:
            return self.list_cache[path]
        except KeyError:
            ls = self.mlist.listdir(path)
            for name, entry in ls.iteritems():
                self.attr_cache[path + '/' + name] = entry2attr(entry)
            dirlist = DOTDOTS + ls.keys()
            self.list_cache[path] = dirlist
            return dirlist

    def read(self, path, size, offset, fh):
        cp = self.content_cache.get(path, self.query_content(path))
        return cp[offset:size+offset]

    def query_content(self, path):
        content = self.mlist.openfile(path).read()
        self.content_cache[path] = content
        return content
    
    access = None
    flush = None
    getxattr = None
    listxattr = None
    open = None
    opendir = None
    release = None
    releasedir = None
    statfs = None
コード例 #2
0
ファイル: sympafs.py プロジェクト: dnet/sympa-python-api
 def __init__(self, url, email, passwd, mlist):
     self.sympa = Sympa(url)
     self.email = email
     self.passwd = passwd
     t = time()
     self.attr_cache = {'/': dict(st_mode=(S_IFDIR | READ_ONLY), st_nlink=2,
         st_ctime=t, st_mtime=t, st_atime=t)}
     self.list_cache = {}
     self.content_cache = {}
     self.sympa_login()
     self.mlist = self.sympa.lists[mlist]