Run a mailman program outside of mailman shell
Hi again folks. I have hundreds of lists to convert from MM2.1 to MM3, and intend to write a Python program do this this rather than running commands in mailman shell (and rather than running 'command()' functions in mailman shell, if possible).
However, when I write a simple Python program to run the types of commands found in the Mailman docs, such as these <https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/commands/docs/shell.html>, I get errors. This is a venv installation, following these instructions <https://docs.mailman3.org/en/latest/install/virtualenv.html>. The Mailman3 installation is working fine and I have a handful of lists in production that I set up manually.
Here's a very simple program, import-try1.py, just to create a list: #!/opt/mailman/venv/bin/python3
from mailman.app.lifecycle import create_list l = create_list('testlist2@lists.aaabbb.org')
Here's the output I get (yes, the domain exists and already has lists - I'm putting aaabbb instead of the actual domain name):
./import-try1.py Traceback (most recent call last): File "/opt/mailman/./import-try1.py", line 4, in <module> l = create_list('testlist2@lists.aaabbb.org') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.12/site-packages/mailman/app/lifecycle.py", line 74, in create_list getUtility(IEmailValidator).validate(fqdn_listname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.12/site-packages/zope/component/_api.py", line 180, in getUtility raise ComponentLookupError(interface, name) zope.interface.interfaces.ComponentLookupError: (<InterfaceClass mailman.interfaces.address.IEmailValidator>, '')
I get different errors with other sets of commands. The same commands work
fine from mailman shell
, i.e.,
(venv) mailman@mail:~$ mailman shell Welcome to the GNU Mailman3 shell on aaabbb.org
from mailman.app.lifecycle import create_list l = create_list('testlist2@lists.aaabbb.org')
Output from mailman info, with the passwords omitted:
GNU Mailman 3.3.9 (Tom Sawyer) Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] config file: /etc/mailman3/mailman.cfg db url: postgresql://mailman:secretaaabbb@localhost/mailman devmode: DISABLED REST root url: http://localhost:8001/3.1/ REST credentials: restadmin:reallysecretaaabbb
I suspect I just need to either change the interpreter (1st line of my program), or find the correct 'import' lines (I've tried numerous variations; the above is the simplest example). Help will be appreciated! Greg
On Tue, Jul 23, 2024 at 11:18 PM Greg Newby <gbnewby@petascale.org> wrote:
Hi again folks. I have hundreds of lists to convert from MM2.1 to MM3, and intend to write a Python program do this this rather than running commands in mailman shell (and rather than running 'command()' functions in mailman shell, if possible).
, I get errors. This is a venv installation, following these instructions <https://docs.mailman3.org/en/latest/install/virtualenv.html>. The Mailman3 installation is working fine and I have a handful of lists in production
However, when I write a simple Python program to run the types of commands found in the Mailman docs, such as these < https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/commands/do... that I set up manually.
Okay. Not to go against your favorite method, but looks to me that you're killing a feal with a hammer!
I had some 10 lists to migrate from MM2 to MM3 and I simply did the migrations using bash a shell command line.
for l in list1 list2 list3 ...listN; do blah blah; done
...as documented here: https://docs.mailman3.org/en/latest/migration.html
-- Best regards, Odhiambo WASHINGTON, Nairobi,KE +254 7 3200 0004/+254 7 2274 3223 In an Internet failure case, the #1 suspect is a constant: DNS. "Oh, the cruft.", egrep -v '^$|^.*#' ¯\_(ツ)_/¯ :-) [How to ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html]
Hi Odhiambo. Thanks for your suggestion. Yes, I know how to write a shell script, and also how to run mailman shell commands from within a Python program.
By writing my own Python program with the native mailman functions, I'll be able to more easily confirm functions ran correctly and test for exceptions. The other methods don't make that very easy.
Greg Newby
On Tue, Jul 23, 2024 at 11:40 PM Greg Newby <gbnewby@petascale.org> wrote:
Hi Odhiambo. Thanks for your suggestion. Yes, I know how to write a shell script, and also how to run mailman shell commands from within a Python program
I did not mean the 'mailman shell' commands. Just the shell invocation of the migration.
-- Best regards, Odhiambo WASHINGTON, Nairobi,KE +254 7 3200 0004/+254 7 2274 3223 In an Internet failure case, the #1 suspect is a constant: DNS. "Oh, the cruft.", egrep -v '^$|^.*#' ¯\_(ツ)_/¯ :-) [How to ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html]
Hi,
I also would like to have an answer to this.
I was successful using the mailmanclient and the REST-API as described here: https://docs.mailman3.org/projects/mailmanclient/en/latest/src/mailmanclient...
With this you have the same usecases as pistorius can handle in your python scripts
Oli
Am 23.07.24 um 22:17 schrieb Greg Newby:
Hi again folks. I have hundreds of lists to convert from MM2.1 to MM3, and intend to write a Python program do this this rather than running commands in mailman shell (and rather than running 'command()' functions in mailman shell, if possible).
However, when I write a simple Python program to run the types of commands found in the Mailman docs, such as these <https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/commands/docs/shell.html>, I get errors. This is a venv installation, following these instructions <https://docs.mailman3.org/en/latest/install/virtualenv.html>. The Mailman3 installation is working fine and I have a handful of lists in production that I set up manually.
Here's a very simple program, import-try1.py, just to create a list: #!/opt/mailman/venv/bin/python3
from mailman.app.lifecycle import create_list l = create_list('testlist2@lists.aaabbb.org')
Here's the output I get (yes, the domain exists and already has lists - I'm putting aaabbb instead of the actual domain name):
./import-try1.py Traceback (most recent call last): File "/opt/mailman/./import-try1.py", line 4, in <module> l = create_list('testlist2@lists.aaabbb.org') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.12/site-packages/mailman/app/lifecycle.py", line 74, in create_list getUtility(IEmailValidator).validate(fqdn_listname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.12/site-packages/zope/component/_api.py", line 180, in getUtility raise ComponentLookupError(interface, name) zope.interface.interfaces.ComponentLookupError: (<InterfaceClass mailman.interfaces.address.IEmailValidator>, '')
I get different errors with other sets of commands. The same commands work fine from
mailman shell
, i.e.,(venv) mailman@mail:~$ mailman shell Welcome to the GNU Mailman3 shell on aaabbb.org
from mailman.app.lifecycle import create_list l = create_list('testlist2@lists.aaabbb.org')
Output from mailman info, with the passwords omitted:
GNU Mailman 3.3.9 (Tom Sawyer) Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] config file: /etc/mailman3/mailman.cfg db url: postgresql://mailman:secretaaabbb@localhost/mailman devmode: DISABLED REST root url: http://localhost:8001/3.1/ REST credentials: restadmin:reallysecretaaabbb
I suspect I just need to either change the interpreter (1st line of my program), or find the correct 'import' lines (I've tried numerous variations; the above is the simplest example). Help will be appreciated! Greg
Mailman-users mailing list -- mailman-users@mailman3.org To unsubscribe send an email to mailman-users-leave@mailman3.org https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/ Archived at: https://lists.mailman3.org/archives/list/mailman-users@mailman3.org/message/...
This message sent to o.graeber@jpberlin.de
On 7/23/24 13:17, Greg Newby wrote:
Here's a very simple program, import-try1.py, just to create a list: #!/opt/mailman/venv/bin/python3
Here you need
from mailman.core import initialize initialize.initialize()
from mailman.app.lifecycle import create_list l = create_list('testlist2@lists.aaabbb.org')
With that, I think it will work.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
participants (4)
-
Greg Newby
-
Mark Sapiro
-
Odhiambo Washington
-
Oliver Gräber