Commits

Anonymous committed 271886a

use hatta.storage instead of hgdb

Comments (0)

Files changed (3)

MoinMoin/events/hg.py

-import MoinMoin.events as ev
-# import logging
-
-def handle_page_renamed(event):
-    # event.page.page_name_fs (saved already)
-    event.old_page.delete_page()
-
-def handle_page_deleted(event):
-    event.page.delete_page()
-
-def handle_page_reverted(event):
-    # name = event.page.page_name
-    # logging.info('reverted ' + name + ',' + event.previous + ',' + event.current)
-    pass
-
-def handle_page_copied(event):
-    # name = event.page.page_name
-    # logging.info('copied ' + name)
-    pass
-
-def handle(event):
-    """An event handler"""
-
-    # if isinstance(event, (ev.PageChangedEvent, ev.TrivialPageChangedEvent)):
-    #     return handle_page_change(event)
-    if isinstance(event, ev.PageRenamedEvent):
-        return handle_page_renamed(event)
-    elif isinstance(event, ev.PageDeletedEvent):
-        return handle_page_deleted(event)
-    elif isinstance(event, ev.PageCopiedEvent):
-        return handle_page_copied(event)
-    elif isinstance(event, ev.PageRevertedEvent):
-        return handle_page_reverted(event)

MoinMoin/events/storage.py

+import MoinMoin.events as ev
+# import logging
+
+def handle_page_renamed(event):
+    # event.page.page_name_fs (saved already)
+    event.old_page.delete_page()
+
+def handle_page_deleted(event):
+    event.page.delete_page()
+
+def handle_page_reverted(event):
+    # name = event.page.page_name
+    # logging.info('reverted ' + name + ',' + event.previous + ',' + event.current)
+    pass
+
+def handle_page_copied(event):
+    # name = event.page.page_name
+    # logging.info('copied ' + name)
+    pass
+
+def handle(event):
+    """An event handler"""
+
+    # if isinstance(event, (ev.PageChangedEvent, ev.TrivialPageChangedEvent)):
+    #     return handle_page_change(event)
+    if isinstance(event, ev.PageRenamedEvent):
+        return handle_page_renamed(event)
+    elif isinstance(event, ev.PageDeletedEvent):
+        return handle_page_deleted(event)
+    elif isinstance(event, ev.PageCopiedEvent):
+        return handle_page_copied(event)
+    elif isinstance(event, ev.PageRevertedEvent):
+        return handle_page_reverted(event)

MoinMoin/storage.py

 import datetime
 import codecs
 
-from pagelib import dayone
-from pagelib.hgdb import WikiStorage, NotFoundErr
-# from pagelib import pfmpagerouter
+try:
+    import dayone
+except ImportError:
+    class dayone:
+        def __init__(self, *arg, **kw):
+            pass
+try:
+    from hatta.storage import WikiStorage as HattaWikiStorage
+    class WikiStorage(HattaWikiStorage):
+        def _title_to_file(self, title):
+            filename = title.strip()
+            filename += self.extension
+            return os.path.join(self.repo_prefix, filename)
+
+        def _file_to_title(self, filepath):
+            _ = self._
+            if not filepath.startswith(self.repo_prefix):
+                raise Exception(u"Can't read or write outside of the pages repository")
+            name = filepath[len(self.repo_prefix):].strip('/')
+            if self.extension and name.endswith(self.extension):
+                name = name[:-len(self.extension)]
+            return name
+except ImportError:
+    class WikiStorage:
+        def __init__(self, *arg, **kw):
+            pass
 
 from MoinMoin.logfile import editlog
 from MoinMoin import caching
 logging = log.getLogger(__name__)
 
 
-# def router(pagename):
-#     return pfmpagerouter.router(pagename)
-
 
 class PageAdaptor:
     def __init__(self, request, pagename_fs):
         pagename_fs = self.request.cfg.pagename_router(self.pagename_fs)
         try:
             hg_text = self.hgdb.page_text(pagename_fs)
-        except NotFoundErr:
+        except:
             hg_text = None
         return hg_text
     def exists(self):
         # pages = sorted(pages, lambda x,y: os.path.getmtime(x) < os.path.getmtime(y), reverse=True)
         # logging.warning(str(pages))
         pages = sorted(pages, key=lambda(x): os.path.getmtime(x), reverse=True)
-        
+
         _usercache = {}
         for filename in pages:
             result = editlog.EditLogLine(_usercache)