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:
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
Mailman-Developers mailing list Mailman-Developers@python.org http://mail.python.org/mailman/listinfo/mailman-developers Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-developers%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-developers/intothemist%40gmai...
Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp
Jeff Kunzelman (DHL) wrote:
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'
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
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:
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'
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
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Apr 13, 2007, at 1:58 PM, Jeff Kunzelman (DHL) wrote:
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?
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.
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:
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'
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