1 # -*- coding: utf-8 -*-
2 "default plugin for setting: set it in a simple dictionary"
3 # Copyright (C) 2013-2017 Team tiramisu (see AUTHORS for all contributors)
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by the
7 # Free Software Foundation, either version 3 of the License, or (at your
8 # option) any later version.
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # ____________________________________________________________
18 from .sqlite3db import Sqlite3DB
21 class Settings(Sqlite3DB):
24 def __init__(self, storage):
25 super(Settings, self).__init__(storage)
28 def setproperties(self, path, properties):
29 path = self._sqlite_encode_path(path)
30 self._storage.execute("DELETE FROM property WHERE path = ? AND session_id = ?",
31 (path, self._session_id),
33 self._storage.execute("INSERT INTO property(path, properties, session_id) VALUES "
35 self._sqlite_encode(properties),
38 def delproperties(self, path):
39 path = self._sqlite_encode_path(path)
40 self._storage.execute("DELETE FROM property WHERE path = ? AND session_id = ?",
41 (path, self._session_id))
43 def getproperties(self, path, default_properties):
44 path = self._sqlite_encode_path(path)
45 value = self._storage.select("SELECT properties FROM property WHERE "
46 "path = ? AND session_id = ? LIMIT 1", (path, self._session_id))
48 return set(default_properties)
50 return set(self._sqlite_decode(value[0]))
52 def hasproperties(self, path):
53 path = self._sqlite_encode_path(path)
54 return self._storage.select("SELECT properties FROM property WHERE "
55 "path = ? AND session_id = ? LIMIT 1", (path, self._session_id)
58 def reset_all_properties(self):
59 self._storage.execute("DELETE FROM property WHERE session_id = ?", (self._session_id,))
61 def reset_properties(self, path):
62 path = self._sqlite_encode_path(path)
63 self._storage.execute("DELETE FROM property WHERE path = ? AND session_id = ?",
64 (path, self._session_id))
67 def setpermissive(self, path, permissive):
68 path = self._sqlite_encode_path(path)
69 self._storage.execute("DELETE FROM permissive WHERE path = ? AND session_id = ?",
70 (path, self._session_id),
72 self._storage.execute("INSERT INTO permissive(path, permissives, session_id) "
73 "VALUES (?, ?, ?)", (path,
74 self._sqlite_encode(permissive),
77 def getpermissive(self, path='_none'):
78 permissives = self._storage.select("SELECT permissives FROM "
79 "permissive WHERE path = ? AND session_id = ? LIMIT 1",
80 (path, self._session_id))
81 if permissives is None:
84 return frozenset(self._sqlite_decode(permissives[0]))
86 def get_modified_properties(self):
87 """return all modified settings in a dictionary
88 example: {'path1': set(['prop1', 'prop2'])}
91 for path, properties, _ in self._storage.select("SELECT * FROM property "
92 "WHERE session_id = ?",
95 path = self._sqlite_decode_path(path)
96 ret[path] = self._sqlite_decode(properties)
99 def set_modified_properties(self, properties):
100 self._storage.execute("DELETE FROM property", commit=False)
101 for path, property_ in properties.items():
102 self._storage.execute("INSERT INTO property(path, property, session_id) "
103 "VALUES (?, ?, ?)", (path,
104 self._sqlite_encode(property_),
107 self._storage._conn.commit()
109 def get_modified_permissives(self):
110 """return all modified permissives in a dictionary
111 example: {'path1': set(['perm1', 'perm2'])}
114 for path, permissives in self._storage.select("SELECT * FROM permissive "
115 "WHERE session_id = ?",
118 path = self._sqlite_decode_path(path)
119 ret[path] = self._sqlite_decode(permissives)
122 def set_modified_permissives(self, permissives):
123 self._storage.execute("DELETE FROM permissive", commit=False)
124 for path, permissive in permissives.items():
125 self._storage.execute("INSERT INTO permissive(path, permissive, session_id) "
126 "VALUES (?, ?, ?)", (path,
127 self._sqlite_encode(permissive),
130 self._storage._conn.commit()