From: Ethan Glasser-Camp <glasse@cs.rpi.edu>
To: notmuch@notmuchmail.org
Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
Subject: [RFC PATCH 03/13] Introduce mailstore in the python bindings
Date: Wed, 15 Feb 2012 17:01:56 -0500 [thread overview]
Message-ID: <1329343326-16410-4-git-send-email-glasse@cs.rpi.edu> (raw)
In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
From: Ethan Glasser-Camp <ethan@betacantrips.com>
Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
---
bindings/python/notmuch/database.py | 31 +++++++++++++++++---------
bindings/python/notmuch/globals.py | 3 ++
bindings/python/notmuch/mailstore.py | 38 ++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 11 deletions(-)
create mode 100644 bindings/python/notmuch/mailstore.py
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 36b65ec..638ade3 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -23,7 +23,9 @@ from ctypes import c_char_p, c_void_p, c_uint, c_long, byref, POINTER
from notmuch.globals import (nmlib, STATUS, NotmuchError, NotInitializedError,
NullPointerError, Enum, _str,
NotmuchDatabaseP, NotmuchDirectoryP, NotmuchMessageP, NotmuchTagsP,
- NotmuchQueryP, NotmuchMessagesP, NotmuchThreadsP, NotmuchFilenamesP)
+ NotmuchQueryP, NotmuchMessagesP, NotmuchThreadsP, NotmuchFilenamesP,
+ NotmuchMailstoreP)
+from notmuch.mailstore import Mailstore
from notmuch.thread import Threads
from notmuch.message import Messages, Message
from notmuch.tag import Tags
@@ -78,7 +80,7 @@ class Database(object):
"""notmuch_database_open"""
_open = nmlib.notmuch_database_open
- _open.argtypes = [c_char_p, c_uint]
+ _open.argtypes = [NotmuchMailstoreP, c_char_p, c_uint]
_open.restype = NotmuchDatabaseP
"""notmuch_database_upgrade"""
@@ -105,11 +107,13 @@ class Database(object):
"""notmuch_database_create"""
_create = nmlib.notmuch_database_create
- _create.argtypes = [c_char_p]
+ _create.argtypes = [NotmuchMailstoreP, c_char_p]
_create.restype = NotmuchDatabaseP
- def __init__(self, path=None, create=False, mode=0):
- """If *path* is `None`, we will try to read a users notmuch
+ def __init__(self, mailstore=None, path=None, create=False, mode=0):
+ """If *mailstore* is `None`, we will just use 'maildir'.
+
+ If *path* is `None`, we will try to read a users notmuch
configuration and use his configured database. The location of the
configuration file can be specified through the environment variable
*NOTMUCH_CONFIG*, falling back to the default `~/.notmuch-config`.
@@ -130,6 +134,9 @@ class Database(object):
failure.
"""
self._db = None
+ if mailstore == None:
+ mailstore = Mailstore('maildir')
+
if path is None:
# no path specified. use a user's default database
if Database._std_db_path is None:
@@ -138,16 +145,16 @@ class Database(object):
path = Database._std_db_path
if create == False:
- self.open(path, mode)
+ self.open(mailstore, path, mode)
else:
- self.create(path)
+ self.create(mailstore, path)
def _assert_db_is_initialized(self):
"""Raises :exc:`NotInitializedError` if self._db is `None`"""
if self._db is None:
raise NotInitializedError()
- def create(self, path):
+ def create(self, mailstore, path):
"""Creates a new notmuch database
This function is used by __init__() and usually does not need
@@ -167,14 +174,15 @@ class Database(object):
raise NotmuchError(message="Cannot create db, this Database() "
"already has an open one.")
- res = Database._create(_str(path), Database.MODE.READ_WRITE)
+ mailstore = mailstore._mailstore
+ res = Database._create(mailstore, _str(path), Database.MODE.READ_WRITE)
if not res:
raise NotmuchError(
message="Could not create the specified database")
self._db = res
- def open(self, path, mode=0):
+ def open(self, mailstore, path, mode=0):
"""Opens an existing database
This function is used by __init__() and usually does not need
@@ -187,7 +195,8 @@ class Database(object):
:exception: Raises :exc:`NotmuchError` in case of any failure
(possibly after printing an error message on stderr).
"""
- res = Database._open(_str(path), mode)
+ mailstore = mailstore._mailstore # unwrap mailstore
+ res = Database._open(mailstore, _str(path), mode)
if not res:
raise NotmuchError(message="Could not open the specified database")
diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
index 4138460..5f01dce 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -228,6 +228,9 @@ class NotmuchDatabaseS(Structure):
pass
NotmuchDatabaseP = POINTER(NotmuchDatabaseS)
+class NotmuchMailstoreS(Structure):
+ pass
+NotmuchMailstoreP = POINTER(NotmuchMailstoreS)
class NotmuchQueryS(Structure):
pass
diff --git a/bindings/python/notmuch/mailstore.py b/bindings/python/notmuch/mailstore.py
new file mode 100644
index 0000000..315ea70
--- /dev/null
+++ b/bindings/python/notmuch/mailstore.py
@@ -0,0 +1,38 @@
+"""
+This file is part of notmuch.
+
+Notmuch is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Notmuch is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with notmuch. If not, see <http://www.gnu.org/licenses/>.
+
+Copyright 2012 Ethan Glasser-Camp <ethan@betacantrips.com>'
+"""
+
+# This is all kind of cargo-culted from database.py. I hope someone
+# else takes a good look at this!
+
+import os
+from ctypes import c_char_p, c_void_p, c_uint, c_long, byref, POINTER
+from notmuch.globals import (nmlib, STATUS, NotmuchError, NotInitializedError,
+ NullPointerError, Enum, _str,
+ NotmuchDatabaseP, NotmuchDirectoryP, NotmuchMessageP, NotmuchTagsP,
+ NotmuchQueryP, NotmuchMessagesP, NotmuchThreadsP, NotmuchFilenamesP,
+ NotmuchMailstoreP,)
+
+class Mailstore(object):
+ """The :class:`Mailstore` represents "where the mail lives"."""
+ _get_by_name = nmlib.notmuch_mailstore_get_by_name
+ _get_by_name.argtypes = [c_char_p]
+ _get_by_name.restype = NotmuchMailstoreP
+
+ def __init__(self, type=None, path=None):
+ self._mailstore = self._get_by_name(type)
--
1.7.5.4
next prev parent reply other threads:[~2012-02-15 22:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-15 22:01 [RFC PATCH 00/13] Modular message store code Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 01/13] Create configuration paramater database.type Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 02/13] Add the concept of a mailstore in its absolute minimal sense Ethan Glasser-Camp
2012-02-15 22:01 ` Ethan Glasser-Camp [this message]
2012-02-15 22:01 ` [RFC PATCH 04/13] Replace remaining places where fopen occurs Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 05/13] notmuch_database_add_message calculates sha1 of messages using mailstore Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 06/13] Pass mailstore to _notmuch_message_index_file Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 07/13] notmuch-new: pull out useful bits of add_files_recursive Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 08/13] count_files and add_files shall be generic Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 09/13] Mailstore also provides a "rename" function Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 10/13] Introduce concept of mailstore "constructor" Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 11/13] Add a close function to mailstore Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 12/13] Close files using notmuch_mailstore_close instead of fclose Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 13/13] First crack at a CouchDB mailstore Ethan Glasser-Camp
2012-02-16 0:56 ` [RFC PATCH 00/13] Modular message store code Mark Walters
2012-03-01 13:51 ` Ethan Glasser-Camp
2012-02-16 7:47 ` Stewart Smith
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1329343326-16410-4-git-send-email-glasse@cs.rpi.edu \
--to=glasse@cs.rpi.edu \
--cc=ethan@betacantrips.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).