[Tutor] TLlistmaster.py [bug hunting]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sun, 6 Jan 2002 14:59:57 -0800 (PST)


On Sun, 6 Jan 2002, Kirk D Bailey wrote:

> I have got TLlistmaster.py almost complete. There is one minor bug in
> there. Regretfully, it's a tiny little stinkbug and it is driving me
> crazy(ier).

What we need to do is isolate the bug.  Time to don our hunting caps!  
*grin* I'll transcribe what I'm looking at while I'm hunting the bug, to
show the thought processes I'm going through.



> there is no error code, but it fails to see the presence of the
> subject line in the pending file.

How do we know this?  Let's see where it reports that it can't find a
subject.  I'll quote the part of your code, but strip off the comments for
the moment:


###
if thecommand == "join":
    print "This person wants to join'"+listname+"' list!"
    if subject in pendings:
        [code cut...]
    else:
        print "cannot find subject in pending file!"
        sys.exit()
###


Since the output is printing that "cannot find subject..." stuff, we must
be jumping in here, and 'thecommand' must be "join".  Also, 'subject' must
not be in 'pendings'.  What is 'subject', and what is 'pendings'?  If we
know what the values of these variables are, we might discover why we
can't find the subject in the pending file.


I'll now search for places where 'subject' is being assigned to...

###
subject = string.strip(Message['Subject'])
subject = string.replace(subject,"Re:","")
subject = string.strip(subject)
###

You may want to bundle this processing all together into a "getSubject()"
function, because it's very easy to forget to do all this cleanup on the
subject string.  Also, I think that strip()ping the string twice is
superfluous.

So 'subject' must be a cleaned up header within the Message.  Now let's
see what 'pendings' is:


###
pendings=readpending()
gangstrip(pendings)
###

Good!  Since there's a function called readpending(), we can focus on that
function, without bouncing around in the rest of the code.  Let's see what
readpending() does.


###
def readpending():
    f4=open('./lists/pending','r')
    pending=f4.readlines()
    f4.close()
    return pending
###

Ok, clear enough.  readpending() opens up a file './list/pending' and
returns a list of lines.  Just as long as the './list/pending' file itself
contains that subject, we should be fine.  I personally feel that the
gangstrip() should be part of readpending(), not parallel to it.



So what must be happening is that the subject line isn't in the pendings
file.  Your debugging output shows:

> CLEANED UP subject line='join highprimate@howlermonkey.net evil-humor
> 1010287984'


which looks ok.  What does your pending file contain?  Just one line!

> Pending action='join testcode@howlermonkey.net testlist3 1010173860'


So there's no match!  Those two strings are different from each other, and
from the debugging output, I'm guessing that there's only one pending
action within './list/pending'.  Check your pending file, and things that
affect your pending file.  How does one get added to the pending file?


Hope this helps!