skip to Main Content

I am trying to access members of an existing Mailman 3 mailing list directly from Django Management console on a Debian Bullseye where Mailman is installed from deb packages (mailman3-full). I can connect to the Django admin console like this (all 3 variants seem to work fine):

$ /usr/share/mailman3-web/manage.py shell
$ mailman-web shell
$ mailman-web shell --settings /etc/mailman3/mailman-web.py
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
>>> 

But inside the Django admin console, some mailman components seem to be missing.

I try to access the list manager as described here: Docs > Models > The mailing list manager:

>>> from mailman.interfaces.listmanager import IListManager
>>> from zope.component import getUtility
>>> list_manager = getUtility(IListManager)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/zope/component/_api.py", line 169, in getUtility
    raise ComponentLookupError(interface, name)
zope.interface.interfaces.ComponentLookupError: (<InterfaceClass mailman.interfaces.listmanager.IListManager>, '')

Can’t figure out why this ComponentLookupError happens.

Also tried to acccess a list with the ListManager implementation:

>>> from mailman.config import config
>>> from mailman.model.listmanager import ListManager
>>> list_manager = ListManager()

>>> list_manager.get('[email protected]')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/mailman/database/transaction.py", line 85, in wrapper
    return function(args[0], config.db.store, *args[1:], **kws)
AttributeError: 'NoneType' object has no attribute 'store'

>>> list_manager.get_by_list_id('mynews.example.com')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/mailman/database/transaction.py", line 85, in wrapper
    return function(args[0], config.db.store, *args[1:], **kws)
AttributeError: 'NoneType' object has no attribute 'store'

What am I doing wrong here? None of the examples in the Mailman 3 models documentation is working if I don’t even get that far.

any help greatly appreciated!

2

Answers


  1. Chosen as BEST ANSWER

    So mailman shell works great and I could run this interactively:

    from mailman.interfaces.listmanager import IListManager
    from zope.component import getUtility
    from mailman.testing.documentation import dump_list
    from operator import attrgetter
    
    def dump_members(roster):
        all_addresses = list(member.address for member in roster)
        sorted_addresses = sorted(all_addresses, key=attrgetter('email'))
        dump_list(sorted_addresses)
    
    list_manager = getUtility(IListManager)
    mlist = list_manager.get('[email protected]')
    dump_members(mlist.members.members)
    

    but how could I put this into a script that could be run with mailman withlist -r listmembers -l [email protected]?

    from mailman.testing.documentation import dump_list
    from operator import attrgetter
    
    def listmembers(mlist):
        roster = mlist.members.members
        all_addresses = list(member.address for member in roster)
        sorted_addresses = sorted(all_addresses, key=attrgetter('email'))
        dump_list(sorted_addresses)
    

    where would I put such a listmembers.py runner? I tried to put it into /usr/lib/python3/dist-packages/mailman/runners directory, but didn't work:

    $ mailman withlist -r listmembers -l [email protected]
    ModuleNotFoundError: No module named 'listmembers'
    

    Thanks!


  2. It’s just the wrong shell you are using. You should use Mailman core shell instead.

    It is accessible via just mailman shell in your system most probably.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search