Mercurial > p > roundup > code
comparison roundup/roundupdb.py @ 524:dce4c75bef5a
changed all config accesses...
...so they access either the instance or the config attriubute on the
db. This means that all config is obtained from instance_config
instead of the mish-mash of classes. This will make switching to a
ConfigParser setup easier too, I hope.
At a minimum, this makes migration a _little_ easier (a lot easier in the
0.5.0 switch, I hope!)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 14 Jan 2002 02:20:15 +0000 |
| parents | 4291a31bfa89 |
| children | d17c60d16f7f |
comparison
equal
deleted
inserted
replaced
| 523:32db08940334 | 524:dce4c75bef5a |
|---|---|
| 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.38 2002-01-10 05:57:45 richard Exp $ | 18 # $Id: roundupdb.py,v 1.39 2002-01-14 02:20:15 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 |
| 235 class DetectorError(RuntimeError): | 235 class DetectorError(RuntimeError): |
| 236 pass | 236 pass |
| 237 | 237 |
| 238 # XXX deviation from spec - was called ItemClass | 238 # XXX deviation from spec - was called ItemClass |
| 239 class IssueClass(Class): | 239 class IssueClass(Class): |
| 240 # configuration | |
| 241 MESSAGES_TO_AUTHOR = 'no' | |
| 242 INSTANCE_NAME = 'Roundup issue tracker' | |
| 243 EMAIL_SIGNATURE_POSITION = 'bottom' | |
| 244 | 240 |
| 245 # Overridden methods: | 241 # Overridden methods: |
| 246 | 242 |
| 247 def __init__(self, db, classname, **properties): | 243 def __init__(self, db, classname, **properties): |
| 248 """The newly-created class automatically includes the "messages", | 244 """The newly-created class automatically includes the "messages", |
| 301 # get the current nosy list, we'll need it | 297 # get the current nosy list, we'll need it |
| 302 nosy = self.get(nodeid, 'nosy') | 298 nosy = self.get(nodeid, 'nosy') |
| 303 | 299 |
| 304 # possibly send the message to the author, as long as they aren't | 300 # possibly send the message to the author, as long as they aren't |
| 305 # anonymous | 301 # anonymous |
| 306 if (self.MESSAGES_TO_AUTHOR == 'yes' and | 302 if (self.db.config.MESSAGES_TO_AUTHOR == 'yes' and |
| 307 users.get(authid, 'username') != 'anonymous'): | 303 users.get(authid, 'username') != 'anonymous'): |
| 308 sendto.append(authid) | 304 sendto.append(authid) |
| 309 r[authid] = 1 | 305 r[authid] = 1 |
| 310 | 306 |
| 311 # now figure the nosy people who weren't recipients | 307 # now figure the nosy people who weren't recipients |
| 330 messageid = messages.get(msgid, 'messageid') | 326 messageid = messages.get(msgid, 'messageid') |
| 331 if not messageid: | 327 if not messageid: |
| 332 # this is an old message that didn't get a messageid, so | 328 # this is an old message that didn't get a messageid, so |
| 333 # create one | 329 # create one |
| 334 messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(), | 330 messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(), |
| 335 self.classname, nodeid, self.MAIL_DOMAIN) | 331 self.classname, nodeid, self.db.config.MAIL_DOMAIN) |
| 336 messages.set(msgid, messageid=messageid) | 332 messages.set(msgid, messageid=messageid) |
| 337 | 333 |
| 338 # update the message's recipients list | 334 # update the message's recipients list |
| 339 messages.set(msgid, recipients=recipients) | 335 messages.set(msgid, recipients=recipients) |
| 340 | 336 |
| 354 | 350 |
| 355 # make the message body | 351 # make the message body |
| 356 m = [''] | 352 m = [''] |
| 357 | 353 |
| 358 # put in roundup's signature | 354 # put in roundup's signature |
| 359 if self.EMAIL_SIGNATURE_POSITION == 'top': | 355 if self.db.config.EMAIL_SIGNATURE_POSITION == 'top': |
| 360 m.append(self.email_signature(nodeid, msgid)) | 356 m.append(self.email_signature(nodeid, msgid)) |
| 361 | 357 |
| 362 # add author information | 358 # add author information |
| 363 if len(self.get(nodeid,'messages')) == 1: | 359 if len(self.get(nodeid,'messages')) == 1: |
| 364 m.append("New submission from %s%s:"%(authname, authaddr)) | 360 m.append("New submission from %s%s:"%(authname, authaddr)) |
| 372 # add the change note | 368 # add the change note |
| 373 if change_note: | 369 if change_note: |
| 374 m.append(change_note) | 370 m.append(change_note) |
| 375 | 371 |
| 376 # put in roundup's signature | 372 # put in roundup's signature |
| 377 if self.EMAIL_SIGNATURE_POSITION == 'bottom': | 373 if self.db.config.EMAIL_SIGNATURE_POSITION == 'bottom': |
| 378 m.append(self.email_signature(nodeid, msgid)) | 374 m.append(self.email_signature(nodeid, msgid)) |
| 379 | 375 |
| 380 # get the files for this message | 376 # get the files for this message |
| 381 message_files = messages.get(msgid, 'files') | 377 message_files = messages.get(msgid, 'files') |
| 382 | 378 |
| 383 # create the message | 379 # create the message |
| 384 message = cStringIO.StringIO() | 380 message = cStringIO.StringIO() |
| 385 writer = MimeWriter.MimeWriter(message) | 381 writer = MimeWriter.MimeWriter(message) |
| 386 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, title)) | 382 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, title)) |
| 387 writer.addheader('To', ', '.join(sendto)) | 383 writer.addheader('To', ', '.join(sendto)) |
| 388 writer.addheader('From', '%s <%s>'%(authname, self.ISSUE_TRACKER_EMAIL)) | 384 writer.addheader('From', '%s <%s>'%(authname, |
| 389 writer.addheader('Reply-To', '%s <%s>'%(self.INSTANCE_NAME, | 385 self.db.config.ISSUE_TRACKER_EMAIL)) |
| 390 self.ISSUE_TRACKER_EMAIL)) | 386 writer.addheader('Reply-To', '%s <%s>'%(self.db.config.INSTANCE_NAME, |
| 387 self.db.config.ISSUE_TRACKER_EMAIL)) | |
| 391 writer.addheader('MIME-Version', '1.0') | 388 writer.addheader('MIME-Version', '1.0') |
| 392 if messageid: | 389 if messageid: |
| 393 writer.addheader('Message-Id', messageid) | 390 writer.addheader('Message-Id', messageid) |
| 394 if inreplyto: | 391 if inreplyto: |
| 395 writer.addheader('In-Reply-To', inreplyto) | 392 writer.addheader('In-Reply-To', inreplyto) |
| 429 body.write('\n'.join(m)) | 426 body.write('\n'.join(m)) |
| 430 | 427 |
| 431 # now try to send the message | 428 # now try to send the message |
| 432 if SENDMAILDEBUG: | 429 if SENDMAILDEBUG: |
| 433 open(SENDMAILDEBUG, 'w').write('FROM: %s\nTO: %s\n%s\n'%( | 430 open(SENDMAILDEBUG, 'w').write('FROM: %s\nTO: %s\n%s\n'%( |
| 434 self.ADMIN_EMAIL, ', '.join(sendto), message.getvalue())) | 431 self.db.config.ADMIN_EMAIL,', '.join(sendto),message.getvalue())) |
| 435 else: | 432 else: |
| 436 try: | 433 try: |
| 437 # send the message as admin so bounces are sent there | 434 # send the message as admin so bounces are sent there |
| 438 # instead of to roundup | 435 # instead of to roundup |
| 439 smtp = smtplib.SMTP(self.MAILHOST) | 436 smtp = smtplib.SMTP(self.db.config.MAILHOST) |
| 440 smtp.sendmail(self.ADMIN_EMAIL, sendto, message.getvalue()) | 437 smtp.sendmail(self.db.config.ADMIN_EMAIL, sendto, |
| 438 message.getvalue()) | |
| 441 except socket.error, value: | 439 except socket.error, value: |
| 442 raise MessageSendError, \ | 440 raise MessageSendError, \ |
| 443 "Couldn't send confirmation email: mailhost %s"%value | 441 "Couldn't send confirmation email: mailhost %s"%value |
| 444 except smtplib.SMTPException, value: | 442 except smtplib.SMTPException, value: |
| 445 raise MessageSendError, \ | 443 raise MessageSendError, \ |
| 446 "Couldn't send confirmation email: %s"%value | 444 "Couldn't send confirmation email: %s"%value |
| 447 | 445 |
| 448 def email_signature(self, nodeid, msgid): | 446 def email_signature(self, nodeid, msgid): |
| 449 ''' Add a signature to the e-mail with some useful information | 447 ''' Add a signature to the e-mail with some useful information |
| 450 ''' | 448 ''' |
| 451 web = self.ISSUE_TRACKER_WEB + 'issue'+ nodeid | 449 web = self.db.config.ISSUE_TRACKER_WEB + 'issue'+ nodeid |
| 452 email = '"%s" <%s>'%(self.INSTANCE_NAME, self.ISSUE_TRACKER_EMAIL) | 450 email = '"%s" <%s>'%(self.db.config.INSTANCE_NAME, |
| 451 self.db.config.ISSUE_TRACKER_EMAIL) | |
| 453 line = '_' * max(len(web), len(email)) | 452 line = '_' * max(len(web), len(email)) |
| 454 return '%s\n%s\n%s\n%s'%(line, email, web, line) | 453 return '%s\n%s\n%s\n%s'%(line, email, web, line) |
| 455 | 454 |
| 456 def generateChangeNote(self, nodeid, oldvalues): | 455 def generateChangeNote(self, nodeid, oldvalues): |
| 457 """Generate a change note that lists property changes | 456 """Generate a change note that lists property changes |
| 528 m.insert(0, '') | 527 m.insert(0, '') |
| 529 return '\n'.join(m) | 528 return '\n'.join(m) |
| 530 | 529 |
| 531 # | 530 # |
| 532 # $Log: not supported by cvs2svn $ | 531 # $Log: not supported by cvs2svn $ |
| 532 # Revision 1.38 2002/01/10 05:57:45 richard | |
| 533 # namespace clobberation | |
| 534 # | |
| 533 # Revision 1.37 2002/01/08 04:12:05 richard | 535 # Revision 1.37 2002/01/08 04:12:05 richard |
| 534 # Changed message-id format to "<%s.%s.%s%s@%s>" so it complies with RFC822 | 536 # Changed message-id format to "<%s.%s.%s%s@%s>" so it complies with RFC822 |
| 535 # | 537 # |
| 536 # Revision 1.36 2002/01/02 02:31:38 richard | 538 # Revision 1.36 2002/01/02 02:31:38 richard |
| 537 # Sorry for the huge checkin message - I was only intending to implement #496356 | 539 # Sorry for the huge checkin message - I was only intending to implement #496356 |
