Improved environment initialization.
authorFredrik Tolf <fredrik@dolda2000.com>
Fri, 20 Mar 2015 05:14:59 +0000 (06:14 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Fri, 20 Mar 2015 05:14:59 +0000 (06:14 +0100)
didex/store.py

index 15d2eca..450a9fe 100644 (file)
@@ -3,15 +3,23 @@ from . import db, index, cache
 from .db import txnfun
 
 class environment(object):
-    def __init__(self, path):
-        self.path = path
+    def __init__(self, *, path=None, getpath=None, recover=False):
+        if path is not None:
+            self.path = path
+            self.getpath = None
+        else:
+            self.path = None
+            self.getpath = getpath
+        self.recover = recover
         self.lk = threading.Lock()
         self.bk = None
 
     def __call__(self):
         with self.lk:
             if self.bk is None:
-                self.bk = db.environment(self.path)
+                if self.path is None:
+                    self.path = self.getpath()
+                self.bk = db.environment(self.path, recover=self.recover)
             return self.bk
 
     def close(self):
@@ -41,7 +49,7 @@ class store(object):
         if env:
             self.env = env
         else:
-            self.env = environment(path)
+            self.env = environment(path=path)
         self._db = None
         if ncache is None:
             ncache = cache.cache()