#!/usr/bin/python # vim: fileencoding=utf8 import re import readline import subprocess import yum from textwrap import wrap from fedora.client.bodhi import BodhiClient # Bodhi username USERNAME="skvidal" RELEASE="F12" # date after which an update has to be created to not ignore it DATE="2010-01-01 00:00:00" IS_UPDATES_TESTING = re.compile(r'([^\.]+)\.[^ ]+[ ]*([^ ]+)[ ]*@updates-testing') BODHI_BUG_RE = re.compile(r'(: )([1-9][0-9]*)( - )') def notes_wrap(notes, width=67, subsequent_indent=(" "*11 + ": ")): return ("\n" + subsequent_indent).join(map(lambda p: "\n".join(wrap(p, width=width, subsequent_indent=subsequent_indent)), notes.split("\r\n"))).split("\n") # copied from /usr/lib/python2.6/site-packages/fedora/client/bodhi.py to fix wrapping of notes # This makes this copy of easy-karma licensed as LGPL2.1 def bodhi_update_str(self, update, minimal=False): """ Return a string representation of a given update dictionary. :arg update: An update dictionary, acquired by the ``list`` method. :kwarg minimal: Return a minimal one-line representation of the update. """ if isinstance(update, basestring): return update if minimal: val = "" date = update['date_pushed'] and update['date_pushed'].split()[0] \ or update['date_submitted'].split()[0] val += ' %-43s %-11s %-8s %10s ' % (update['builds'][0]['nvr'], update['type'], update['status'], date) for build in update['builds'][1:]: val += '\n %s' % build['nvr'] return val val = "%s\n%s\n%s\n" % ('=' * 80, '\n'.join( wrap(update['title'].replace(',', ', '), width=80, initial_indent=' '*5, subsequent_indent=' '*5)), '=' * 80) if update['updateid']: val += " Update ID: %s\n" % update['updateid'] val += """ Release: %s Status: %s Type: %s Karma: %d""" % (update['release']['long_name'], update['status'], update['type'], update['karma']) if update['request'] != None: val += "\n Request: %s" % update['request'] if len(update['bugs']): bugs = '' i = 0 for bug in update['bugs']: bugstr = '%s%s - %s\n' % (i and ' ' * 11 + ': ' or '', bug['bz_id'], bug['title']) bugs += '\n'.join(wrap(bugstr, width=67, subsequent_indent=' '*11+': ')) + '\n' i += 1 bugs = bugs[:-1] val += "\n Bugs: %s" % bugs if update['notes']: notes = notes_wrap(update['notes'], width=67, subsequent_indent=' ' * 11 + ': ') val += "\n Notes: %s" % '\n'.join(notes) val += """ Submitter: %s Submitted: %s\n""" % (update['submitter'], update['date_submitted']) if len(update['comments']): val += " Comments: " comments = [] for comment in update['comments']: if comment['anonymous']: anonymous = " (unauthenticated)" else: anonymous = "" comments.append("%s%s%s - %s (karma %s)" % (' ' * 13, comment['author'], anonymous, comment['timestamp'], comment['karma'])) if comment['text']: text = wrap(comment['text'], initial_indent=' ' * 13, subsequent_indent=' ' * 13, width=67) comments.append('\n'.join(text)) val += '\n'.join(comments).lstrip() + '\n' if update['updateid']: val += "\n %s\n" % ('%s%s/%s' % (self.base_url, update['release']['name'], update['updateid'])) else: val += "\n %s\n" % ('%s%s' % (self.base_url, update['title'])) return val def update_str(bc, update): bodhi_str = bodhi_update_str(bc, update) update_info = BODHI_BUG_RE.sub(r"\1https://bugzilla.redhat.com/\2\3", bodhi_str) return update_info def already_commented(update, user): for comment in update["comments"]: if not comment["anonymous"] and comment["author"] == user: return True return False if __name__ == "__main__": bc = BodhiClient(username=USERNAME) my = yum.YumBase() my.preconf.debuglevel=0 updates_packages = [] for pkg in my.rpmdb.returnPackages(): if pkg.yumdb_info.get('from_repo') == 'updates-testing': updates_packages.append(pkg.sourcerpm[:-8]) updates_packages = set(updates_packages) # probably raises some exceptions testing_updates = bc.query(release=RELEASE, status="testing", limit=1000)["updates"] # create a mapping build -> update testing_builds = {} for update in testing_updates: if not already_commented(update, USERNAME): for build in update['builds']: testing_builds[build['nvr']] = update for build in testing_builds: update = testing_builds[build] date = update["date_submitted"] if date > DATE and build in updates_packages: print update_str(bc, update) karma = raw_input("Comment? -1/0/1 ->karma, other -> skip> ") if karma in ["-1", "0", "1"]: comment = raw_input("Comment> ") if comment: subprocess.call(["bodhi", "-k", karma, "-c", comment, "-u", USERNAME, update["title"]]) else: print "skipped because of empty comment"