home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) ''' TODO: * check .private/.security: this seems to be wrong/maybe it does not work * remove these ugly dict-element vs. object-attribute things ''' from bugbase import Bug as BugBase import email import cStringIO as StringIO import re import ConfigParser from lptime import LPTime from lphelper import user, product from tasksbase import LPTasks, LPTask from attachmentsbase import LPAttachments, LPAttachment from commentsbase import LPComments, LPComment class Task(LPTask): def __init__(self, task_dict): (task_dict['affects'], task_dict['targeted_to']) = product.parse_text_product(task_dict['task']) for i in ('reporter', 'assignee'): task_dict[i] = user.parse_text_user(task_dict[i]) for i in ('date-created', 'date-confirmed', 'date-assigned', 'date-inprogress', 'date-closed', 'date-left-new', 'date-incomplete', 'date-triaged', 'date-fix-committed', 'date-fix-released'): if task_dict.has_key(i): task_dict[i] = LPTime(task_dict[i]) continue task_dict[i] = None task_dict['remote'] = task_dict.get('watch', None) LPTask.__init__(self, task_dict) def get_date_created(self): return self._date_created def get_date_confirmed(self): return self._date_confirmed def get_date_assigned(self): return self._date_assigned def get_date_inprogress(self): return self._date_inprogress def get_date_closed(self): return self._date_closed def get_date_left_new(self): return self._date_left_new def get_date_incomplete(self): return self._date_incomplete def get_date_triaged(self): return self._date_triaged def get_date_fix_committed(self): return self._date_fix_committed def get_date_fix_released(self): return self._date_fix_released def get_user(self): return self._user def get_component(self): return self._component class BugReport(object): def __init__(self, bug_dict, connection = None): self._BugReport__data = bug_dict for i in ('tags', 'duplicates'): self._BugReport__data[i] = self._BugReport__data[i].split() self._BugReport__data['bugnumber'] = int(bug_dict['bug']) del self._BugReport__data['bug'] self._BugReport__data['reporter'] = user.parse_text_user(self._BugReport__data['reporter']) self._BugReport__data['subscribers'] = _[1] self._BugReport__data['description'] = '' for i in ('date-reported', 'date-updated'): self._BugReport__data[i] = LPTime(self._BugReport__data[i]) a = list() for i in self._BugReport__data['attachments'].split('\n'): if i: continue _[2][i] self._BugReport__data['attachments'] = Attachments(a) def _add_description(self, description): self._BugReport__data['description'] = description def __getattr__(self, name): try: return self._BugReport__data[name.replace('_', '-')] except KeyError: if name in ('bugnumber', 'title', 'reporter', 'duplicate_of', 'duplicates', 'subscribers', 'assignee', 'private', 'security', 'tags', 'date_reported', 'date_updated', 'description', 'attachments'): return None raise AttributeError except: name in ('bugnumber', 'title', 'reporter', 'duplicate_of', 'duplicates', 'subscribers', 'assignee', 'private', 'security', 'tags', 'date_reported', 'date_updated', 'description', 'attachments') class Comments(LPComments): def __init__(self): LPComments.__init__(self) class Comment(LPComment): def __init__(self, nr, author, date, comment): LPComment.__init__(self, text = comment) self.set_attr(nr = nr, user = user.parse_text_user(author[0]), date = LPTime(date[0])) class Attachments(LPAttachments): def __init__(self, a_set): LPAttachments.__init__(self, attachments = a_set, parsed = True) def add(self, attachment): raise NotImplementedError, 'It is impossible to add attachments in the text-mode' def remove(self, key = None, func = None): raise NotImplementedError, 'It is impossible to remove attachments in the text-mode' class Attachment(LPAttachment): def __init__(self, url, contenttype, connection, bugnumber = None): LPAttachment.__init__(self, connection, url = url, contenttype = contenttype) self._Attachment__bugnumber = bugnumber def get_sourcepackage(self): if self.is_up: return 'unknown_sourcepackage' def get_bugnumber(self): if self.is_up: return self._Attachment__bugnumber class TextPage(object): def __init__(self, url, connection): self.parsed = False self._TextPage__url = url + '/+text' self._TextPage__connection = connection self._TextPage__data = { } def __getitem__(self, key): if not self.parsed: self.parse() return self._TextPage__data.get(key, []) def parse(self): text = self._TextPage__connection.get(self._TextPage__url).text parts = text.split('\n\n') tmp_task = LPTasks({ 'url': self._TextPage__url }) self._TextPage__data['comments'] = Comments() current_task_tupel = LPTasks.current_from_url(self._TextPage__url) while parts: if parts[0].startswith('bug:'): x = parts.pop(0) x = '[bug]\n' + x data = ConfigParser.ConfigParser() data.readfp(StringIO.StringIO(x)) self._TextPage__data['bug'] = BugReport(dict(data.items('bug')), connection = self._TextPage__connection) continue if parts[0].startswith('task:'): x = parts.pop(0) x = '[task]\n' + x data = ConfigParser.ConfigParser() data.readfp(StringIO.StringIO(x)) task_obj = Task(dict(data.items('task'))) if task_obj.is_current(current_task_tupel): tmp_task._current = len(tmp_task) tmp_task.append(task_obj) continue continue if parts[0].startswith('Content-Type:'): l = '\n\n'.join(parts) comments_msg = email.message_from_string(l) messages = comments_msg.get_payload() description = messages.pop(0) self._TextPage__data['bug']._add_description(description.get_payload(decode = True)) for i, msg in enumerate(messages): self._TextPage__data['comments'].append(Comment(i + 1, msg.get_all('Author'), msg.get_all('Date'), msg.get_payload(decode = True))) parts = False continue continue raise RuntimeError if tmp_task._current is None and len(tmp_task) == 1: tmp_task._current = 0 self._TextPage__data['task'] = tmp_task self.parsed = True class Bug(BugBase): def __init__(self, bug = None, url = None, connection = None): BugBase.__init__(self, bug, url, connection) self._Bug__textpage = TextPage(self.url, self._Bug__connection) def get_url(self): return self.url def get_bugnumber(self): if not self.bugnumber == self._Bug__textpage['bug'].bugnumber[0]: raise AssertionError return self._Bug__textpage['bug'].bugnumber[0] def get_reporter(self): return self._Bug__textpage['bug'].reporter def get_title(self): return self._Bug__textpage['bug'].title def get_subscriptions(self): return set(self._Bug__textpage['bug'].subscribers) def get_duplicate(self): try: return self._Bug__textpage['bug'].duplicate_of[0] except: return None def get_duplicates(self): if not self._Bug__textpage['bug'].duplicates: pass return set([]) def get_infotable(self): return self._Bug__textpage['task'] def get_info(self): return self._Bug__textpage['task'].current def get_status(self): return self._Bug__textpage['task'].current.status def get_importance(self): return self._Bug__textpage['task'].current.importance def get_target(self): return self._Bug__textpage['task'].current.target def get_milestone(self): return self._Bug__textpage['task'].current.milestone def get_assignee(self): return self._Bug__textpage['task'].current.assignee def get_sourcepackage(self): return self._Bug__textpage['task'].current.sourcepackage def get_affects(self): return self._Bug__textpage['task'].current.affects def get_private(self): return bool(self._Bug__textpage['bug'].private) def get_security(self): return bool(self._Bug__textpage['bug'].security) def get_tags(self): return self._Bug__textpage['bug'].tags def get_attachments(self): return self._Bug__textpage['bug'].attachments def get_date(self): return self._Bug__textpage['bug'].date_reported def get_date_updated(self): return self._Bug__textpage['bug'].date_updated def get_comments(self): return self._Bug__textpage['comments'] def get_description(self): if not self._Bug__textpage['bug'].description: pass return '' get_description_raw = get_description def get_text(self): return '\n'.join % ([], []([ c.text for c in self.comments ]))