comparison roundup/roundupdb.py @ 647:b3b483e0fd5e

Fixed a couple of dodgy bits found by pychekcer.
author Richard Jones <richard@users.sourceforge.net>
date Wed, 27 Feb 2002 03:16:02 +0000
parents 086f67453062
children 9382ad731c1c
comparison
equal deleted inserted replaced
646:07abfe8f0c01 647:b3b483e0fd5e
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.46 2002-02-25 14:22:59 grubert Exp $ 18 # $Id: roundupdb.py,v 1.47 2002-02-27 03:16:02 richard 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 mimetools, MimeWriter, cStringIO 25 import MimeWriter, cStringIO
26 import base64, mimetypes 26 import base64, mimetypes
27 27
28 import hyperdb, date 28 import hyperdb, date
29 29
30 # set to indicate to roundup not to actually _send_ email 30 # set to indicate to roundup not to actually _send_ email
40 if m is None: 40 if m is None:
41 raise DesignatorError, '"%s" not a node designator'%designator 41 raise DesignatorError, '"%s" not a node designator'%designator
42 return m.group(1), m.group(2) 42 return m.group(1), m.group(2)
43 43
44 44
45 def extractUserFromList(users): 45 def extractUserFromList(userClass, users):
46 '''Given a list of users, try to extract the first non-anonymous user 46 '''Given a list of users, try to extract the first non-anonymous user
47 and return that user, otherwise return None 47 and return that user, otherwise return None
48 ''' 48 '''
49 if len(users) > 1: 49 if len(users) > 1:
50 # make sure we don't match the anonymous or admin user 50 # make sure we don't match the anonymous or admin user
51 for user in users: 51 for user in users:
52 if user == '1': continue 52 if user == '1': continue
53 if self.user.get(user, 'username') == 'anonymous': continue 53 if userClass.get(user, 'username') == 'anonymous': continue
54 # first valid match will do 54 # first valid match will do
55 return user 55 return user
56 # well, I guess we have no choice 56 # well, I guess we have no choice
57 return user[0] 57 return user[0]
58 elif users: 58 elif users:
71 user is created if they don't exist in the db already 71 user is created if they don't exist in the db already
72 ''' 72 '''
73 (realname, address) = address 73 (realname, address) = address
74 74
75 # try a straight match of the address 75 # try a straight match of the address
76 user = extractUserFromList(self.user.stringFind(address=address)) 76 user = extractUserFromList(self.user,
77 self.user.stringFind(address=address))
77 if user is not None: return user 78 if user is not None: return user
78 79
79 # try the user alternate addresses if possible 80 # try the user alternate addresses if possible
80 props = self.user.getprops() 81 props = self.user.getprops()
81 if props.has_key('alternate_addresses'): 82 if props.has_key('alternate_addresses'):
82 users = self.user.filter({'alternate_addresses': address}, 83 users = self.user.filter({'alternate_addresses': address},
83 [], []) 84 [], [])
84 user = extractUserFromList(users) 85 user = extractUserFromList(self.user, users)
85 if user is not None: return user 86 if user is not None: return user
86 87
87 # try to match the username to the address (for local 88 # try to match the username to the address (for local
88 # submissions where the address is empty) 89 # submissions where the address is empty)
89 user = extractUserFromList(self.user.stringFind(username=address)) 90 user = extractUserFromList(self.user,
91 self.user.stringFind(username=address))
90 92
91 # couldn't match address or username, so create a new user 93 # couldn't match address or username, so create a new user
92 if create: 94 if create:
93 return self.user.create(username=address, address=address, 95 return self.user.create(username=address, address=address,
94 realname=realname) 96 realname=realname)
541 # list the changes 543 # list the changes
542 m = [] 544 m = []
543 l = changed.items() 545 l = changed.items()
544 l.sort() 546 l.sort()
545 for propname, oldvalue in l: 547 for propname, oldvalue in l:
546 prop = cl.properties[propname] 548 prop = props[propname]
547 value = cl.get(nodeid, propname, None) 549 value = cl.get(nodeid, propname, None)
548 if isinstance(prop, hyperdb.Link): 550 if isinstance(prop, hyperdb.Link):
549 link = self.db.classes[prop.classname] 551 link = self.db.classes[prop.classname]
550 key = link.labelprop(default_to_id=1) 552 key = link.labelprop(default_to_id=1)
551 if key: 553 if key:
592 m.insert(0, '') 594 m.insert(0, '')
593 return '\n'.join(m) 595 return '\n'.join(m)
594 596
595 # 597 #
596 # $Log: not supported by cvs2svn $ 598 # $Log: not supported by cvs2svn $
599 # Revision 1.46 2002/02/25 14:22:59 grubert
600 # . roundup db: catch only IOError in getfile.
601 #
597 # Revision 1.44 2002/02/15 07:08:44 richard 602 # Revision 1.44 2002/02/15 07:08:44 richard
598 # . Alternate email addresses are now available for users. See the MIGRATION 603 # . Alternate email addresses are now available for users. See the MIGRATION
599 # file for info on how to activate the feature. 604 # file for info on how to activate the feature.
600 # 605 #
601 # Revision 1.43 2002/02/14 22:33:15 richard 606 # Revision 1.43 2002/02/14 22:33:15 richard

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