[Yt-svn] yt-commit r1029 - in branches/yt-object-serialization/yt: fido lagos
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Tue Dec 23 15:57:20 PST 2008
Author: mturk
Date: Tue Dec 23 15:57:19 2008
New Revision: 1029
URL: http://yt.spacepope.org/changeset/1029
Log:
Adding a non-functional SQLite backend for parameter file storage and also a
caching mechanism for existant parameter files.
Added:
branches/yt-object-serialization/yt/fido/ParameterFileStorage.py
Modified:
branches/yt-object-serialization/yt/lagos/OutputTypes.py
Added: branches/yt-object-serialization/yt/fido/ParameterFileStorage.py
==============================================================================
--- (empty file)
+++ branches/yt-object-serialization/yt/fido/ParameterFileStorage.py Tue Dec 23 15:57:19 2008
@@ -0,0 +1,53 @@
+"""
+A simple SQLite interface to grabbing and storing parameter files
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: KIPAC/SLAC/Stanford
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 2008 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+## This is going to be the means of interacting with an SQLite (no, I repeat,
+## ORM will be used here!) db in the ~/.yt/ directory where parameter files
+## will be stored. It will be queried for a hash, which then gets instantiated
+## and returned to the user.
+
+## Non-functional right now.
+
+from yt.fido import *
+import sqlite
+
+class ParameterFileStore(object):
+ _shared_state = {} # Do we need this?
+
+ def __new__(cls, *args, **kwargs):
+ pass
+
+ def _get_db_name(self):
+ return os.path.expanduser("~/.yt/pfdb.sql")
+
+ def _initialize_new(self, filename = None):
+ self._conn = sqlite.connect(self._get_db_name())
+
+ def get_pf(self, hash):
+ pass
+
+ def check_pf(self, fn = None, ctid = None, basedir = None,
+ initial_time = None, hash = None):
+ pass
Modified: branches/yt-object-serialization/yt/lagos/OutputTypes.py
==============================================================================
--- branches/yt-object-serialization/yt/lagos/OutputTypes.py (original)
+++ branches/yt-object-serialization/yt/lagos/OutputTypes.py Tue Dec 23 15:57:19 2008
@@ -32,7 +32,22 @@
# When such a thing comes to pass, I'll move all the stuff that is contant up
# to here, and then have it instantiate EnzoStaticOutputs as appropriate.
+_cached_pfs = defaultdict(lambda: dict())
+
class StaticOutput(object):
+ class __metaclass__(type):
+ def __call__(cls, *args, **kwargs):
+ return cls.__new__(cls, *args, **kwargs)
+
+ def __new__(cls, filename, *args, **kwargs):
+ apath = os.path.abspath(filename)
+ if not os.path.exists(apath): raise IOError
+ if apath not in _cached_pfs:
+ obj = object.__new__(cls)
+ _cached_pfs[apath] = obj
+ obj.__init__(filename, *args, **kwargs)
+ return _cached_pfs.pop(apath)
+
def __init__(self, filename, data_style=None):
"""
Base class for generating new output types. Principally consists of
More information about the yt-svn
mailing list