]> scripts.mit.edu Git - wizard.git/commitdiff
Get rid of wizard.cache.
authorEdward Z. Yang <ezyang@mit.edu>
Sat, 17 Jul 2010 22:11:13 +0000 (15:11 -0700)
committerEdward Z. Yang <ezyang@mit.edu>
Sat, 17 Jul 2010 22:11:13 +0000 (15:11 -0700)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
doc/index.rst
doc/module/wizard.cache.rst [deleted file]
wizard/cache.py [deleted file]

index 6c1b044e2eda605c0f2e7d6efaf700b32725da76..9859d414f7c59c2f70bf11c994e82c034361cc50 100644 (file)
@@ -72,7 +72,6 @@ Modules
     module/wizard
     module/wizard.app
     module/wizard.app.php
-    module/wizard.cache
     module/wizard.deploy
     module/wizard.git
     module/wizard.install
diff --git a/doc/module/wizard.cache.rst b/doc/module/wizard.cache.rst
deleted file mode 100644 (file)
index a7cef06..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-:mod:`wizard.cache`
-===================
-
-.. automodule:: wizard.cache
-
-Classes
--------
-.. autoclass:: make
-    :members:
-.. autoclass:: SerializedDict
-    :members:
diff --git a/wizard/cache.py b/wizard/cache.py
deleted file mode 100644 (file)
index c6eb2b4..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-"""
-Provides caching of old results from mass commands, so that
-we don't have to do them again.  Successes are cached as
-the string "OK"; errors are stored as the string exception name.
-Entries are indexed by location.
-
-.. testsetup:: *
-
-    from wizard.cache import *
-"""
-
-import sqlite3
-
-def make(file=None):
-    """
-    Generates a :class:`SerializedDict` if ``file`` is not ``None``,
-    and a normal dictionary otherwise.
-    """
-    if file:
-        return SerializedDict(file)
-    else:
-        return {}
-
-class SerializedDict(object):
-    """
-    Implements a dictionary that serializes itself to disk.  We
-    use sqlite in order to implement relatively efficient updates.
-
-        >>> import os
-        >>> f = "/tmp/wizard-cache-test.db"
-        >>> if os.path.exists(f): os.unlink(f)
-        >>> d = SerializedDict(f)
-        >>> try:
-        ...   d["foo"]
-        ...   raise Exception("didn't raise")
-        ... except KeyError:
-        ...   pass
-        >>> d["foo"] = "baz"
-        >>> d["foo"]
-        'baz'
-        >>> d["foo"] = "bar"
-        >>> d["foo"]
-        'bar'
-        >>> e = SerializedDict(f)
-        >>> e["foo"]
-        'bar'
-        >>> del e["foo"]
-        >>> "foo" in e
-        False
-        >>> os.unlink(f)
-    """
-    #: Connection to sqlite database
-    conn = None
-    def __init__(self, file):
-        self.conn = sqlite3.connect(file)
-        try:
-            self.conn.execute('create table dict(key string primary key, value string)')
-        except sqlite3.OperationalError as e:
-            if e.args[0] != "table dict already exists":
-                raise
-        self.conn.isolation_level = None
-    def __getitem__(self, key):
-        row = self.conn.execute('select value from dict where key = ?', (key,)).fetchone()
-        if row:
-            return str(row[0])
-        else:
-            raise KeyError
-    def __setitem__(self, key, value):
-        self.conn.execute('insert or replace into dict (key, value) values (?, ?)', (key, value))
-    def __delitem__(self, key):
-        self.conn.execute('delete from dict where key = ?', (key,))
-    def __contains__(self, key):
-        return bool(self.conn.execute('select count(*) from dict where key = ?', (key,)).fetchone()[0])