From 5801edee319946798d1078d6eb968362834e7b5f Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Thu, 9 Jul 2009 12:33:27 +0300 Subject: [PATCH] Apply the patch from Tobias Polzin --- wikifuse.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/wikifuse.py b/wikifuse.py index 9f2296a..50d97e4 100755 --- a/wikifuse.py +++ b/wikifuse.py @@ -95,6 +95,7 @@ fuse.fuse_python_api = (0, 2) out_charset = locale.getpreferredencoding() if out_charset == None: out_charset = "utf-8" +page_coding = "utf-8" #print("Using charset %s for stdout" % out_charset) @@ -167,7 +168,10 @@ class WikiServerProxySimple(WikiServerProxy): class WikiServerProxyMoinCookie(WikiServerProxy): def __init__(self, url, user_id): - transport = self.transport(user_id) + if url.startswith("https"): + transport = self.safeTransport(user_id) + else: + transport = self.transport(user_id) WikiServerProxy.__init__(self, url, transport=transport) def __getattr__(self, name): @@ -198,6 +202,20 @@ class WikiServerProxyMoinCookie(WikiServerProxy): return host, extra_headers, x509 + class safeTransport(xmlrpclib.SafeTransport): + def __init__(self, user_id): + xmlrpclib.SafeTransport.__init__(self) + self.user_id = user_id + + def get_host_info(self, host): + host, extra_headers, x509 = xmlrpclib.SafeTransport.get_host_info(self, host) + + if extra_headers == None: + extra_headers = [] + extra_headers.append(("Cookie", "MOIN_ID=" + self.user_id)) + + return host, extra_headers, x509 + # MoinMoinWiki xmlrpc authentication # class WikiServerProxyMoinAuth(WikiServerProxy): @@ -268,6 +286,19 @@ class WikiServerProxyMoinAuth(WikiServerProxy): return ret +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 WikiServer: def __init__(self, name, proxy): self.name = name @@ -301,6 +332,9 @@ class WikiServer: self.pages = {} self.virt_pages = {} + self.all = [unicode(x).encode(page_coding) + for x in self.wikiproxy.getAllPages()] + info += "pages: %s\n%s" % (len(self.all),"\n".join(self.all)) self.virt_pages['_'] = info #self.virt_pages['cyr'] = u"кириÐ��»Ð¸Ñ Ð��°" @@ -315,15 +349,16 @@ class WikiServer: for page in self.virt_pages.iterkeys(): yield fuse.Direntry(page) - all = self.wikiproxy.getAllPages() + all = self.all for page in all: + page = page.replace("/","%%") if page.find('/') == -1: yield fuse.Direntry(page) def getattr(self, path): log_basic("getattr \"%s\"" % path) - st = fuse.Stat() + st = MyStat() st.st_nlink = 1 st.st_mode = S_IFREG | 0666 @@ -336,13 +371,18 @@ class WikiServer: st.st_size = self.pages[path]['size'] return st - info = self.wikiproxy.getPageInfo(path) + if path.replace("%%","/") not in self.all: + log_basic("not in all") + return -ENOENT + + info = self.wikiproxy.getPageInfo(path.replace("%%","/")) if info.has_key('faultCode'): log_error("getPageInfo(%s) failed" % path + repr(info)) return -ENOENT - page = self.wikiproxy.getPage(path).encode('utf-8') - st.st_size = len(page) + data = self.wikiproxy.getPage(path.replace("%%","/")) + data = unicode(data).encode(out_charset) + st.st_size = len(data) return st @@ -359,7 +399,8 @@ class WikiServer: self.pages[path]['modified'] = False return 0 - data = self.wikiproxy.getPage(path).encode('utf-8') + data = self.wikiproxy.getPage(path.replace("%%","/")) + data = unicode(data).encode(out_charset) if self.pages[path].has_key('size'): size = self.pages[path]['size'] if size != len(data): @@ -438,7 +479,9 @@ class WikiServer: if self.pages[path]['modified']: log_basic("PUT PAGE") log_debug("\"%s\"" % self.pages[path]['data']) - ret = self.wikiproxy.putPage(path, self.pages[path]['data']) + ret = self.wikiproxy.putPage( + path.replace("%%","/"), + unicode( self.pages[path]['data'], out_charset ) ) if type(ret) == types.BooleanType and ret == True: self.pages[path]['modified'] = False return 0 @@ -476,10 +519,13 @@ class WikiFS(fuse.Fuse): def getattr(self, path): log_basic("getattr \"%s\"" % path) - st = fuse.Stat() + st = MyStat() + st.st_nlink = 2 - if path.count("/") == 1: + if path == "/" or ( + path.count("/") == 1 and + path[1:] in [server.name for server in self.servers] ): st.st_mode = S_IFDIR | 0700 return st @@ -616,7 +662,7 @@ class WikiFS(fuse.Fuse): # Read config file old_path = sys.path -sys.path = [os.environ['HOME'] + "/.config/wikifuse"] +sys.path = [".",os.environ['HOME'] + "/.config/wikifuse"] try: import config except: @@ -644,7 +690,7 @@ def main(): proxy = WikiServerProxySimple(wiki['xmlrpc_url']) servers.append(WikiServer(wiki['name'], proxy)) - fs = WikiFS(servers) + fs = WikiFS(servers,version="%prog " + fuse.__version__,dash_s_do='setsingle') #fs.multithreaded = 1 fs.parse(errex=1) fs.main() -- 2.11.4.GIT