changeset 1026:fd0d86823c41

Added working TagStore and Tag classes.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Thu, 20 Jul 2006 00:13:09 +0200
parents 8ee55064a4f2
children 5fa60ea62b28
files MoinMoin/wikisync.py
diffstat 1 files changed, 45 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/wikisync.py	Thu Jul 20 00:12:48 2006 +0200
+++ b/MoinMoin/wikisync.py	Thu Jul 20 00:13:09 2006 +0200
@@ -6,18 +6,58 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-# XXX add some code here
+try:
+    import cpickle as pickle
+except ImportError:
+    import pickle
+
+
 class Tag(object):
     """ This class is used to store information about merging state. """
-    pass
+    
+    def __init__(self, remote_wiki, remote_rev, current_rev):
+        self.remote_wiki = remote_wiki
+        self.remote_rev = remote_rev
+        self.current_rev = current_rev
 
 
-class TagStore(object):
-    """ This class manages the storage of tags. """
+class AbstractTagStore(object):
+    """ This class is an abstract base class that shows how to implement classes
+        that manage the storage of tags. """
+
+    def __init__(self, page):
+        pass
+
+    def add(self, **kwargs):
+        print "Got tag for page %r: %r" % (self.page, kwargs)
+
+
+class PickleTagStore(AbstractTagStore):
+    """ This class manages the storage of tags in pickle files. """
 
     def __init__(self, page):
         self.page = page
+        self.filename = page.getPagePath('synctags', use_underlay=0, check_create=1, isfile=1)
+        self.load()
 
+    def load(self):
+        try:
+            datafile = file(self.filename, "rb")
+        except IOError:
+            self.tags = []
+        else:
+            self.tags = pickle.load(datafile)
+            datafile.close()
+    
+    def commit(self):
+        datafile = file(self.filename, "wb")
+        pickle.dump(self.tags, datafile, protocol=pickle.HIGHEST_PROTOCOL)
+        datafile.close()
+
+    # public methods
     def add(self, **kwargs):
-        # XXX add some code here
         print "Got tag for page %r: %r" % (self.page, kwargs)
+        self.tags.append(Tag(**kwargs))
+        self.commit()
+
+TagStore = PickleTagStore
\ No newline at end of file