cache is always a dictionary in memory
[tiramisu.git] / tiramisu / storage / sqlite3 / setting.py
index 5e722d3..720849b 100644 (file)
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 # ____________________________________________________________
-from tiramisu.storage.sqlite3.storage import Cache
+from .sqlite3db import Sqlite3DB
 
 
-class Settings(Cache):
+class Settings(Sqlite3DB):
     __slots__ = tuple()
 
     def __init__(self, storage):
-        settings_table = 'CREATE TABLE IF NOT EXISTS property(path text primary key, properties text)'
-        permissives_table = 'CREATE TABLE IF NOT EXISTS permissive(path text primary key, permissives text)'
+        settings_table = 'CREATE TABLE IF NOT EXISTS property(path text '
+        settings_table += 'primary key, properties text)'
+        permissives_table = 'CREATE TABLE IF NOT EXISTS permissive(path text '
+        permissives_table += 'primary key, permissives text)'
         # should init cache too
-        super(Settings, self).__init__('property', storage)
+        super(Settings, self).__init__(storage)
         self.storage.execute(settings_table, commit=False)
         self.storage.execute(permissives_table)
 
     # propertives
     def setproperties(self, path, properties):
-        self.storage.execute("DELETE FROM property WHERE path = ?", (path,), False)
-        self.storage.execute("INSERT INTO property(path, properties) VALUES (?, ?)",
-                             (path, self._sqlite_encode(properties)))
+        path = self._sqlite_encode_path(path)
+        self.storage.execute("DELETE FROM property WHERE path = ?", (path,),
+                             False)
+        self.storage.execute("INSERT INTO property(path, properties) VALUES "
+                             "(?, ?)", (path,
+                                        self._sqlite_encode(properties)))
 
     def getproperties(self, path, default_properties):
-        value = self.storage.select("SELECT properties FROM property WHERE path = ?", (path,))
+        path = self._sqlite_encode_path(path)
+        value = self.storage.select("SELECT properties FROM property WHERE "
+                                    "path = ?", (path,))
         if value is None:
             return set(default_properties)
         else:
             return set(self._sqlite_decode(value[0]))
 
     def hasproperties(self, path):
-        return self.storage.select("SELECT properties FROM property WHERE path = ?", (path,)) is not None
+        path = self._sqlite_encode_path(path)
+        return self.storage.select("SELECT properties FROM property WHERE "
+                                   "path = ?", (path,)) is not None
 
     def reset_all_propertives(self):
         self.storage.execute("DELETE FROM property")
 
     def reset_properties(self, path):
+        path = self._sqlite_encode_path(path)
         self.storage.execute("DELETE FROM property WHERE path = ?", (path,))
 
     def get_properties(self, context):
         """return all properties in a dictionary
         """
         ret = {}
-        for path, properties in self.storage.select("SELECT * FROM property", only_one=False):
-            if path == '_none':
-                opt = None
-            else:
-                opt = context.cfgimpl_get_description().impl_get_opt_by_path(path)
+        for path, properties in self.storage.select("SELECT * FROM property",
+                                                    only_one=False):
+            path = self._sqlite_decode_path(path)
             properties = self._sqlite_decode(properties)
-            ret[opt] = properties
+            ret[path] = properties
         return ret
 
     # permissive
     def setpermissive(self, path, permissive):
-        self.storage.execute("DELETE FROM permissive WHERE path = ?", (path,), False)
-        self.storage.execute("INSERT INTO permissive(path, permissives) VALUES (?, ?)",
-                             (path, self._sqlite_encode(permissive)))
+        path = self._sqlite_encode_path(path)
+        self.storage.execute("DELETE FROM permissive WHERE path = ?", (path,),
+                             False)
+        self.storage.execute("INSERT INTO permissive(path, permissives) "
+                             "VALUES (?, ?)", (path,
+                                               self._sqlite_encode(permissive)
+                                               ))
 
     def getpermissive(self, path='_none'):
-        permissives = self.storage.select("SELECT permissives FROM permissive WHERE path = ?", (path,))
+        permissives = self.storage.select("SELECT permissives FROM "
+                                          "permissive WHERE path = ?",
+                                          (path,))
         if permissives is None:
             return frozenset()
         else: