diff options
Diffstat (limited to 'fedora-easy-karma.py')
-rwxr-xr-x | fedora-easy-karma.py | 121 |
1 files changed, 86 insertions, 35 deletions
diff --git a/fedora-easy-karma.py b/fedora-easy-karma.py index a605d60..7671f63 100755 --- a/fedora-easy-karma.py +++ b/fedora-easy-karma.py @@ -48,6 +48,8 @@ except ImportError: from fedora.client.bodhi import BodhiClient +PROMPT = "Comment? -1/0/1 -> karma, 'i' -> ignore, other -> skip> " + class FEK_helper(object): @staticmethod @@ -82,9 +84,10 @@ class FEK_helper(object): values["header_line"] = "=" * width values["title"] = "\n".join( wrap(update["title"].replace(",", ", "), - width=width, - initial_indent=" " * 5, - subsequent_indent=" " * 5)) + width=width, + initial_indent=" " * 5, + subsequent_indent=" " * 5) + ) if update["updateid"]: values["updateid"] = " Update ID: %s\n" % update["updateid"] @@ -117,20 +120,33 @@ class FEK_helper(object): bugs.append("%s - %s" % (bz_id, bz_title)) if wrap_bugs: - values["bugs"] = "%s\n" % FEK_helper.wrap_paragraphs_prefix(bugs, first_prefix=" Bugs: ", width=width, extra_newline=True) + values["bugs"] = "%s\n" % FEK_helper.wrap_paragraphs_prefix( + bugs, first_prefix=" Bugs: ", width=width, + extra_newline=True + ) else: - values["bugs"] = " Bugs: %s\n" % ("\n" + " " * 11 + ": ").join(bugs) + values["bugs"] = " Bugs: %s\n" % ( + "\n" + " " * 11 + ": ").join(bugs) else: values["bugs"] = "" if update["nagged"] and "test_cases" in update["nagged"]: - test_cases = ["%s%s" % (test_cases_url, t.replace(" ", "_").replace(":", "%3A")) for t in update["nagged"]["test_cases"]] - values["test_cases"] = "%s\n" % FEK_helper.wrap_paragraphs_prefix(test_cases, first_prefix=" Test Cases: ", width=width, extra_newline=True) + test_cases = [] + for tc in update["nagged"]["test_cases"]: + tc = tc.replace(" ", "_").replace(":", "%3A") + test_cases.append(test_cases_url + tc) + values["test_cases"] = "%s\n" % FEK_helper.wrap_paragraphs_prefix( + test_cases, first_prefix=" Test Cases: ", width=width, + extra_newline=True + ) else: values["test_cases"] = "" if update["notes"]: - values["notes"] = "%s\n" % FEK_helper.wrap_paragraphs_prefix(update["notes"].split("\r\n"), first_prefix=" Notes: ", width=width) + values["notes"] = "%s\n" % FEK_helper.wrap_paragraphs_prefix( + update["notes"].split("\r\n"), first_prefix=" Notes: ", + width=width + ) else: values["notes"] = "" @@ -148,10 +164,14 @@ class FEK_helper(object): if comment["anonymous"]: comment["author"] += " (unauthenticated)" - comments.append("%(indent)s%(author)s - %(timestamp)s (karma %(karma)s)" % comment) + comments.append( + "%(indent)s%(author)s - %(timestamp)s (karma %(karma)s)" % + comment + ) if comment["text"]: - wrapped = wrap(comment["text"], initial_indent=indent, subsequent_indent=indent, width=width) + wrapped = wrap(comment["text"], initial_indent=indent, + subsequent_indent=indent, width=width) comments.append("\n".join(wrapped)) val += "\n".join(comments).lstrip() + "\n" values["comments"] = val @@ -159,21 +179,26 @@ class FEK_helper(object): values["comments"] = "" if update["updateid"]: - url_path = "%s/%s" % (update["release"]["name"], update["updateid"]) + url_path = "%s/%s" % (update["release"]["name"], + update["updateid"]) else: url_path = update["title"] values["update_url"] = " %s%s\n" % (bodhi_base_url, url_path) - values["karma_status"] = "%d/%d" % (values["karma"], values["stable_karma"]) + values["karma_status"] = "%d/%d" % (values["karma"], + values["stable_karma"]) return format_string % values @staticmethod - def wrap_paragraphs(paragraphs, width=67, subsequent_indent=(" "*11 + ": "), second_column_indent=0): + def wrap_paragraphs(paragraphs, width=67, + subsequent_indent=(" " * 11 + ": "), + second_column_indent=0): return ("\n%s" % subsequent_indent).join(map(lambda p: "\n".join(wrap(p, width=width, subsequent_indent=(subsequent_indent + " " * second_column_indent))), paragraphs)) @staticmethod - def wrap_paragraphs_prefix(paragraphs, first_prefix, width=80, extra_newline=False): + def wrap_paragraphs_prefix(paragraphs, first_prefix, width=80, + extra_newline=False): if isinstance(paragraphs, basestring): paragraphs = paragraphs.split("\n") @@ -351,7 +376,8 @@ class FedoraEasyKarma(object): for pkg in pkghelper.installed_packages: installed = datetime.datetime.fromtimestamp(pkg.installtime) installed_timedelta = now - installed - if installed_timedelta < installed_max_days and installed_timedelta > installed_min_days: + if installed_timedelta < installed_max_days and \ + installed_timedelta > installed_min_days: build = pkg.sourcerpm[:-8] if build in installed_testing_builds: installed_testing_builds[build].append(pkg) @@ -432,39 +458,46 @@ class FedoraEasyKarma(object): # python-fedora 0.3.20 and might not want to do to keep the cache # complete if self.options.critpath_only: - testing_updates = [u for u in testing_updates if u["critpath"] and not u["critpath_approved"]] + testing_updates = [u for u in testing_updates if u["critpath"] and + not u["critpath_approved"]] # create a mapping build -> update testing_builds = {} for update in testing_updates: - if self.options.include_commented or not self.already_commented(update, self.options.fas_username): + if self.options.include_commented or not \ + self.already_commented(update, self.options.fas_username): for build in update["builds"]: testing_builds[build["nvr"]] = update self.debug("starting feedback loop") - # multiple build can be grouped together in one update, only ask once per update + # multiple build can be grouped together in one update, only ask once + # per update processed_updates = [] ignored_updates = [] builds = testing_builds.keys() builds.sort() if not builds: - print "No testing packages found, you can run "\ - "'%s update --enablerepo=\"*-testing\"' to install some" % pkghelper.package_manager + print "No testing packages found, install some with: "\ + "'%s update --enablerepo=\"*-testing\"'" % \ + pkghelper.package_manager for build in builds: update = testing_builds[build] # Do not query for previously ignored updates # Store update title to save these to a file - if not self.options.include_ignored and update.title in previously_ignored_updates: + if not self.options.include_ignored and \ + update.title in previously_ignored_updates: print "ignored: %s" % update.title ignored_updates.append(update.title) continue # Ignore own updates - if self.options.ignore_own and update["submitter"] == self.options.fas_username: + if self.options.ignore_own and \ + update["submitter"] == self.options.fas_username: continue - if update not in processed_updates and build in installed_testing_builds: + if update not in processed_updates and \ + build in installed_testing_builds: processed_updates.append(update) affected_builds = [b["nvr"] for b in update["builds"]] @@ -475,21 +508,36 @@ class FedoraEasyKarma(object): # remove version and release ["-".join(b.split("-")[:-2]) for b in affected_builds]]): continue - installed_rpms = [self.format_rpm(pkg) for pkg in installed_pkgs] + installed_rpms = [ + self.format_rpm(pkg) for pkg in installed_pkgs] if not self.options.list_rpms_only: - print FEK_helper.bodhi_update_str(update, bodhi_base_url=bc.base_url, width=self.options.wrap_width, wrap_bugs=self.options.wrap_bugs) + print FEK_helper.bodhi_update_str( + update, bodhi_base_url=bc.base_url, + width=self.options.wrap_width, + wrap_bugs=self.options.wrap_bugs + ) if self.options.wrap_rpms: - print FEK_helper.wrap_paragraphs_prefix(installed_rpms, first_prefix=" inst. RPMS: ", width=self.options.wrap_width) + print FEK_helper.wrap_paragraphs_prefix( + installed_rpms, first_prefix=" inst. RPMS: ", + width=self.options.wrap_width) else: - print " inst. RPMS: %s\n" % ("\n" + " " * 11 + ": ").join(installed_rpms) - if self.already_commented(update, self.options.fas_username): + indentation = "\n" + " " * 11 + ": " + rpmlist = indentation.join(installed_rpms) + print " inst. RPMS: %s\n" % rpmlist + if self.already_commented(update, + self.options.fas_username): print "!!! already commented by you !!!" try: - karma = self.raw_input("Comment? -1/0/1 -> karma, 'i' -> ignore, other -> skip> ", default=self.options.default_karma, add_to_history=False) + karma = self.raw_input( + PROMPT, default=self.options.default_karma, + add_to_history=False) if karma in ["-1", "0", "1"]: - comment = self.raw_input("Comment> ", default=self.options.default_comment) + comment = self.raw_input( + "Comment> ", + default=self.options.default_comment) if comment or not self.options.skip_empty_comment: - result = self.send_comment(bc, update, comment, karma) + result = self.send_comment(bc, update, comment, + karma) if not result[0]: self.warning("Comment not submitted: %s" % result[1]) else: @@ -525,7 +573,8 @@ class FedoraEasyKarma(object): # References: # https://fedorahosted.org/bodhi/ticket/400 # https://bugzilla.redhat.com/show_bug.cgi?id=572228 - if not comment["anonymous"] and comment["author"].split(" ")[0] == user: + if not comment["anonymous"] and \ + comment["author"].split(" ")[0] == user: return True return False @@ -543,7 +592,7 @@ class FedoraEasyKarma(object): def format_rpm(self, rpm): now = datetime.datetime.now() - install_age=(now - datetime.datetime.fromtimestamp(rpm.installtime)) + install_age = (now - datetime.datetime.fromtimestamp(rpm.installtime)) res = "%(name)s-%(version)s-%(release)s.%(arch)s - %(summary)s" % rpm res += " (installed %s days ago)" % install_age.days return res @@ -573,7 +622,8 @@ class FedoraEasyKarma(object): readline.set_pre_input_hook(None) if not add_to_history: try: - readline.remove_history_item(readline.get_current_history_length() - 1) + readline.remove_history_item( + readline.get_current_history_length() - 1) # raised when CTRL-D is used on first prompt except ValueError: pass @@ -588,7 +638,8 @@ class FedoraEasyKarma(object): return (True, res) except fedora.client.AuthError, e: self.warning("Authentication error") - bc.password = getpass.getpass('FAS password for %s: ' % self.options.fas_username) + bc.password = getpass.getpass('FAS password for %s: ' % + self.options.fas_username) except fedora.client.ServerError, e: self.warning("Server error: %s" % str(e)) |