#!/usr/bin/python # # stale_critpath.py - script to gather information on Fedora critpath updates # and the time that they have been waiting for enough karma # to be pushed to stable. # # Copyright 2011, Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # Authors: # Tim Flink import fedora.client import datetime import sys import optparse class StaleCritpath(): max_updates = 1000 def __init__(self): self.bodhi = fedora.client.bodhi.BodhiClient() def get_critpath_updates(self, rel): updates = self.bodhi.query(release=rel, status='testing', limit=self.max_updates) # we're interested in updates that aren't requested to be pushed to # stable yet return [up for up in updates['updates'] if up['critpath'] and up['request'] != 'stable'] def sort_oldest_critpath(self, updates): timed_updates = [] now = datetime.datetime.utcnow() for update in updates: date = datetime.datetime.strptime(update['date_pushed'], '%Y-%m-%d %H:%M:%S') delta = now - date timed_updates.append((delta, update)) return sorted(timed_updates, key=lambda up:up[0], reverse=True) if __name__ == '__main__': parser = optparse.OptionParser(description= 'Script to gather information about how long \ critpath updates have been in updates-testing') parser.add_option('-r', '--release', action='store', type='int', default=None, help='Version of Fedora to check for (default: all)') (opts, args) = parser.parse_args() if opts.release: releases = [opts.release] else: # this should really detect releases instead of hardcoding them releases = [14, 15, 16] stale = StaleCritpath() for release in releases: updates = stale.get_critpath_updates('f%d' % release) s_up = stale.sort_oldest_critpath(updates) print '********************************************************************************' print '* Fedora %d %-66s *' % (release, 'Updates Waiting for Push to Stable') print '********************************************************************************' print " %d eligible critpath updates found in f%d-updates-testing" % (len(s_up), release) print "" print " time | update title" print '--------------------------------------------------------------------------------' for up in s_up: print "%3d days | %s" % (up[0].days, str(up[1]['title'])) # this makes it easier to read if all versions are requested but # just makes a mess if only one is requested if len(releases) > 1: print '\n'