diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-01-04 15:20:39 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-01-04 15:20:39 +0100 |
commit | 71dfea04c7ff73444902c2e796df8700fde17307 (patch) | |
tree | 67658cfad7c728420179bf0f44864d9db1420fe7 /hyperkitty/archiver.py | |
parent | 015596867024364377c35b305043d99876e52816 (diff) | |
download | hyperkitty-71dfea04c7ff73444902c2e796df8700fde17307.tar.gz hyperkitty-71dfea04c7ff73444902c2e796df8700fde17307.tar.xz hyperkitty-71dfea04c7ff73444902c2e796df8700fde17307.zip |
Move the archiver module to the root of the distribution
Diffstat (limited to 'hyperkitty/archiver.py')
-rw-r--r-- | hyperkitty/archiver.py | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/hyperkitty/archiver.py b/hyperkitty/archiver.py new file mode 100644 index 0000000..b8437a8 --- /dev/null +++ b/hyperkitty/archiver.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 1998-2012 by the Free Software Foundation, Inc. +# +# This file is part of HyperKitty. +# +# HyperKitty 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. +# +# HyperKitty 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 +# HyperKitty. If not, see <http://www.gnu.org/licenses/>. +# +# Author: Aurelien Bompard <abompard@fedoraproject.org> +# + +""" +Class implementation of Mailman's IArchiver interface +""" + +import os +import sys +from urlparse import urljoin + +from zope.interface import implements +from mailman.interfaces.archiver import IArchiver +from mailman.config import config +from mailman.config.config import external_configuration +from django.core.urlresolvers import reverse +from kittystore import get_store +from kittystore.utils import get_message_id_hash + + +class Archiver(object): + + implements(IArchiver) + + name = "hyperkitty" + + def __init__(self): + self.store = None + self.store_url = None + self._load_conf() + + def _load_conf(self): + """ + Find the location of the Django settings module from Mailman's + configuration file, and load it to get the store's URL. + """ + # Read our specific configuration file + archiver_config = external_configuration( + config.archiver.hyperkitty.configuration) + settings_path = archiver_config.get("general", "django_settings") + if settings_path.endswith("/settings.py"): + # we want the directory + settings_path = os.path.dirname(settings_path) + #path_added = False + if settings_path not in sys.path: + #path_added = True + sys.path.append(settings_path) + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") + try: + from django.conf import settings + except ImportError: + raise ImportError("Could not import Django's settings from %s" + % settings_path) + self.store_url = settings.KITTYSTORE_URL + #if path_added: + # sys.path.remove(settings_path) + + def list_url(self, mlist): + """Return the url to the top of the list's archive. + + :param mlist: The IMailingList object. + :returns: The url string. + """ + return urljoin(self.store_url, + reverse('archives', args=[mlist.fqdn_listname])) + + def permalink(self, mlist, msg): + """Return the url to the message in the archive. + + This url points directly to the message in the archive. This method + only calculates the url, it does not actually archive the message. + + :param mlist: The IMailingList object. + :param msg: The message object. + :returns: The url string or None if the message's archive url cannot + be calculated. + """ + msg_id = msg['Message-Id'].strip().strip("<>") + msg_hash = get_message_id_hash(msg_id) + return urljoin(self.store_url, reverse('message_index', + kwargs={"mlist_fqdn": mlist.fqdn_listname, + "hashid": msg_hash})) + + def archive_message(self, mlist, msg): + """Send the message to the archiver. + + :param mlist: The IMailingList object. + :param msg: The message object. + :returns: The url string or None if the message's archive url cannot + be calculated. + """ + if self.store is None: + self.store = get_store(self.store_url) + msg.message_id_hash = self.store.add_to_list(mlist, msg) + self.store.commit() + # TODO: Update karma + return msg.message_id_hash |