diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-05-07 15:26:43 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-05-07 15:26:43 +0200 |
commit | b244c2ff1856abe602e3553b376208f8dfbdce5c (patch) | |
tree | 6a1ccde63d1af8c8b0ccdeffae7b0cc2e3e18d89 /alot/db/manager.py | |
parent | 006c5211f34096392d887ce3ef647ff20823490d (diff) |
db/manager: get rid of an unnecessary indentation level
Diffstat (limited to 'alot/db/manager.py')
-rw-r--r-- | alot/db/manager.py | 166 |
1 files changed, 84 insertions, 82 deletions
diff --git a/alot/db/manager.py b/alot/db/manager.py index 888e9404..3c3ce7d6 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -111,94 +111,96 @@ class DBManager: """ if self.ro: raise DatabaseROError() - if self.writequeue: - # read notmuch's config regarding imap flag synchronization - sync = settings.get_notmuch_setting('maildir', 'synchronize_flags') + if not self.writequeue: + return - # go through writequeue entries - while self.writequeue: - current_item = self.writequeue.popleft() - logging.debug('write-out item: %s', str(current_item)) + # read notmuch's config regarding imap flag synchronization + sync = settings.get_notmuch_setting('maildir', 'synchronize_flags') - # watch out for notmuch errors to re-insert current_item - # to the queue on errors + # go through writequeue entries + while self.writequeue: + current_item = self.writequeue.popleft() + logging.debug('write-out item: %s', str(current_item)) + + # watch out for notmuch errors to re-insert current_item + # to the queue on errors + try: + # the first two coordinants are cnmdname and post-callback + cmd, afterwards = current_item[:2] + logging.debug('cmd created') + + # acquire a writeable db handler try: - # the first two coordinants are cnmdname and post-callback - cmd, afterwards = current_item[:2] - logging.debug('cmd created') - - # acquire a writeable db handler - try: - mode = Database.MODE.READ_WRITE - db = Database(path=self.path, mode=mode) - except NotmuchError: - raise DatabaseLockedError() - logging.debug('got write lock') - - # make this a transaction - db.begin_atomic() - logging.debug('got atomic') - - if cmd == 'add': - logging.debug('add') - path, tags = current_item[2:] - msg, _ = db.add_message(path, sync_maildir_flags=sync) - logging.debug('added msg') + mode = Database.MODE.READ_WRITE + db = Database(path=self.path, mode=mode) + except NotmuchError: + raise DatabaseLockedError() + logging.debug('got write lock') + + # make this a transaction + db.begin_atomic() + logging.debug('got atomic') + + if cmd == 'add': + logging.debug('add') + path, tags = current_item[2:] + msg, _ = db.add_message(path, sync_maildir_flags=sync) + logging.debug('added msg') + msg.freeze() + logging.debug('freeze') + for tag in tags: + msg.add_tag(tag, sync_maildir_flags=sync) + logging.debug('added tags ') + msg.thaw() + logging.debug('thaw') + + elif cmd == 'setconfig': + key = current_item[2] + value = current_item[3] + db.set_config(key, value) + + else: # tag/set/untag + querystring, tags = current_item[2:] + query = db.create_query(querystring) + for msg in query.search_messages(): msg.freeze() - logging.debug('freeze') + if cmd == 'tag': + strategy = msg.add_tag + if cmd == 'set': + msg.remove_all_tags() + strategy = msg.add_tag + elif cmd == 'untag': + strategy = msg.remove_tag for tag in tags: - msg.add_tag(tag, sync_maildir_flags=sync) - logging.debug('added tags ') + strategy(tag, sync_maildir_flags=sync) msg.thaw() - logging.debug('thaw') - - elif cmd == 'setconfig': - key = current_item[2] - value = current_item[3] - db.set_config(key, value) - - else: # tag/set/untag - querystring, tags = current_item[2:] - query = db.create_query(querystring) - for msg in query.search_messages(): - msg.freeze() - if cmd == 'tag': - strategy = msg.add_tag - if cmd == 'set': - msg.remove_all_tags() - strategy = msg.add_tag - elif cmd == 'untag': - strategy = msg.remove_tag - for tag in tags: - strategy(tag, sync_maildir_flags=sync) - msg.thaw() - - logging.debug('ended atomic') - # end transaction and reinsert queue item on error - if db.end_atomic() != notmuch.STATUS.SUCCESS: - raise DatabaseError('end_atomic failed') - logging.debug('ended atomic') - - # close db - db.close() - logging.debug('closed db') - - # call post-callback - if callable(afterwards): - logging.debug(str(afterwards)) - afterwards() - logging.debug('called callback') - - # re-insert item to the queue upon Xapian/NotmuchErrors - except (XapianError, NotmuchError) as e: - logging.exception(e) - self.writequeue.appendleft(current_item) - raise DatabaseError(str(e)) - except DatabaseLockedError as e: - logging.debug('index temporarily locked') - self.writequeue.appendleft(current_item) - raise e - logging.debug('flush finished') + + logging.debug('ended atomic') + # end transaction and reinsert queue item on error + if db.end_atomic() != notmuch.STATUS.SUCCESS: + raise DatabaseError('end_atomic failed') + logging.debug('ended atomic') + + # close db + db.close() + logging.debug('closed db') + + # call post-callback + if callable(afterwards): + logging.debug(str(afterwards)) + afterwards() + logging.debug('called callback') + + # re-insert item to the queue upon Xapian/NotmuchErrors + except (XapianError, NotmuchError) as e: + logging.exception(e) + self.writequeue.appendleft(current_item) + raise DatabaseError(str(e)) + except DatabaseLockedError as e: + logging.debug('index temporarily locked') + self.writequeue.appendleft(current_item) + raise e + logging.debug('flush finished') def kill_search_processes(self): """ |