comparison roundup/roundupdb.py @ 770:0ffb5aaeecf5

Use 'email' instead of 'rfc822', if available. Don't use isinstance() on a string (not allowed in python 2.1). Return an error message instead of crashing if 'oldvalues' isn't a dict (in generateChangeNote).
author Derrick Hudson <dman13@users.sourceforge.net>
date Sat, 15 Jun 2002 15:49:29 +0000
parents 17208b487199
children db5daf396518
comparison
equal deleted inserted replaced
769:17208b487199 770:0ffb5aaeecf5
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 # $Id: roundupdb.py,v 1.56 2002-06-14 03:54:21 dman13 Exp $ 18 # $Id: roundupdb.py,v 1.57 2002-06-15 15:49:29 dman13 Exp $
19 19
20 __doc__ = """ 20 __doc__ = """
21 Extending hyperdb with types specific to issue-tracking. 21 Extending hyperdb with types specific to issue-tracking.
22 """ 22 """
23 23
24 import re, os, smtplib, socket, copy, time, random 24 import re, os, smtplib, socket, copy, time, random
25 import MimeWriter, cStringIO 25 import MimeWriter, cStringIO
26 import base64, quopri, mimetypes 26 import base64, quopri, mimetypes
27 import rfc822 27 # if available, use the 'email' module, otherwise fallback to 'rfc822'
28 try :
29 from email.Utils import dump_address_pair as straddr
30 except ImportError :
31 from rfc822 import dump_address_pair as straddr
28 32
29 import hyperdb, date 33 import hyperdb, date
30 34
31 # set to indicate to roundup not to actually _send_ email 35 # set to indicate to roundup not to actually _send_ email
32 # this var must contain a file to write the mail to 36 # this var must contain a file to write the mail to
393 authname = users.get(authid, 'realname') 397 authname = users.get(authid, 'realname')
394 if not authname: 398 if not authname:
395 authname = users.get(authid, 'username') 399 authname = users.get(authid, 'username')
396 authaddr = users.get(authid, 'address') 400 authaddr = users.get(authid, 'address')
397 if authaddr: 401 if authaddr:
398 authaddr = rfc822.dump_address_pair( ('',authaddr) ) 402 authaddr = straddr( ('',authaddr) )
399 else: 403 else:
400 authaddr = '' 404 authaddr = ''
401 405
402 # make the message body 406 # make the message body
403 m = [''] 407 m = ['']
439 # create the message 443 # create the message
440 message = cStringIO.StringIO() 444 message = cStringIO.StringIO()
441 writer = MimeWriter.MimeWriter(message) 445 writer = MimeWriter.MimeWriter(message)
442 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, title)) 446 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, title))
443 writer.addheader('To', ', '.join(sendto)) 447 writer.addheader('To', ', '.join(sendto))
444 writer.addheader('From', rfc822.dump_address_pair( 448 writer.addheader('From', straddr(
445 (authname, self.db.config.ISSUE_TRACKER_EMAIL) ) ) 449 (authname, self.db.config.ISSUE_TRACKER_EMAIL) ) )
446 writer.addheader('Reply-To', rfc822.dump_address_pair( 450 writer.addheader('Reply-To', straddr(
447 (self.db.config.INSTANCE_NAME, 451 (self.db.config.INSTANCE_NAME,
448 self.db.config.ISSUE_TRACKER_EMAIL) ) ) 452 self.db.config.ISSUE_TRACKER_EMAIL) ) )
449 writer.addheader('MIME-Version', '1.0') 453 writer.addheader('MIME-Version', '1.0')
450 if messageid: 454 if messageid:
451 writer.addheader('Message-Id', messageid) 455 writer.addheader('Message-Id', messageid)
515 ''' 519 '''
516 520
517 # simplistic check to see if the url is valid, 521 # simplistic check to see if the url is valid,
518 # then append a trailing slash if it is missing 522 # then append a trailing slash if it is missing
519 base = self.db.config.ISSUE_TRACKER_WEB 523 base = self.db.config.ISSUE_TRACKER_WEB
520 if not isinstance( base , "" ) or not base.startswith( "http://" ) : 524 # Oops, can't do this in python2.1
525 #if not isinstance( base , "" ) or not base.startswith( "http://" ) :
526 if type(base) != type("") or not base.startswith( "http://" ) :
521 base = "Configuration Error: ISSUE_TRACKER_WEB isn't a fully-qualified URL" 527 base = "Configuration Error: ISSUE_TRACKER_WEB isn't a fully-qualified URL"
522 elif base[-1] != '/' : 528 elif base[-1] != '/' :
523 base += '/' 529 base += '/'
524 web = base + 'issue'+ nodeid 530 web = base + 'issue'+ nodeid
525 #web = self.db.config.ISSUE_TRACKER_WEB + 'issue'+ nodeid
526 531
527 # ensure the email address is properly quoted 532 # ensure the email address is properly quoted
528 email = rfc822.dump_address_pair( self.db.config.INSTANCE_NAME , 533 email = straddr( (self.db.config.INSTANCE_NAME ,
529 self.db.config.ISSUE_TRACKER_EMAIL ) 534 self.db.config.ISSUE_TRACKER_EMAIL) )
530 535
531 line = '_' * max(len(web), len(email)) 536 line = '_' * max(len(web), len(email))
532 return '%s\n%s\n%s\n%s'%(line, email, web, line) 537 return '%s\n%s\n%s\n%s'%(line, email, web, line)
533 538
534 539
575 """ 580 """
576 cn = self.classname 581 cn = self.classname
577 cl = self.db.classes[cn] 582 cl = self.db.classes[cn]
578 changed = {} 583 changed = {}
579 props = cl.getprops(protected=0) 584 props = cl.getprops(protected=0)
585
586 # XXX DSH
587 # Temporary work-around to prevent crashes and allow the issue to be
588 # submitted.
589 try :
590 oldvalues.keys
591 except AttributeError :
592 # The arg isn't a dict. Precondition/interface violation.
593 return '\n'.join(
594 ('', '-'*10,
595 "Precondition/interface Error -- 'oldvalues' isn't a dict." ,
596 '-'*10 , '' , str(oldvalues) ) )
580 597
581 # determine what changed 598 # determine what changed
582 for key in oldvalues.keys(): 599 for key in oldvalues.keys():
583 if key in ['files','messages']: continue 600 if key in ['files','messages']: continue
584 new_value = cl.get(nodeid, key) 601 new_value = cl.get(nodeid, key)
647 m.insert(0, '') 664 m.insert(0, '')
648 return '\n'.join(m) 665 return '\n'.join(m)
649 666
650 # 667 #
651 # $Log: not supported by cvs2svn $ 668 # $Log: not supported by cvs2svn $
669 # Revision 1.56 2002/06/14 03:54:21 dman13
670 # #565992 ] if ISSUE_TRACKER_WEB doesn't have the trailing '/', add it
671 #
672 # use the rfc822 module to ensure that every (oddball) email address and
673 # real-name is properly quoted
674 #
652 # Revision 1.55 2002/06/11 04:58:07 richard 675 # Revision 1.55 2002/06/11 04:58:07 richard
653 # detabbing 676 # detabbing
654 # 677 #
655 # Revision 1.54 2002/05/29 01:16:17 richard 678 # Revision 1.54 2002/05/29 01:16:17 richard
656 # Sorry about this huge checkin! It's fixing a lot of related stuff in one go 679 # Sorry about this huge checkin! It's fixing a lot of related stuff in one go

Roundup Issue Tracker: http://roundup-tracker.org/