Determining if a user or list has moderation

I'm trying to write a script to determine what lists have users that have moderation turned on. I found the following example in the list archives using the withlist command
from Mailman import mm_cfg
def list_moderated(m): for member in m.getMembers(): if m.getMemberOption(member, mm_cfg.Moderate): print member
However when I run the command:
withlist -q -r checkModerated.py jww_test
I get the following error: Traceback (most recent call last): File "/home/mailman/bin/withlist", line 297, in ? main() File "/home/mailman/bin/withlist", line 269, in main func = getattr(mod, callable) AttributeError: 'module' object has no attribute 'py'
This seems pretty simple to me, but I don't have any python experience, this is my first brush with python. I do know perl, java and assorted other programming languages but you have to start somewhere when learning something new. Any help would be appreciated. Or you can forward this to your co-workers to make fun of the n00b.
Jeff Kunzelman Principal Systems Engineer - Messaging Infrastructure DHL Worldwide Express - AMIS 8701 East Hartford Drive Scottsdale, AZ 85255 USA

Hi You are calling the 'withlist' command wrong.
You havent specified what you put into the checkModerated.py script, but thats kinda by the by, since
from "withlist -h":
-r [module.]callable
This can be used to run a script with the opened MailList object.
This works by attempting to import `module' (which must be in the
directory containing withlist, or already be accessible on your
sys.path), and then calling `callable' from the module. callable can
be a class or function; it is called with the MailList object as the
first argument. If additional args are given on the command line,
they are passed as subsequent positional args to the callable.
Note that `module.' is optional; if it is omitted then a module with
the name `callable' will be imported.
The global variable `r' will be set to the results of this call.
if you use "-r" you need to call a function, not give it a script name (hence the error .. no ".py" attribute)
keep reading down that help screen, and .. " As another example, say you wanted to change the password for a particular user on a particular list. You could put the following function in a file called `changepw.py':
from Mailman.Errors import NotAMemberError
def changepw(mlist, addr, newpasswd): try: mlist.setMemberPassword(addr, newpasswd) mlist.Save() except NotAMemberError: print 'No address matched:', addr
and run this from the command line: % bin/withlist -l -r changepw mylist somebody@somewhere.org foobar
"
hope that helps ;)
andy
On 13/04/07, Jeff Kunzelman (DHL) <Jeff.Kunzelman@dhl.com> wrote:
-- andy nicholson +61 406 306 715

Jeff Kunzelman (DHL) wrote:
The help for withlist says
--run [module.]callable
-r [module.]callable
I realize this is cryptic, but in your case (module file name = checkModerated.py; function name/callable = list_moderated) it means the withlist command needs to be
withlist -q -r checkModerated.list_moderated jww_test
Note that the 'module name' does not include the .py suffix of the file name. Alternatively, if you named the file list_moderated.py, you could run it with
withlist -q -r list_moderated jww_test
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan

This answered my question, thanks a lot!
Is there an api anywhere that has a full list of all the objects you can use in mailman?
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Thursday, April 12, 2007 9:44 PM To: Jeff Kunzelman (DHL); mailman-developers@python.org Subject: Re: [Mailman-Developers] Determining if a user or list has moderation
Jeff Kunzelman (DHL) wrote:
The help for withlist says
--run [module.]callable
-r [module.]callable
I realize this is cryptic, but in your case (module file name = checkModerated.py; function name/callable = list_moderated) it means the withlist command needs to be
withlist -q -r checkModerated.list_moderated jww_test
Note that the 'module name' does not include the .py suffix of the file name. Alternatively, if you named the file list_moderated.py, you could run it with
withlist -q -r list_moderated jww_test
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Apr 13, 2007, at 1:58 PM, Jeff Kunzelman (DHL) wrote:
Not in Mailman 2.1. We'll do better next time! I have a bunch of
uncommitted changes that will start to use formal zope.interfaces to
document the important APIs.
- -Barry
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin)
iQCVAwUBRh/G6XEjvBPtnXfVAQLpFAQArxnYzhgm4j8wovitx+8ZtKEWzvf9pIq2 Q9OB1n8dF58Rym/l6Z9FVATeSOVsGr5ktiMw+Df6fMGmMz06sROpq27uiHEEvYtz zVZx3Z0galeJXeQP+NR4DodRN5wY1ftsrCItJWOLTLBRd8geRxtPcUGqljhCiaND Bgp72cKzHjw= =ZeWa -----END PGP SIGNATURE-----

Just wanted to post my quick and dirty solution to reporting on moderated lists. I wrote a perl script to execute the withlist command with output from the list_lists command:
### Begin Perl ### #!/usr/bin/perl
# open file open(FILE, "listsTest.txt") or die("Unable to open file");
# read file into an array @lists = <FILE>;
# close file close(FILE);
foreach $line (@lists) {
my @listname = split(/\s-\s/, $line);
@listname[0] =~ s/\s//g;
$moderators = `./withlist -q -r checkModerated.list_moderated
$listname[0]`;
if (length($moderators) > 0)
{
print $listname[0], " Moderated Users \n";
}
else
{
print $listname[0], " No Moderated Users \n";
}
}
### end ###
My python script to find the moderated users:
### begin python ####
from Mailman import mm_cfg
def list_moderated(m): for member in m.getMembers(): if m.getMemberOption(member, mm_cfg.Moderate): print member
### end ###
Thanks for answers to my questions!!!
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Thursday, April 12, 2007 9:44 PM To: Jeff Kunzelman (DHL); mailman-developers@python.org Subject: Re: [Mailman-Developers] Determining if a user or list has moderation
Jeff Kunzelman (DHL) wrote:
The help for withlist says
--run [module.]callable
-r [module.]callable
I realize this is cryptic, but in your case (module file name = checkModerated.py; function name/callable = list_moderated) it means the withlist command needs to be
withlist -q -r checkModerated.list_moderated jww_test
Note that the 'module name' does not include the .py suffix of the file name. Alternatively, if you named the file list_moderated.py, you could run it with
withlist -q -r list_moderated jww_test
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan

Hi You are calling the 'withlist' command wrong.
You havent specified what you put into the checkModerated.py script, but thats kinda by the by, since
from "withlist -h":
-r [module.]callable
This can be used to run a script with the opened MailList object.
This works by attempting to import `module' (which must be in the
directory containing withlist, or already be accessible on your
sys.path), and then calling `callable' from the module. callable can
be a class or function; it is called with the MailList object as the
first argument. If additional args are given on the command line,
they are passed as subsequent positional args to the callable.
Note that `module.' is optional; if it is omitted then a module with
the name `callable' will be imported.
The global variable `r' will be set to the results of this call.
if you use "-r" you need to call a function, not give it a script name (hence the error .. no ".py" attribute)
keep reading down that help screen, and .. " As another example, say you wanted to change the password for a particular user on a particular list. You could put the following function in a file called `changepw.py':
from Mailman.Errors import NotAMemberError
def changepw(mlist, addr, newpasswd): try: mlist.setMemberPassword(addr, newpasswd) mlist.Save() except NotAMemberError: print 'No address matched:', addr
and run this from the command line: % bin/withlist -l -r changepw mylist somebody@somewhere.org foobar
"
hope that helps ;)
andy
On 13/04/07, Jeff Kunzelman (DHL) <Jeff.Kunzelman@dhl.com> wrote:
-- andy nicholson +61 406 306 715

Jeff Kunzelman (DHL) wrote:
The help for withlist says
--run [module.]callable
-r [module.]callable
I realize this is cryptic, but in your case (module file name = checkModerated.py; function name/callable = list_moderated) it means the withlist command needs to be
withlist -q -r checkModerated.list_moderated jww_test
Note that the 'module name' does not include the .py suffix of the file name. Alternatively, if you named the file list_moderated.py, you could run it with
withlist -q -r list_moderated jww_test
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan

This answered my question, thanks a lot!
Is there an api anywhere that has a full list of all the objects you can use in mailman?
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Thursday, April 12, 2007 9:44 PM To: Jeff Kunzelman (DHL); mailman-developers@python.org Subject: Re: [Mailman-Developers] Determining if a user or list has moderation
Jeff Kunzelman (DHL) wrote:
The help for withlist says
--run [module.]callable
-r [module.]callable
I realize this is cryptic, but in your case (module file name = checkModerated.py; function name/callable = list_moderated) it means the withlist command needs to be
withlist -q -r checkModerated.list_moderated jww_test
Note that the 'module name' does not include the .py suffix of the file name. Alternatively, if you named the file list_moderated.py, you could run it with
withlist -q -r list_moderated jww_test
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Apr 13, 2007, at 1:58 PM, Jeff Kunzelman (DHL) wrote:
Not in Mailman 2.1. We'll do better next time! I have a bunch of
uncommitted changes that will start to use formal zope.interfaces to
document the important APIs.
- -Barry
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin)
iQCVAwUBRh/G6XEjvBPtnXfVAQLpFAQArxnYzhgm4j8wovitx+8ZtKEWzvf9pIq2 Q9OB1n8dF58Rym/l6Z9FVATeSOVsGr5ktiMw+Df6fMGmMz06sROpq27uiHEEvYtz zVZx3Z0galeJXeQP+NR4DodRN5wY1ftsrCItJWOLTLBRd8geRxtPcUGqljhCiaND Bgp72cKzHjw= =ZeWa -----END PGP SIGNATURE-----

Just wanted to post my quick and dirty solution to reporting on moderated lists. I wrote a perl script to execute the withlist command with output from the list_lists command:
### Begin Perl ### #!/usr/bin/perl
# open file open(FILE, "listsTest.txt") or die("Unable to open file");
# read file into an array @lists = <FILE>;
# close file close(FILE);
foreach $line (@lists) {
my @listname = split(/\s-\s/, $line);
@listname[0] =~ s/\s//g;
$moderators = `./withlist -q -r checkModerated.list_moderated
$listname[0]`;
if (length($moderators) > 0)
{
print $listname[0], " Moderated Users \n";
}
else
{
print $listname[0], " No Moderated Users \n";
}
}
### end ###
My python script to find the moderated users:
### begin python ####
from Mailman import mm_cfg
def list_moderated(m): for member in m.getMembers(): if m.getMemberOption(member, mm_cfg.Moderate): print member
### end ###
Thanks for answers to my questions!!!
-----Original Message----- From: Mark Sapiro [mailto:msapiro@value.net] Sent: Thursday, April 12, 2007 9:44 PM To: Jeff Kunzelman (DHL); mailman-developers@python.org Subject: Re: [Mailman-Developers] Determining if a user or list has moderation
Jeff Kunzelman (DHL) wrote:
The help for withlist says
--run [module.]callable
-r [module.]callable
I realize this is cryptic, but in your case (module file name = checkModerated.py; function name/callable = list_moderated) it means the withlist command needs to be
withlist -q -r checkModerated.list_moderated jww_test
Note that the 'module name' does not include the .py suffix of the file name. Alternatively, if you named the file list_moderated.py, you could run it with
withlist -q -r list_moderated jww_test
-- Mark Sapiro <msapiro@value.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
participants (4)
-
andy nicholson
-
Barry Warsaw
-
Jeff Kunzelman (DHL)
-
Mark Sapiro