[Mailman-Users] Setting max_message_size for selected list viawithlist

Mark Sapiro msapiro at value.net
Fri May 20 21:14:25 CEST 2005


Christopher Adams wrote:
>
>Thanks for your suggestions. I tried running it using withlist as you suggested. My 
>maxmessagesize.py is below:
>
>###maxmessagesize.py
>### determines maximum message size allowed to select lists
>### useage: withlist -l -r maxmessagesize
>def maxmessagesize(m):
>#
># open and read the list names file
>    f = open('/home/chris/lists.txt')
>    l = f.read()
>#
># is this list's name in the file
>    if l.find(m._internal_name) >= 0:
>       m.max_message_size = 500
>       m.Save()
>       m.Unlock()
>    f.close()
>
>
>The following is the result:
>
>
>./withlist -l -a -r maxmessagesize
>Importing maxmessagesize...
>Traceback (most recent call last):
>   File "./withlist", line 275, in ?
>     main()
>   File "./withlist", line 247, in main
>     mod = __import__(module)
>   File "./maxmessagesize.py", line 8
>     l = f.read()
>     ^
>SyntaxError: invalid syntax
>
>
>Can you give me some idea what may be wrong. I realize your suggestion was just off the top of your 
>head.


I copied the above script out of your e-mail and changed only the name
of the file containing the lists. I then ran it exactly as you did and
it worked just fine. I don't know why it didn't work for you unless
it's an indentation problem. Do you have a mixture of tabs and spaces
for indentation or is the actual script in the file indented
differently than it is above? Python is sensitive to indentation. If
you have any tabs in your script, try replacing them with spaces so
the script is indented exactly as above with spaces only.

>I also don't quite understand the need for the lines:
>
>if l.find(m._internal_name) >= 0:
>       m.max_message_size = 500
>
>If I have already written out a file of  lists that I want to affect with withlist, it doesn't seem 
>like I would need this.


My little change to your script reads the file of list names into one
long string 'l'. It then tries to find the name of the list currently
being processed in that string. withlist is processing all lists so
this is how the script decides whether or not to make the change for
the current list. l.find(m._internal_name) returns a number >= 0 if
m._internal_name (the lowercase list name) is found in the string l
(the number is the location in the string where it is found), and it
returns -1 if not found.

Thus the 'if' says only do the following 3 lines (indentation
determines which lines) if this list is in the lists.txt file.

--
Mark Sapiro <msapiro at value.net>       The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan




More information about the Mailman-Users mailing list