Reformat offlineimap/folder/LocalStatusSQLite.py

Add some spaces, remove lines,... now format is better (lintian).
This commit is contained in:
Rodolfo García Peñas (kix) 2020-08-29 19:45:15 +02:00
parent cb95bc87b0
commit 265de25460

View File

@ -83,7 +83,7 @@ class LocalStatusSQLiteFolder(BaseFolder):
if not os.path.exists(dirname):
os.makedirs(dirname)
if not os.path.isdir(dirname):
raise UserWarning("SQLite database path '%s' is not a directory."%
raise UserWarning("SQLite database path '%s' is not a directory." %
dirname)
self.connection = None
@ -121,7 +121,7 @@ class LocalStatusSQLiteFolder(BaseFolder):
UserWarning(
"cannot open database file '%s': %s.\nYou might"
" want to check the rights to that file and if "
"it cleanly opens with the 'sqlite<3>' command"%
"it cleanly opens with the 'sqlite<3>' command" %
(self.filename, e)),
exc_info()[2])
@ -144,7 +144,7 @@ class LocalStatusSQLiteFolder(BaseFolder):
try:
os.unlink(self.filename)
except OSError as e:
self.ui.debug('', "could not remove file %s: %s"%
self.ui.debug('', "could not remove file %s: %s" %
(self.filename, e))
def storesmessages(self):
@ -204,7 +204,7 @@ class LocalStatusSQLiteFolder(BaseFolder):
# Upgrade from database version 1 to version 2
# This change adds labels and mtime columns, to be used by Gmail IMAP and Maildir folders.
if from_ver <= 1:
self.ui._msg('Upgrading LocalStatus cache from version 1 to version 2 for %s:%s'%
self.ui._msg('Upgrading LocalStatus cache from version 1 to version 2 for %s:%s' %
(self.repository, self))
self.connection.executescript("""ALTER TABLE status ADD mtime INTEGER DEFAULT 0;
ALTER TABLE status ADD labels VARCHAR(256) DEFAULT '';
@ -216,13 +216,12 @@ class LocalStatusSQLiteFolder(BaseFolder):
# if from_ver <= 2: ... #upgrade from 2 to 3
# if from_ver <= 3: ... #upgrade from 3 to 4
def __create_db(self):
"""Create a new db file.
self.connection must point to the opened and valid SQlite
database connection."""
self.ui._msg('Creating new Local Status db for %s:%s'%
self.ui._msg('Creating new Local Status db for %s:%s' %
(self.repository, self))
self.connection.executescript("""
CREATE TABLE metadata (key VARCHAR(50) PRIMARY KEY, value VARCHAR(128));
@ -232,12 +231,10 @@ class LocalStatusSQLiteFolder(BaseFolder):
self.connection.commit()
self._newfolder = True
# Interface from BaseFolder
def msglist_item_initializer(self, uid):
return {'uid': uid, 'flags': set(), 'labels': set(), 'time': 0, 'mtime': 0}
# Interface from BaseFolder
def cachemessagelist(self):
self.dropmessagelistcache()
@ -294,21 +291,20 @@ class LocalStatusSQLiteFolder(BaseFolder):
'(id,flags,mtime,labels) VALUES (?,?,?,?)',
data, executemany=True)
# Following some pure SQLite functions, where we chose to use
# BaseFolder() methods instead. Doing those on the in-memory list is
# quicker anyway. If our db becomes so big that we don't want to
# maintain the in-memory list anymore, these might come in handy
# in the future though.
#
#def uidexists(self,uid):
# def uidexists(self,uid):
# conn, cursor = self.get_cursor()
# with conn:
# cursor.execute('SELECT id FROM status WHERE id=:id',{'id': uid})
# return cursor.fetchone()
# This would be the pure SQLite solution, use BaseFolder() method,
# to avoid threading with sqlite...
#def getmessageuidlist(self):
# def getmessageuidlist(self):
# conn, cursor = self.get_cursor()
# with conn:
# cursor.execute('SELECT id from status')
@ -316,12 +312,12 @@ class LocalStatusSQLiteFolder(BaseFolder):
# for row in cursor:
# r.append(row[0])
# return r
#def getmessagecount(self):
# def getmessagecount(self):
# conn, cursor = self.get_cursor()
# with conn:
# cursor.execute('SELECT count(id) from status');
# return cursor.fetchone()[0]
#def getmessageflags(self, uid):
# def getmessageflags(self, uid):
# conn, cursor = self.get_cursor()
# with conn:
# cursor.execute('SELECT flags FROM status WHERE id=:id',
@ -331,7 +327,6 @@ class LocalStatusSQLiteFolder(BaseFolder):
# return flags
# assert False,"getmessageflags() called on non-existing message"
# Interface from BaseFolder
def savemessage(self, uid, content, flags, rtime, mtime=0, labels=set()):
"""Writes a new message, with the specified uid.
@ -354,37 +349,33 @@ class LocalStatusSQLiteFolder(BaseFolder):
labels = ', '.join(sorted(labels))
try:
self.__sql_write('INSERT INTO status (id,flags,mtime,labels) VALUES (?,?,?,?)',
(uid,flags,mtime,labels))
(uid, flags, mtime, labels))
except Exception as e:
six.reraise(UserWarning,
UserWarning("%s while inserting UID %s"%
UserWarning("%s while inserting UID %s" %
(str(e), str(uid))),
exc_info()[2])
return uid
# Interface from BaseFolder
def savemessageflags(self, uid, flags):
assert self.uidexists(uid)
self.messagelist[uid]['flags'] = flags
flags = ''.join(sorted(flags))
self.__sql_write('UPDATE status SET flags=? WHERE id=?',(flags,uid))
self.__sql_write('UPDATE status SET flags=? WHERE id=?', (flags, uid))
def getmessageflags(self, uid):
return self.messagelist[uid]['flags']
def savemessagelabels(self, uid, labels, mtime=None):
self.messagelist[uid]['labels'] = labels
if mtime: self.messagelist[uid]['mtime'] = mtime
labels = ', '.join(sorted(labels))
if mtime:
self.__sql_write('UPDATE status SET labels=?, mtime=? WHERE id=?',(labels,mtime,uid))
self.__sql_write('UPDATE status SET labels=?, mtime=? WHERE id=?', (labels, mtime, uid))
else:
self.__sql_write('UPDATE status SET labels=? WHERE id=?',(labels,uid))
self.__sql_write('UPDATE status SET labels=? WHERE id=?', (labels, uid))
def savemessageslabelsbulk(self, labels):
"""
@ -396,7 +387,6 @@ class LocalStatusSQLiteFolder(BaseFolder):
for uid, l in list(labels.items()):
self.messagelist[uid]['labels'] = l
def addmessageslabels(self, uids, labels):
data = []
for uid in uids:
@ -406,7 +396,6 @@ class LocalStatusSQLiteFolder(BaseFolder):
for uid in uids:
self.messagelist[uid]['labels'] = self.messagelist[uid]['labels'] | labels
def deletemessageslabels(self, uids, labels):
data = []
for uid in uids:
@ -416,11 +405,9 @@ class LocalStatusSQLiteFolder(BaseFolder):
for uid in uids:
self.messagelist[uid]['labels'] = self.messagelist[uid]['labels'] - labels
def getmessagelabels(self, uid):
return self.messagelist[uid]['labels']
def savemessagesmtimebulk(self, mtimes):
"""Saves mtimes from the mtimes dictionary in a single database operation."""
@ -429,17 +416,15 @@ class LocalStatusSQLiteFolder(BaseFolder):
for uid, mt in list(mtimes.items()):
self.messagelist[uid]['mtime'] = mt
def getmessagemtime(self, uid):
return self.messagelist[uid]['mtime']
# Interface from BaseFolder
def deletemessage(self, uid):
if not uid in self.messagelist:
return
self.__sql_write('DELETE FROM status WHERE id=?', (uid, ))
del(self.messagelist[uid])
self.__sql_write('DELETE FROM status WHERE id=?', (uid,))
del (self.messagelist[uid])
# Interface from BaseFolder
def deletemessages(self, uidlist):
@ -456,4 +441,4 @@ class LocalStatusSQLiteFolder(BaseFolder):
# arg2 needs to be an iterable of 1-tuples [(1,),(2,),...]
self.__sql_write('DELETE FROM status WHERE id=?', list(zip(uidlist, )), True)
for uid in uidlist:
del(self.messagelist[uid])
del (self.messagelist[uid])