make sure folder exists

This commit is contained in:
j 2019-01-25 18:42:49 +05:30
parent d97d396ef3
commit 2713c17550

View file

@ -22,23 +22,32 @@ logger = logging.getLogger(__name__)
MAX_WORKERS = 4
class Icons(dict):
def __init__(self, db):
self._db = db
self.create()
def is_available(self):
folder = os.path.dirname(self._db)
if os.path.exists(folder):
if not os.path.exists(self._db):
self.create()
return os.path.exists(self._db)
def connect(self):
conn = sqlite3.connect(self._db, timeout=90)
return conn
def create(self):
conn = self.connect()
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS icon (id varchar(64) unique, data blob)')
c.execute('CREATE TABLE IF NOT EXISTS setting (key varchar(256) unique, value text)')
if int(self.get_setting(c, 'version', 0)) < 1:
self.set_setting(c, 'version', 1)
folder = os.path.dirname(self._db)
if os.path.exists(folder):
conn = self.connect()
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS icon (id varchar(64) unique, data blob)')
c.execute('CREATE TABLE IF NOT EXISTS setting (key varchar(256) unique, value text)')
if int(self.get_setting(c, 'version', 0)) < 1:
self.set_setting(c, 'version', 1)
def get_setting(self, c, key, default=None):
c.execute('SELECT value FROM setting WHERE key = ?', (key, ))
@ -139,6 +148,8 @@ def get_icons_db_path():
return icons_db_path
def get_icon_sync(id, type_, size):
if not icons.is_available():
return ''
if size:
skey = '%s:%s:%s' % (type_, id, size)
data = icons[skey]