---
hooks/post-bodhi-update/watch-bodhi-requests.py | 30 +------------
lib/python/bodhi_utils.py | 49 +++++++++++++++++++++++
2 files changed, 52 insertions(+), 27 deletions(-)
create mode 100755 lib/python/bodhi_utils.py
diff --git a/hooks/post-bodhi-update/watch-bodhi-requests.py b/hooks/post-bodhi-update/watch-bodhi-requests.py
index f1a4e6c..1df5654 100755
--- a/hooks/post-bodhi-update/watch-bodhi-requests.py
+++ b/hooks/post-bodhi-update/watch-bodhi-requests.py
@@ -55,6 +55,7 @@ import optparse
import time
import os
from autoqa.repoinfo import repoinfo
+from autoqa.bodhi_utils import bodhitime, parse_bodhitime, bodhi_list
cachedir = '/var/cache/autoqa/watch-bodhi-requests'
try:
@@ -69,32 +70,8 @@ except OSError, e:
bodhi_releases = ['F11','F12','F13']
archlist = ('i686', 'x86_64', 'noarch')
-
-def bodhitime(timestamp):
- '''Convert timestamp (seconds since Epoch, assumed to be local time) to a
- Bodhi-approved time string ('%Y-%m-%d %H:%M:%S')'''
- return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(timestamp))
-
-def parse_bodhitime(bodhitimestr):
- '''Convert a Bodhi-approved time string ('%Y-%m-%d %H:%M:%S') to a
- float-represented number of seconds since Epoch (local time)'''
- return time.mktime(time.strptime(bodhitimestr,'%Y-%m-%d %H:%M:%S'))
-
-def bodhi_list(params, limit=100):
- '''Perform a bodhi 'list' method call, with pagination handling'''
- bodhi = fedora.client.bodhi.BodhiClient()
- params['tg_paginate_limit'] = limit
- params['tg_paginate_no'] = 1
-
- updates = list()
- num_items = 1 # this is a lie to get us in the loop
- while num_items > len(updates):
- r = bodhi.send_request('list', params)
- num_items = r['num_items']
- updates += r['updates']
- params['tg_paginate_no'] += 1
- return updates
-
+# XXX NOTE we could probably be using cPickle or something here, rather than
+# a possibly-unreliable invented encoding/decoding to save a set()
def save_update_ids(update_ids, cachefile):
try:
f = open(cachefile,'w')
@@ -103,7 +80,6 @@ def save_update_ids(update_ids, cachefile):
f.close()
except IOError, e:
print "error: failed to write %s: %s" % (cachefile, str(e))
-
def load_update_ids(cachefile):
update_ids = set()
try:
diff --git a/lib/python/bodhi_utils.py b/lib/python/bodhi_utils.py
new file mode 100755
index 0000000..cb91bf8
--- /dev/null
+++ b/lib/python/bodhi_utils.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+# bodhi_utils.py - utility functions for dealing with bodhi
+#
+# Copyright 2010, 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:
+# Will Woods <wwoods(a)redhat.com>
+
+import fedora.client
+import time
+
+def bodhitime(timestamp):
+ '''Convert timestamp (seconds since Epoch, assumed to be local time) to a
+ Bodhi-approved time string ('%Y-%m-%d %H:%M:%S')'''
+ return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(timestamp))
+
+def parse_bodhitime(bodhitimestr):
+ '''Convert a Bodhi-approved time string ('%Y-%m-%d %H:%M:%S') to a
+ float-represented number of seconds since Epoch (local time)'''
+ return time.mktime(time.strptime(bodhitimestr,'%Y-%m-%d %H:%M:%S'))
+
+def bodhi_list(params, limit=100):
+ '''Perform a bodhi 'list' method call, with pagination handling'''
+ bodhi = fedora.client.bodhi.BodhiClient()
+ params['tg_paginate_limit'] = limit
+ params['tg_paginate_no'] = 1
+
+ updates = list()
+ num_items = 1 # this is a lie to get us in the loop
+ while num_items > len(updates):
+ r = bodhi.send_request('list', params)
+ num_items = r['num_items']
+ updates += r['updates']
+ params['tg_paginate_no'] += 1
+ return updates
--
1.7.0.1