[Yt-svn] yt-commit r1044 - branches/yt-object-serialization/yt/fido
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Fri Dec 26 07:10:38 PST 2008
Author: mturk
Date: Fri Dec 26 07:10:38 2008
New Revision: 1044
URL: http://yt.spacepope.org/changeset/1044
Log:
Unfortunately, multiple writes by different processes in a shelf don't work, so
we need to move to a transaction based system, which I am mediating with
__getitem__ and __setitem__. Hopefully this will work!
Modified:
branches/yt-object-serialization/yt/fido/ParameterFileStorage.py
Modified: branches/yt-object-serialization/yt/fido/ParameterFileStorage.py
==============================================================================
--- branches/yt-object-serialization/yt/fido/ParameterFileStorage.py (original)
+++ branches/yt-object-serialization/yt/fido/ParameterFileStorage.py Fri Dec 26 07:10:38 2008
@@ -57,24 +57,22 @@
return self
def __init__(self, in_memory = False):
- if self._shelve is None:
- self._shelve = shelve.open(self._get_db_name())
-
+ pass
+
def _get_db_name(self):
return os.path.expanduser("~/.yt/parameter_files.db")
def wipe_hash(self, hash):
- if hash in self._shelve:
- del self._shelve[hash]
- self._shelve.sync()
+ if hash in self.keys():
+ del self[hash]
def get_pf_hash(self, hash):
- return self._convert_pf(self._shelve[hash])
+ return self._convert_pf(self[hash])
def get_pf_ctid(self, ctid):
- for h in self._shelve:
- if self._shelve[h]['ctid'] == ctid:
- return self._convert_pf(self._shelve[h])
+ for h in self.keys():
+ if self[h]['ctid'] == ctid:
+ return self._convert_pf(self[h])
def _adapt_pf(self, pf):
return dict(bn=pf.basename,
@@ -95,18 +93,33 @@
return pf
def check_pf(self, pf):
- if pf._hash() not in self._shelve:
+ if pf._hash() not in self.keys():
self.insert_pf(pf)
return
- pf_dict = self._shelve[pf._hash()]
+ pf_dict = self[pf._hash()]
if pf_dict['bn'] != pf.basename \
or pf_dict['fp'] != pf.fullpath:
self.wipe_hash(pf._hash())
self.insert_pf(pf)
def insert_pf(self, pf):
- self._shelve[pf._hash()] = self._adapt_pf(pf)
- self._shelve.sync()
+ self[pf._hash()] = self._adapt_pf(pf)
+
+ def __getitem__(self, key):
+ my_shelf = shelve.open(self._get_db_name(), flag='r')
+ return my_shelf[key]
+
+ def __setitem__(self, key, val):
+ my_shelf = shelve.open(self._get_db_name(), 'c')
+ my_shelf[key] = val
+
+ def __delitem__(self, key):
+ my_shelf = shelve.open(self._get_db_name(), 'c')
+ del my_shelf[key]
+
+ def keys(self):
+ my_shelf = shelve.open(self._get_db_name(), flag='r')
+ return my_shelf.keys()
class ObjectStorage(object):
pass
More information about the yt-svn
mailing list