summaryrefslogtreecommitdiff
path: root/alot/db/__init__.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-03-18 22:02:04 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-05-17 15:38:58 +0100
commit6b28e35677a25b967afd2679ff157a896de7f124 (patch)
tree3e039618fc8c7cea0dcaf55532201d2e5cbf7994 /alot/db/__init__.py
parentb7541e8159f800a9e376c6af99591bc00c69bd12 (diff)
neater error handling while flushing
this avoids logging a traceback on temporarily locked indices and imports db.error classes directly for use in DBManager
Diffstat (limited to 'alot/db/__init__.py')
-rw-r--r--alot/db/__init__.py36
1 files changed, 19 insertions, 17 deletions
diff --git a/alot/db/__init__.py b/alot/db/__init__.py
index 92b73258..674ae55e 100644
--- a/alot/db/__init__.py
+++ b/alot/db/__init__.py
@@ -8,8 +8,10 @@ from collections import deque
from message import Message
from alot.settings import settings
from thread import Thread
-
-import errors
+from errors import DatabaseError
+from errors import DatabaseLockedError
+from errors import DatabaseROError
+from errors import NonexistantObjectError
DB_ENC = 'utf-8'
@@ -63,11 +65,11 @@ class DBManager(object):
You are responsible to retry flushing at a later time if you want to
ensure that the cached changes are applied to the database.
- :exception: :exc:`errors.DatabaseROError` if db is opened read-only
- :exception: :exc:`errors.DatabaseLockedError` if db is locked
+ :exception: :exc:`~errors.DatabaseROError` if db is opened read-only
+ :exception: :exc:`~errors.DatabaseLockedError` if db is locked
"""
if self.ro:
- raise errors.DatabaseROError()
+ raise DatabaseROError()
if self.writequeue:
# read notmuch's config regarding imap flag synchronization
sync = settings.get_notmuch_setting('maildir', 'synchronize_flags')
@@ -129,7 +131,7 @@ class DBManager(object):
# end transaction and reinsert queue item on error
if db.end_atomic() != notmuch.STATUS.SUCCESS:
- raise errors.DatabaseError('end_atomic failed')
+ raise DatabaseError('end_atomic failed')
# close db
db.close()
@@ -144,7 +146,7 @@ class DBManager(object):
self.writequeue.appendleft(current_item)
raise DatabaseError(unicode(e))
except DatabaseLockedError as e:
- logging.exception(e)
+ logging.debug('index temporarily locked')
self.writequeue.appendleft(current_item)
raise e
@@ -161,7 +163,7 @@ class DBManager(object):
"""
add tags to messages matching `querystring`.
This appends a tag operation to the write queue and raises
- :exc:`errors.DatabaseROError` if in read only mode.
+ :exc:`~errors.DatabaseROError` if in read only mode.
:param querystring: notmuch search string
:type querystring: str
@@ -172,13 +174,13 @@ class DBManager(object):
:type afterwards: callable
:param remove_rest: remove tags from matching messages before tagging
:type remove_rest: bool
- :exception: :exc:`errors.DatabaseROError`
+ :exception: :exc:`~errors.DatabaseROError`
.. note::
You need to call :meth:`DBManager.flush` to actually write out.
"""
if self.ro:
- raise errors.DatabaseROError()
+ raise DatabaseROError()
if remove_rest:
self.writequeue.append(('set', afterwards, querystring, tags))
else:
@@ -188,7 +190,7 @@ class DBManager(object):
"""
removes tags from messages that match `querystring`.
This appends an untag operation to the write queue and raises
- :exc:`errors.DatabaseROError` if in read only mode.
+ :exc:`~errors.DatabaseROError` if in read only mode.
:param querystring: notmuch search string
:type querystring: str
@@ -197,13 +199,13 @@ class DBManager(object):
:param afterwards: callback that gets called after successful
application of this tagging operation
:type afterwards: callable
- :exception: :exc:`errors.DatabaseROError`
+ :exception: :exc:`~errors.DatabaseROError`
.. note::
You need to call :meth:`DBManager.flush` to actually write out.
"""
if self.ro:
- raise errors.DatabaseROError()
+ raise DatabaseROError()
self.writequeue.append(('untag', afterwards, querystring, tags))
def count_messages(self, querystring):
@@ -231,7 +233,7 @@ class DBManager(object):
return query.search_threads().next()
except StopIteration:
errmsg = 'no thread with id %s exists!' % tid
- raise errors.NonexistantObjectError(errmsg)
+ raise NonexistantObjectError(errmsg)
def get_thread(self, tid):
"""returns :class:`Thread` with given thread id (str)"""
@@ -245,7 +247,7 @@ class DBManager(object):
return db.find_message(mid)
except:
errmsg = 'no message with id %s exists!' % mid
- raise errors.NonexistantObjectError(errmsg)
+ raise NonexistantObjectError(errmsg)
def get_message(self, mid):
"""returns :class:`Message` with given message id (str)"""
@@ -325,7 +327,7 @@ class DBManager(object):
:type afterwards: callable or None
"""
if self.ro:
- raise errors.DatabaseROError()
+ raise DatabaseROError()
self.writequeue.append(('add', afterwards, path, tags))
def remove_message(self, message, afterwards=None):
@@ -338,6 +340,6 @@ class DBManager(object):
:type afterwards: callable or None
"""
if self.ro:
- raise errors.DatabaseROError()
+ raise DatabaseROError()
path = message.get_filename()
self.writequeue.append(('remove', afterwards, path))