make sure folder exists
This commit is contained in:
parent
d97d396ef3
commit
2713c17550
1 changed files with 18 additions and 7 deletions
|
@ -22,17 +22,26 @@ 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):
|
||||
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)')
|
||||
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue