def get_client_from_parsed_config(config:configparser.ConfigParser) -> DokuWikiClient: """Create the DokuWikiClient instance, and patch it with more functions""" client = DokuWikiClient(config['url'], config['user'], config['password']) def with_additional_methods(theclient): def page(pagename:str, rev=None): "Wraps client.page to make it reject category name such as 'page:'" if pagename.endswith(':'): raise ValueError(f"You shouldn't ask for a category content with client.page() function: '{pagename}'") return theclient.page_real(pagename, rev) def has_page(pagename:str) -> bool: # WARNING: for dokuwiki, 'page' and 'page:' are equivalent. # But in this source code, we want it to give different answers depending if 'page' is a category. # if the page 'page' exists on the remote wiki, then 'page' returns True. # But 'page:' will return true iif there is at least one page in the 'page' category. # That could be for instance 'page:page' or 'page:page:page'. # WARNING: if unpatched, client.page() accepts 'page:', and will treat it as 'page'. if pagename.endswith(':'): return bool(client.pagelist(pagename[-1])) # at least one subpage if pagename.endswith(':*'): return bool(client.pagelist(pagename[-2])) # at least one subpage # We now test specifically the page, not the category. try: theclient.page_info(pagename) except DokuWikiXMLRPCError as err: if err.message == 'The requested page does not exist': return False else: raise else: return True theclient.has_page = has_page theclient.page, theclient.page_real = page, theclient.page return theclient return with_additional_methods(client)
class DokuFS(fuse.Fuse): usage = """Doku Wiki Fuse driver ... -o url="http://site.tld/lib/exe/xmlrpc.php" -o username="******" -o password="******" ... Dont forget to activate xmlrpc and allow access for your user account in localconfig.php on server-side. Try -d to see whats going on """ def __init__(self, *args, **kw): fuse.Fuse.__init__(self, *args, **kw) self.parser.add_option(mountopt="url", help="Dokuwiki XMLRPC URL (including lib/exe/xmlrpc.php)") self.parser.add_option(mountopt="username", help="Wiki Username") self.parser.add_option(mountopt="password", help="Wiki Password") self.log = logging.getLogger("DokuFS") self.pagetreeCache = dict() self.pagetreeCacheTime = 0 self.pagetreeCacheTimeout = 5 def connect(self): self.log.info("connect") try: self.dokuwiki = DokuWikiClient(self.url, self.username, self.password) self.log.info( "RPC Version: {0}".format(self.dokuwiki.rpc_version_supported()) ) self._pagelist(cache=False) except Exception,e: self.log.error( "Exception {0}: {1}".format(e.__class__.__name__,str(e))) raise RuntimeError(e)
def connect(self): self.log.info("connect") try: self.dokuwiki = DokuWikiClient(self.url, self.username, self.password) self.log.info( "RPC Version: {0}".format(self.dokuwiki.rpc_version_supported()) ) self._pagelist(cache=False) except Exception,e: self.log.error( "Exception {0}: {1}".format(e.__class__.__name__,str(e))) raise RuntimeError(e)