diff options
author | Pawel Hajdan, Jr <phajdan.jr@gentoo.org> | 2011-05-22 15:36:34 +0200 |
---|---|---|
committer | Pawel Hajdan, Jr <phajdan.jr@gentoo.org> | 2011-05-22 15:36:34 +0200 |
commit | 59f26733ad4684cc923bd4b299b5498f8f015b37 (patch) | |
tree | 0921fee2962f55acb8b2e82b0caf6a4a905f4ca7 | |
parent | Initial commit, add a simple batch bugzilla viewer. (diff) | |
download | arch-tools-59f26733ad4684cc923bd4b299b5498f8f015b37.tar.gz arch-tools-59f26733ad4684cc923bd4b299b5498f8f015b37.tar.bz2 arch-tools-59f26733ad4684cc923bd4b299b5498f8f015b37.zip |
Cleanup: convert all indentation to tabs.
-rwxr-xr-x | bugzilla-viewer.py | 292 |
1 files changed, 146 insertions, 146 deletions
diff --git a/bugzilla-viewer.py b/bugzilla-viewer.py index bf034cc..d1de3c0 100755 --- a/bugzilla-viewer.py +++ b/bugzilla-viewer.py @@ -22,163 +22,163 @@ class TermTooSmall(Exception): # Main class (called with curses.wrapper later). class MainWindow: - def __init__(self, screen, bugs, bugs_dict, packages_dict, related_bugs, repoman_dict): - self.bugs = bugs - self.bugs_dict = bugs_dict - self.packages_dict = packages_dict - self.related_bugs = related_bugs - self.repoman_dict = repoman_dict - - curses.curs_set(0) - self.screen = screen - - curses.use_default_colors() - self.init_screen() - - c = self.screen.getch() - while c not in ( ord("q"), curses.ascii.ESC): - if c == ord("j"): - self.scroll_bugs_pad(1) - elif c == ord("k"): - self.scroll_bugs_pad(-1) - elif c == curses.KEY_DOWN: - self.scroll_contents_pad(1) - elif c == curses.KEY_UP: - self.scroll_contents_pad(-1) - elif c == curses.KEY_RESIZE: - self.init_screen() - - c = self.screen.getch() - - def init_screen(self): - (self.height, self.width) = self.screen.getmaxyx() - - if self.height < 12 or self.width < 80: - raise TermTooSmall() - - self.screen.border() - self.screen.vline(1, self.width / 3, curses.ACS_VLINE, self.height - 2) - self.screen.refresh() - - self.fill_bugs_pad() - self.refresh_bugs_pad() - - self.fill_contents_pad() - self.refresh_contents_pad() - - def fill_bugs_pad(self): - self.bugs_pad = curses.newpad(len(self.bugs),self.width) - self.bugs_pad.erase() - - self.bugs_pad_pos = 0 + def __init__(self, screen, bugs, bugs_dict, packages_dict, related_bugs, repoman_dict): + self.bugs = bugs + self.bugs_dict = bugs_dict + self.packages_dict = packages_dict + self.related_bugs = related_bugs + self.repoman_dict = repoman_dict + + curses.curs_set(0) + self.screen = screen + + curses.use_default_colors() + self.init_screen() + + c = self.screen.getch() + while c not in (ord("q"), curses.ascii.ESC): + if c == ord("j"): + self.scroll_bugs_pad(1) + elif c == ord("k"): + self.scroll_bugs_pad(-1) + elif c == curses.KEY_DOWN: + self.scroll_contents_pad(1) + elif c == curses.KEY_UP: + self.scroll_contents_pad(-1) + elif c == curses.KEY_RESIZE: + self.init_screen() + + c = self.screen.getch() + + def init_screen(self): + (self.height, self.width) = self.screen.getmaxyx() + + if self.height < 12 or self.width < 80: + raise TermTooSmall() + + self.screen.border() + self.screen.vline(1, self.width / 3, curses.ACS_VLINE, self.height - 2) + self.screen.refresh() + + self.fill_bugs_pad() + self.refresh_bugs_pad() + + self.fill_contents_pad() + self.refresh_contents_pad() + + def fill_bugs_pad(self): + self.bugs_pad = curses.newpad(len(self.bugs),self.width) + self.bugs_pad.erase() - for i in range(len(self.bugs)): - self.bugs_pad.addstr(i, 0, - " " + self.bugs[i].find('bug_id').text + " " + self.bugs[i].find('short_desc').text) - - def scroll_bugs_pad(self, amount): - height = len(self.bugs) - - self.bugs_pad_pos += amount - if self.bugs_pad_pos < 0: self.bugs_pad_pos = 0 - if self.bugs_pad_pos >= height: - self.bugs_pad_pos = height - 1 - self.refresh_bugs_pad() - - self.fill_contents_pad() - self.refresh_contents_pad() - - def refresh_bugs_pad(self): - (height, width) = self.bugs_pad.getmaxyx() - for i in range(height): - self.bugs_pad.addch(i, 0, " ") - self.bugs_pad.addch(self.bugs_pad_pos, 0, "*") - pos = min(height - self.height + 2, max(0, self.bugs_pad_pos - (self.height / 2))) - self.bugs_pad.refresh( - pos, 0, - 1, 1, - self.height - 2, self.width / 3 - 1) - - def fill_contents_pad(self): - width = 2 * self.width / 3 - - bug = self.bugs[self.bugs_pad_pos] - - output = [] - output += textwrap.wrap(bug.find("short_desc").text, width=width-2) - output.append("-" * (width - 2)) - - cpvs = self.packages_dict[bug.find("bug_id").text] - if cpvs: - output += textwrap.wrap("Found package cpvs:", width=width-2) - for cpv in cpvs: - output += textwrap.wrap(cpv, width=width-2) - output.append("-" * (width - 2)) - deps = bug.findall("dependson") - if deps: - output += textwrap.wrap("Depends on:", width=width-2) - for dep in deps: - dep_bug = self.bugs_dict[dep.text] - desc = dep.text + " " + dep_bug.find("bug_status").text + " " + dep_bug.find("short_desc").text - output += textwrap.wrap(desc, width=width-2) + for i in range(len(self.bugs)): + self.bugs_pad.addstr(i, 0, + " " + self.bugs[i].find('bug_id').text + " " + self.bugs[i].find('short_desc').text) + + def scroll_bugs_pad(self, amount): + height = len(self.bugs) + + self.bugs_pad_pos += amount + if self.bugs_pad_pos < 0: + self.bugs_pad_pos = 0 + if self.bugs_pad_pos >= height: + self.bugs_pad_pos = height - 1 + self.refresh_bugs_pad() + + self.fill_contents_pad() + self.refresh_contents_pad() + + def refresh_bugs_pad(self): + (height, width) = self.bugs_pad.getmaxyx() + for i in range(height): + self.bugs_pad.addch(i, 0, " ") + self.bugs_pad.addch(self.bugs_pad_pos, 0, "*") + pos = min(height - self.height + 2, max(0, self.bugs_pad_pos - (self.height / 2))) + self.bugs_pad.refresh( + pos, 0, + 1, 1, + self.height - 2, self.width / 3 - 1) + + def fill_contents_pad(self): + width = 2 * self.width / 3 + + bug = self.bugs[self.bugs_pad_pos] + + output = [] + output += textwrap.wrap(bug.find("short_desc").text, width=width-2) output.append("-" * (width - 2)) + + cpvs = self.packages_dict[bug.find("bug_id").text] + if cpvs: + output += textwrap.wrap("Found package cpvs:", width=width-2) + for cpv in cpvs: + output += textwrap.wrap(cpv, width=width-2) + output.append("-" * (width - 2)) + + deps = bug.findall("dependson") + if deps: + output += textwrap.wrap("Depends on:", width=width-2) + for dep in deps: + dep_bug = self.bugs_dict[dep.text] + desc = dep.text + " " + dep_bug.find("bug_status").text + " " + dep_bug.find("short_desc").text + output += textwrap.wrap(desc, width=width-2) + output.append("-" * (width - 2)) - related = self.related_bugs[bug.find("bug_id").text] - if related: - output += textwrap.wrap("Related bugs:", width=width-2) - for related_bug in related: - if related_bug['bugid'] == bug.find("bug_id").text: - continue - desc = related_bug['bugid'] + " " + related_bug['desc'] - output += textwrap.wrap(desc, width=width-2) - output.append("-" * (width - 2)) + related = self.related_bugs[bug.find("bug_id").text] + if related: + output += textwrap.wrap("Related bugs:", width=width-2) + for related_bug in related: + if related_bug['bugid'] == bug.find("bug_id").text: + continue + desc = related_bug['bugid'] + " " + related_bug['desc'] + output += textwrap.wrap(desc, width=width-2) + output.append("-" * (width - 2)) - if bug.find("bug_id").text in repoman_dict and repoman_dict[bug.find("bug_id").text]: - output += textwrap.wrap("Repoman output:", width=width-2) - lines = repoman_dict[bug.find("bug_id").text].split("\n") - for line in lines: - output += textwrap.wrap(line, width=width-2) - output.append("-" * (width - 2)) + if bug.find("bug_id").text in repoman_dict and repoman_dict[bug.find("bug_id").text]: + output += textwrap.wrap("Repoman output:", width=width-2) + lines = repoman_dict[bug.find("bug_id").text].split("\n") + for line in lines: + output += textwrap.wrap(line, width=width-2) + output.append("-" * (width - 2)) - for elem in bug.findall("long_desc"): - output += textwrap.wrap("%s:" % elem.find("who").text, width=width-2) - lines = elem.find("thetext").text.split("\n") - for line in lines: - output += textwrap.wrap(line, width=width-2) - output.append("-" * (width - 2)) - - self.contents_pad_length = len(output) - - self.contents_pad = curses.newpad(max(self.contents_pad_length, self.height), width) - self.contents_pad.erase() + for elem in bug.findall("long_desc"): + output += textwrap.wrap("%s:" % elem.find("who").text, width=width-2) + lines = elem.find("thetext").text.split("\n") + for line in lines: + output += textwrap.wrap(line, width=width-2) + output.append("-" * (width - 2)) - self.contents_pad_pos = 0 + self.contents_pad_length = len(output) - for i in range(len(output)): - if type(output[i]) == unicode: - real_output = output[i] - else: - real_output = unicode(output[i], errors='replace') - self.contents_pad.addstr(i, 0, real_output.encode("utf-8")) + self.contents_pad = curses.newpad(max(self.contents_pad_length, self.height), width) + self.contents_pad.erase() - def scroll_contents_pad(self, amount): - height = self.contents_pad_length - self.height + 5 - - self.contents_pad_pos += amount - if self.contents_pad_pos < 0: self.contents_pad_pos = 0 - if self.contents_pad_pos >= height: - self.contents_pad_pos = height - 1 - self.refresh_contents_pad() - - def refresh_contents_pad(self): - self.contents_pad.refresh( - self.contents_pad_pos, 0, - 1, self.width / 3 + 1, - self.height - 2, self.width - 2) - self.screen.refresh() + + for i in range(len(output)): + if type(output[i]) == unicode: + real_output = output[i] + else: + real_output = unicode(output[i], errors='replace') + self.contents_pad.addstr(i, 0, real_output.encode("utf-8")) + + def scroll_contents_pad(self, amount): + height = self.contents_pad_length - self.height + 5 + + self.contents_pad_pos += amount + if self.contents_pad_pos < 0: + self.contents_pad_pos = 0 + if self.contents_pad_pos >= height: + self.contents_pad_pos = height - 1 + self.refresh_contents_pad() + + def refresh_contents_pad(self): + self.contents_pad.refresh( + self.contents_pad_pos, 0, + 1, self.width / 3 + 1, + self.height - 2, self.width - 2) + self.screen.refresh() if __name__ == "__main__": parser = optparse.OptionParser() |