>From 8806f906cf450d5d0f5e76d009753a5b30443fd1 Mon Sep 17 00:00:00 2001
From: Rakesh Pandit <rakesh(a)fedoraproject.org>
Date: Mon, 6 Jul 2009 14:01:16 +0530
Subject: [PATCH] * GachApplication.py (rm_rf, run): Added new function for tmp
directories, added koji builder to GachApplication run method
* GachBugzillaFeeder.py: replaced feed with downloadurl method.
* GachGenericFeeder.py (downloadurl): New function.
* GachKojiBuilder.py (build): Using downloadurl from feeder,
more print messages.
(getState, retrieve): fixed logic and more print statements.
---
GachApplication.py | 21 +++++++++++++++++----
GachBugzillaFeeder.py | 8 ++++----
GachGenericFeeder.py | 38 ++++++++++++++++++++++++++++++++++++++
GachKojiBuilder.py | 26 +++++++++++++++-----------
4 files changed, 74 insertions(+), 19 deletions(-)
diff --git a/GachApplication.py b/GachApplication.py
index 911e8ee..5e6fcc3 100644
--- a/GachApplication.py
+++ b/GachApplication.py
@@ -20,6 +20,7 @@
import os
import sys
import imp
+import time
import tempfile
from Spec import Spec
@@ -34,6 +35,15 @@ from GachReporter import GachReporter
from GachReviewer import runRpmlint
+def rm_rf(d):
+ for path in (os.path.join(d,f) for f in os.listdir(d)):
+ if os.path.isdir(path):
+ rm_rf(path)
+ else:
+ os.unlink(path)
+ os.rmdir(d)
+
+
class NoBugId(Exception):
"""
No Bug Id
@@ -88,6 +98,8 @@ class GachApplication:
# TODO: Need to put bugzilla URL in rom.config file
bzfeeder = GachBugzillaFeeder()
srpm_spec_downdir = tempfile.mkdtemp(prefix='gach')
+ koji_downdir = tempfile.mkdtemp(prefix='koji', dir=srpm_spec_downdir)
+
print "Downloading ..."
file_path = bzfeeder.feed(bugid, srpm_spec_downdir)
@@ -96,7 +108,6 @@ class GachApplication:
for file in file_path:
print file
- print "Started review:"
reporter = GachReporter()
spec = Spec(file_path[0])
pkg = Pkg(file_path[1])
@@ -108,11 +119,13 @@ class GachApplication:
reporter.printDividerInfo("Pkg rpmlint output")
runRpmlint(reporter, pkg)
+ builder = GachKojiBuilder()
+ builder.build(file_path[1], 'dist-f12', wait=True)
+
+ downloaded_files = builder.retrieve(koji_downdir)
print reporter.getReport()
- for file in file_path:
- os.unlink(file)
- os.rmdir(srpm_spec_downdir)
+ rm_rf(srpm_spec_downdir)
return
diff --git a/GachBugzillaFeeder.py b/GachBugzillaFeeder.py
index 937c253..a0e0c12 100644
--- a/GachBugzillaFeeder.py
+++ b/GachBugzillaFeeder.py
@@ -52,10 +52,10 @@ class
GachBugzillaFeeder(GachGenericFeeder.GachGenericFeeder):
uris = self._filterUris(uris)
file_paths = []
if uris:
- file_paths.append(GachGenericFeeder.GachGenericFeeder.feed( \
- self, uris[0], dest))
- file_paths.append(GachGenericFeeder.GachGenericFeeder.feed( \
- self, uris[1], dest))
+
file_paths.append(GachGenericFeeder.GachGenericFeeder.downloadurl( \
+ self, uris[0], dest, basename=True))
+
file_paths.append(GachGenericFeeder.GachGenericFeeder.downloadurl( \
+ self, uris[1], dest, basename=True))
return file_paths
return None
diff --git a/GachGenericFeeder.py b/GachGenericFeeder.py
index 828ad20..e3eaf32 100644
--- a/GachGenericFeeder.py
+++ b/GachGenericFeeder.py
@@ -18,6 +18,9 @@
import os
import urllib2
+from urlparse import urlparse, parse_qs
+import urlgrabber.grabber as grabber
+import urlgrabber.progress as progress
import GachFeeder
@@ -34,6 +37,39 @@ class GachGenericFeeder(GachFeeder.GachFeeder):
GachFeeder.GachFeeder.__init__(self)
self.bs = bs
+ # Alternate method for downloading
+ def downloadurl(self, url, downloaddir, basename=False):
+ """Download url using grabber
+ """
+ pg = progress.TextMeter()
+ urldict = urlparse(url)
+ querydict = parse_qs(urldict.query)
+
+ if not os.path.exists(downloaddir):
+ os.mkdir(downloaddir)
+
+ if basename:
+ filename = os.path.basename(url)
+ else:
+ filename = querydict['name'][0]
+
+ path = downloaddir + '/' + filename
+ out = os.open(path, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0666)
+ file = grabber.urlopen(url, progress_obj = pg, text = "%s" \
+ %(filename))
+
+ try:
+ while 1:
+ buf = file.read(4096)
+ if not buf:
+ break
+ os.write(out, buf)
+ finally:
+ os.close(out)
+ file.close()
+
+ return path
+
def feed(self, item, dest):
"""
item: Spec/SRPM URI.
@@ -43,6 +79,7 @@ class GachGenericFeeder(GachFeeder.GachFeeder):
try:
uri = urllib2.urlopen(item)
except IOError, urllib2.URLError:
+ print "Error while downloading .."
return None
file_path = dest + "/" + os.path.basename(item)
@@ -65,3 +102,4 @@ class GachGenericFeeder(GachFeeder.GachFeeder):
file.close()
uri.close()
return file_path
+
diff --git a/GachKojiBuilder.py b/GachKojiBuilder.py
index decb787..4f63806 100644
--- a/GachKojiBuilder.py
+++ b/GachKojiBuilder.py
@@ -22,6 +22,7 @@ import random
import string
import time
import tempfile
+
import GachBuilder
from GachGenericFeeder import GachGenericFeeder
@@ -79,21 +80,25 @@ class GachKojiBuilder(GachBuilder.GachBuilder):
"""
self.__create_session()
server_dir = _unique_path("gach-build")
+ print "Uploading source %s ... " %(source),
self._session.uploadWrapper(source, server_dir)
+ print "done."
server_source = server_dir + "/" + os.path.basename(source)
build_opts = {"scratch": True, "skip_tag": None}
+ print "Started koji build with",
self.taskId = self._session.build(server_source, target, build_opts)
self.__logout_session()
-
+ print "taskid", self.taskId, ".. waiting ..."
if wait:
while True:
- state = self.get_state()
- print state
+ state = self.getState()
if state in ["CLOSED"]:
+ print "Job CLOSED."
return True
elif state in ["CANCELED", "FAILED"]:
+ print "Job either CANCELED or FAILED."
return False
- time.sleep(2)
+ time.sleep(0.2)
def getState(self):
"""Return state
@@ -108,10 +113,9 @@ class GachKojiBuilder(GachBuilder.GachBuilder):
"""Check is job done
"""
state = self.getState()
- if state in ["CLOSED"]:
+ if state in ["CLOSED", "CANCELED", "FAILED"]:
return True
- elif state in ["CANCELED", "FAILED"]:
- return False
+ return False
def retrieve(self, builddir):
"""Download all build rpms and logs for each child build
@@ -133,10 +137,10 @@ class GachKojiBuilder(GachBuilder.GachBuilder):
print "Downloading ..."
for eachtaskid in output:
- for eachfile in output[eachtaskid]:
- print eachfile + " ... ",
- path = builddir + "/" + str(eachtaskid)
- filepath.append(feeder.feed(eachfile, path))
+ for eachfileurl in output[eachtaskid]:
+ print eachfileurl + " ... ",
+ outdir = builddir + "/" + str(eachtaskid)
+ filepath.append(feeder.downloadurl(eachfileurl, outdir))
print "done."
self.__logout_session()
--
1.6.2.2