From 16f1868a56403a11f6ee0f7830be04eff346d544 Mon Sep 17 00:00:00 2001 From: pazz Date: Sat, 9 Jul 2011 22:24:29 +0100 Subject: make sure read-only mode dowsn't write this is the first part of a fix for issur #13 --- alot/db.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'alot/db.py') diff --git a/alot/db.py b/alot/db.py index 6377f422..05e8c313 100644 --- a/alot/db.py +++ b/alot/db.py @@ -27,6 +27,9 @@ import helper DB_ENC = 'utf8' +class DatabaseError(Exception): + pass + class DBManager: """ @@ -43,11 +46,14 @@ class DBManager: """ tries to flush all queued write commands to the index """ + if self.ro: + raise DatabaseError('Readonly mode!') if self.writequeue: try: mode = Database.MODE.READ_WRITE db = Database(path=self.path, mode=mode) except NotmuchError: + # TODO: decapsulate ui here. maybe use self.eventloop here if self.ui: # let the mainloop call us again after timeout timeout = config.getint('general', 'flush_retry_timeout') self.ui.update() @@ -86,6 +92,8 @@ class DBManager: :param remove_rest: remove tags from matching messages before tagging :type remove_rest: boolean """ + if self.ro: + raise DatabaseError('Readonly mode!') if remove_rest: self.writequeue.append(('set', querystring, tags)) else: @@ -101,6 +109,8 @@ class DBManager: :param tags: a list of tags to be added :type tags: list of str """ + if self.ro: + raise DatabaseError('Readonly mode!') self.writequeue.append(('untag', querystring, tags)) self.flush() -- cgit v1.2.3