summaryrefslogtreecommitdiff
path: root/Mailman/database/listmanager.py
diff options
context:
space:
mode:
authorbwarsaw2007-05-28 20:21:41 +0000
committerbwarsaw2007-05-28 20:21:41 +0000
commitb18f632faa6de17badabb3c6c7ba61752ac84c37 (patch)
tree8b444330b288c5dfc9b25be639d429abfaeb3d3d /Mailman/database/listmanager.py
parent5ff792b13599920527b48f92f8bad880668f8f26 (diff)
downloadmailman-b18f632faa6de17badabb3c6c7ba61752ac84c37.tar.gz
mailman-b18f632faa6de17badabb3c6c7ba61752ac84c37.tar.zst
mailman-b18f632faa6de17badabb3c6c7ba61752ac84c37.zip
Diffstat (limited to 'Mailman/database/listmanager.py')
-rw-r--r--Mailman/database/listmanager.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/Mailman/database/listmanager.py b/Mailman/database/listmanager.py
new file mode 100644
index 000000000..de8abbd58
--- /dev/null
+++ b/Mailman/database/listmanager.py
@@ -0,0 +1,81 @@
+# Copyright (C) 2007 by the Free Software Foundation, Inc.
+#
+# This program 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 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+"""SQLAlchemy/Elixir based provider of IListManager."""
+
+import weakref
+
+from elixir import *
+from zope.interface import implements
+
+from Mailman import Errors
+from Mailman.Utils import split_listname, fqdn_listname
+from Mailman.configuration import config
+from Mailman.database.model import MailingList
+from Mailman.interfaces import IListManager
+
+
+
+class ListManager(object):
+ implements(IListManager)
+
+ def __init__(self):
+ self._objectmap = weakref.WeakKeyDictionary()
+
+ def create(self, fqdn_listname):
+ listname, hostname = split_listname(fqdn_listname)
+ mlist = MailingList.get_by(list_name=listname,
+ host_name=hostname)
+ if mlist:
+ raise Errors.MMListAlreadyExistsError(fqdn_listname)
+ mlist = MailingList(fqdn_listname)
+ # Wrap the database model object in an application MailList object and
+ # return the latter. Keep track of the wrapper so we can clean it up
+ # when we're done with it.
+ from Mailman.MailList import MailList
+ wrapper = MailList(mlist)
+ self._objectmap[mlist] = wrapper
+ return wrapper
+
+ def delete(self, mlist):
+ # Delete the wrapped backing data. XXX It's kind of icky to reach
+ # into the MailList object this way.
+ mlist._data.delete_rosters()
+ mlist._data.delete()
+ mlist._data = None
+
+ def get(self, fqdn_listname):
+ listname, hostname = split_listname(fqdn_listname)
+ mlist = MailingList.get_by(list_name=listname,
+ host_name=hostname)
+ if not mlist:
+ raise Errors.MMUnknownListError(fqdn_listname)
+ from Mailman.MailList import MailList
+ wrapper = self._objectmap.setdefault(mlist, MailList(mlist))
+ return wrapper
+
+ @property
+ def mailing_lists(self):
+ # Don't forget, the MailingList objects that this class manages must
+ # be wrapped in a MailList object as expected by this interface.
+ for fqdn_listname in self.names:
+ yield self.get(fqdn_listname)
+
+ @property
+ def names(self):
+ for mlist in MailingList.select():
+ yield fqdn_listname(mlist.list_name, mlist.host_name)