Adding save/load to backend interface
authorEd Page <eopage@byu.net>
Sat, 18 Apr 2009 02:04:45 +0000 (21:04 -0500)
committerEd Page <eopage@byu.net>
Sat, 18 Apr 2009 02:04:45 +0000 (21:04 -0500)
src/file_backend.py
src/null_backend.py
src/rtm_backend.py

index 2493e8d..93cee59 100644 (file)
@@ -1,4 +1,5 @@
 import uuid
+import pickle
 import datetime
 
 import toolbox
@@ -6,11 +7,26 @@ import toolbox
 
 class FileManager(object):
 
-       def __init__(self):
+       def __init__(self, filename):
+               self._filename = filename
                self._projects = {}
                self._items = {}
                self._locations = {}
 
+       def save(self):
+               state = {
+                       "projects": self._projects,
+                       "items": self._items,
+                       "locations": self._locations,
+               }
+               pickle.dump(state, self._filename)
+
+       def load(self):
+               state = pickle.load(self._filename)
+               self._projects = state["projects"]
+               self._items = state["items"]
+               self._locations = state["locations"]
+
        def add_project(self, name):
                projId = uuid.uuid4().hex
                projDetails = {
index 5997d13..d70d55e 100644 (file)
@@ -3,6 +3,12 @@ class NullManager(object):
        def __init__(self, username, password, token=None):
                pass
 
+       def save(self):
+               pass
+
+       def load(self):
+               pass
+
        def add_project(self, name):
                raise NotImplementedError("Not logged in to any ToDo system")
 
index 9d7cb5f..d724d13 100644 (file)
@@ -39,6 +39,12 @@ class RtMilkManager(object):
                self._timeline = resp.timeline
                self._lists = []
 
+       def save(self):
+               pass
+
+       def load(self):
+               pass
+
        def add_project(self, name):
                rsp = self._rtm.lists.add(
                        timeline=self._timeline,