From: Ethan Glasser-Camp Date: Wed, 15 Feb 2012 22:01:56 +0000 (+1900) Subject: [RFC PATCH 03/13] Introduce mailstore in the python bindings X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=9c8cc6f362b8d0a334aa9c9b54f3606f4240e004;p=notmuch-archives.git [RFC PATCH 03/13] Introduce mailstore in the python bindings --- diff --git a/f2/ac6423fc4d634665bd34482fd4b370ca68b8f6 b/f2/ac6423fc4d634665bd34482fd4b370ca68b8f6 new file mode 100644 index 000000000..f0a9e8e9c --- /dev/null +++ b/f2/ac6423fc4d634665bd34482fd4b370ca68b8f6 @@ -0,0 +1,249 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 3E774429E43 + for ; Wed, 15 Feb 2012 14:06:01 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.54 +X-Spam-Level: +X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3, + RCVD_IN_SORBS_WEB=0.614] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id AGWL35BsDslV for ; + Wed, 15 Feb 2012 14:05:57 -0800 (PST) +Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu + [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS + id 4865F431E84 for ; Wed, 15 Feb 2012 14:05:57 -0800 + (PST) +X-Hash: + S|a5576c7a0879cdcb947f4f187d2cb881f84fe767|3108d4ff51f659d951563fa092480fc6 +X-Countries: Cameroon, United States +X-SMTP-From: accepted [195.24.209.20] [195.24.209.20] + (localhost) {Cameroon} +DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from + :to:cc:subject:date:message-id:in-reply-to:references; s= + default; i=glasse@cs.rpi.edu; t=1329343555; x=1329948355; l=6302; + bh=xqCkkenyPqaR9+qkgrhnSOEGp8c=; b=E28AwTlbi+ZvfI6i/WJgSSd + 72/sQMaeuBwnOkH8K8DYEAJb75uImAOaBOrTAXNBka7xQoE2E6X6dnujDSCiucSF + +6tfHj1+b9jFt8IICMX1GvjIJOC4gcGnmbGO8Iuo93HwkQitBzJqgpPecb3heRFR + 88ZyxZ4cBo+wo6x0nkyA= +DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc + :subject:date:message-id:in-reply-to:references; q=dns; s= + default; b=Xmcurs/GUda4Y5HviM8tJTMfcm4qcwtMVwxRTv+hksoFexm4N9Ai7 + 0CtFflAdbYASlcgG/SK82SeklNukDlLjprgdbW8sCkKiIbq8RmDZ83+3FbD6z/Ea + 9IckCs1CRKzPQcZkJrZ57TXBAHCWW7o3v4pCKJHgJpKUVoVLSpXbek= +X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00 +X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit + 15) +Authentication-Results: cliffclavin.cs.rpi.edu; + DKIM=neutral (none) header.from=glasse@cs.rpi.edu; + SPF=neutral (mfrom; + Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu +X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FM5RID008763 Auth:glasse +X-Virus-Scanned-By: cliffclavin.cs.rpi.edu +Received: from localhost ([195.24.209.20]) (authenticated bits=0) + by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FM5RID008763 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); + Wed, 15 Feb 2012 17:05:40 -0500 (EST) + (envelope-from glasse@cs.rpi.edu) +From: Ethan Glasser-Camp +To: notmuch@notmuchmail.org +Subject: [RFC PATCH 03/13] Introduce mailstore in the python bindings +Date: Wed, 15 Feb 2012 17:01:56 -0500 +Message-Id: <1329343326-16410-4-git-send-email-glasse@cs.rpi.edu> +X-Mailer: git-send-email 1.7.5.4 +In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> +References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> +X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25 +Cc: Ethan Glasser-Camp +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Wed, 15 Feb 2012 22:06:01 -0000 + +From: Ethan Glasser-Camp + + +Signed-off-by: Ethan Glasser-Camp +--- + 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 . ++ ++Copyright 2012 Ethan Glasser-Camp ' ++""" ++ ++# 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 +