/usr/lib/python3/dist-packages/systemimage/settings.py is in system-image-common 2.2-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # Copyright (C) 2013-2014 Canonical Ltd.
# Author: Barry Warsaw <barry@ubuntu.com>
# This program 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; version 3 of the License.
#
# 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/>.
"""Persistent settings - used by the DBus API."""
__all__ = [
'Settings',
]
import sqlite3
from contextlib import contextmanager
from systemimage.config import config
SCHEMA_VERSION = '1'
AUTO_DOWNLOAD_DEFAULT = '1'
class Settings:
def __init__(self, use_config=None):
self._use_config = use_config
# If the database file does not yet exist, create it.
with self._cursor() as c:
c.execute('select tbl_name from sqlite_master')
if len(c.fetchall()) == 0:
# The database file has no tables.
c.execute('create table settings (key, value)''')
# Hopefully we won't ever need to migrate this schema, but just in
# case we do, set a version value.
c.execute('insert into settings values ("__version__", ?)',
(SCHEMA_VERSION,))
@contextmanager
def _cursor(self):
dbpath = (config.system.settings_db
if self._use_config is None
else self._use_config.system.settings_db)
with sqlite3.connect(dbpath) as conn:
yield conn.cursor()
def set(self, key, value):
with self._cursor() as c:
c.execute('select value from settings where key = ?', (key,))
row = c.fetchone()
if row is None:
c.execute('insert into settings values (?, ?)',
(key, value))
else:
c.execute('update settings set value = ? where key = ?',
(value, key))
def get(self, key):
with self._cursor() as c:
c.execute('select value from settings where key = ?', (key,))
row = c.fetchone()
if row is None:
if key == 'auto_download':
return AUTO_DOWNLOAD_DEFAULT
return ''
return row[0]
|