def bug_text(self): """Return the bug information for text display.""" bug = self.context text = [] text.append('bug: %d' % bug.id) text.append('title: %s' % bug.title) text.append('date-reported: %s' % format_rfc2822_date(bug.datecreated)) text.append('date-updated: %s' % format_rfc2822_date(bug.date_last_updated)) text.append('reporter: %s' % bug.owner.unique_displayname) if bug.duplicateof: text.append('duplicate-of: %d' % bug.duplicateof.id) else: text.append('duplicate-of: ') if bug.duplicates: dupes = ' '.join(str(dupe.id) for dupe in bug.duplicates) text.append('duplicates: %s' % dupes) else: text.append('duplicates: ') if bug.private: # XXX kiko 2007-10-31: this could include date_made_private and # who_made_private but Bjorn doesn't let me. text.append('private: yes') if bug.security_related: text.append('security: yes') patches = [] text.append('attachments: ') for attachment in bug.attachments_unpopulated: if attachment.type != BugAttachmentType.PATCH: text.append(' %s' % self.attachment_text(attachment)) else: patches.append(attachment) text.append('patches: ') for attachment in patches: text.append(' %s' % self.attachment_text(attachment)) text.append('tags: %s' % ' '.join(bug.tags)) text.append('subscribers: ') for subscriber in self.subscribers: text.append(' %s' % subscriber.unique_displayname) return ''.join(line + '\n' for line in text)
def comment_text(self): """Return a text representation of bug comments.""" def build_message(text): mailwrapper = MailWrapper(width=72) text = mailwrapper.format(text) message = MIMEText(text.encode('utf-8'), 'plain', 'utf-8') # This is redundant and makes the template noisy del message['MIME-Version'] return message from lp.bugs.browser.bugtask import ( get_visible_comments, get_comments_for_bugtask) # XXX: kiko 2007-10-31: for some reason, get_comments_for_bugtask # takes a task, not a bug. For now live with it. first_task = self.bugtasks[0] all_comments = get_comments_for_bugtask(first_task) comments = get_visible_comments(all_comments[1:]) comment_mime = MIMEMultipart() message = build_message(self.context.description) comment_mime.attach(message) for comment in comments: message = build_message(comment.text_for_display) message['Author'] = comment.owner.unique_displayname.encode( 'utf-8') message['Date'] = format_rfc2822_date(comment.datecreated) message['Message-Id'] = comment.rfc822msgid comment_mime.attach(message) return comment_mime.as_string().decode('utf-8')
def bugtask_text(self, task): """Return a BugTask for text display.""" text = [] text.append('task: %s' % task.bugtargetname) text.append('status: %s' % task.status.title) text.append('date-created: %s' % format_rfc2822_date(task.datecreated)) for status in ["left_new", "confirmed", "triaged", "assigned", "inprogress", "closed", "incomplete", "fix_committed", "fix_released", "left_closed"]: date = getattr(task, "date_%s" % status) if date: text.append("date-%s: %s" % ( status.replace('_', '-'), format_rfc2822_date(date))) text.append('reporter: %s' % task.owner.unique_displayname) if task.bugwatch: text.append('watch: %s' % task.bugwatch.url) text.append('importance: %s' % task.importance.title) component = task.getPackageComponent() if component: text.append('component: %s' % component.name) if (task.assignee and check_permission('launchpad.LimitedView', task.assignee)): text.append('assignee: %s' % task.assignee.unique_displayname) else: text.append('assignee: ') if task.milestone: text.append('milestone: %s' % task.milestone.name) else: text.append('milestone: ') return ''.join(line + '\n' for line in text)