pep8
This commit is contained in:
parent
c13063686a
commit
cc569efcc7
|
@ -24,8 +24,10 @@ class Settings(Cache):
|
|||
__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)
|
||||
self.storage.execute(settings_table, commit=False)
|
||||
|
@ -33,19 +35,23 @@ class Settings(Cache):
|
|||
|
||||
# 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)))
|
||||
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,))
|
||||
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
|
||||
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")
|
||||
|
@ -57,23 +63,30 @@ class Settings(Cache):
|
|||
"""return all properties in a dictionary
|
||||
"""
|
||||
ret = {}
|
||||
for path, properties in self.storage.select("SELECT * FROM property", only_one=False):
|
||||
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)
|
||||
opt = context.cfgimpl_get_description().impl_get_opt_by_path(
|
||||
path)
|
||||
properties = self._sqlite_decode(properties)
|
||||
ret[opt] = 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)))
|
||||
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:
|
||||
|
|
|
@ -28,14 +28,16 @@ class Values(Cache):
|
|||
def __init__(self, storage):
|
||||
"""init plugin means create values storage
|
||||
"""
|
||||
values_table = 'CREATE TABLE IF NOT EXISTS value(path text primary key, value text, owner text)'
|
||||
values_table = 'CREATE TABLE IF NOT EXISTS value(path text primary '
|
||||
values_table += 'key, value text, owner text)'
|
||||
# should init cache too
|
||||
super(Values, self).__init__('value', storage)
|
||||
self.storage.execute(values_table)
|
||||
|
||||
# sqlite
|
||||
def _sqlite_select(self, path):
|
||||
return self.storage.select("SELECT value FROM value WHERE path = ?", (path,))
|
||||
return self.storage.select("SELECT value FROM value WHERE path = ?",
|
||||
(path,))
|
||||
|
||||
# value
|
||||
def setvalue(self, path, value, owner):
|
||||
|
@ -43,8 +45,9 @@ class Values(Cache):
|
|||
a specified value must be associated to an owner
|
||||
"""
|
||||
self.resetvalue(path)
|
||||
self.storage.execute("INSERT INTO value(path, value, owner) VALUES (?, ?, ?)",
|
||||
(path, self._sqlite_encode(value), str(owner)))
|
||||
self.storage.execute("INSERT INTO value(path, value, owner) VALUES "
|
||||
"(?, ?, ?)", (path, self._sqlite_encode(value),
|
||||
str(owner)))
|
||||
|
||||
def getvalue(self, path):
|
||||
"""get value for an option
|
||||
|
@ -68,7 +71,8 @@ class Values(Cache):
|
|||
example: {option1: (owner, 'value1'), option2: (owner, 'value2')}
|
||||
"""
|
||||
ret = {}
|
||||
for path, value, owner in self.storage.select("SELECT value", only_one=False):
|
||||
for path, value, owner in self.storage.select("SELECT value",
|
||||
only_one=False):
|
||||
opt = context.cfgimpl_get_description().impl_get_opt_by_path(path)
|
||||
owner = getattr(owners, owner)
|
||||
|
||||
|
@ -80,13 +84,15 @@ class Values(Cache):
|
|||
def setowner(self, path, owner):
|
||||
"""change owner for an option
|
||||
"""
|
||||
self.storage.execute("UPDATE value SET owner = ? WHERE path = ?", (str(owner), path))
|
||||
self.storage.execute("UPDATE value SET owner = ? WHERE path = ?",
|
||||
(str(owner), path))
|
||||
|
||||
def getowner(self, path, default):
|
||||
"""get owner for an option
|
||||
return: owner object
|
||||
"""
|
||||
owner = self.storage.select("SELECT owner FROM value WHERE path = ?", (path,))
|
||||
owner = self.storage.select("SELECT owner FROM value WHERE path = ?",
|
||||
(path,))
|
||||
if owner is None:
|
||||
return default
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue