diff piecrust/records.py @ 3:f485ba500df3

Gigantic change to basically make PieCrust 2 vaguely functional. - Serving works, with debug window. - Baking works, multi-threading, with dependency handling. - Various things not implemented yet.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 10 Aug 2014 23:43:16 -0700
parents
children 474c9882decf
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/piecrust/records.py	Sun Aug 10 23:43:16 2014 -0700
@@ -0,0 +1,51 @@
+import os
+import os.path
+import logging
+from piecrust import APP_VERSION
+from piecrust.events import Event
+
+try:
+    import cPickle as pickle
+except ImportError:
+    import pickle
+
+
+logger = logging.getLogger(__name__)
+
+
+class Record(object):
+    VERSION = 1
+
+    def __init__(self):
+        self.app_version = None
+        self.record_version = None
+        self.entries = []
+        self.entry_added = Event()
+
+    def isVersionMatch(self):
+        return (self.app_version == APP_VERSION and
+                self.record_version == self.VERSION)
+
+    def addEntry(self, entry):
+        self.entries.append(entry)
+        self.entry_added.fire(entry)
+
+    def save(self, path):
+        path_dir = os.path.dirname(path)
+        if not os.path.isdir(path_dir):
+            os.makedirs(path_dir, 0755)
+
+        with open(path, 'w') as fp:
+            pickle.dump(self, fp, pickle.HIGHEST_PROTOCOL)
+
+    def __getstate__(self):
+        odict = self.__dict__.copy()
+        del odict['entry_added']
+        return odict
+
+    @staticmethod
+    def load(path):
+        logger.debug("Loading bake record from: %s" % path)
+        with open(path, 'r') as fp:
+            return pickle.load(fp)
+