summaryrefslogtreecommitdiffstats
path: root/yum-presto-legacy/shared/prestoThread.py
diff options
context:
space:
mode:
Diffstat (limited to 'yum-presto-legacy/shared/prestoThread.py')
-rw-r--r--yum-presto-legacy/shared/prestoThread.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/yum-presto-legacy/shared/prestoThread.py b/yum-presto-legacy/shared/prestoThread.py
new file mode 100644
index 0000000..e090910
--- /dev/null
+++ b/yum-presto-legacy/shared/prestoThread.py
@@ -0,0 +1,53 @@
+# authors: Ahmed Kamal <email.ahmedkamal@googlemail.com>
+# Jonathan Dieter <jdieter@gmail.com>
+#
+# 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Copyright 2007 Ahmed Kamal, Jonathan Dieter
+
+import threading
+
+class ReconstructionThread(threading.Thread):
+ def __init__(self, queue, lock, run_function):
+ threading.Thread.__init__(self)
+ self.run_function = run_function
+ self.queue = queue
+ self.lock = lock
+ self.can_exit = False
+ self.messages = ""
+
+ def run(self):
+ while True:
+ try:
+ retval = self.queue.get(not self.can_exit)
+ except:
+ # If we're done with our drpms and no more are coming, let's
+ # blow this joint
+ break
+ if retval != None:
+ messages = apply(self.run_function, retval)
+ if self.can_exit:
+ # If there are not going to be any more new drpms,
+ # send messages directly to conduit
+ conduit = retval[0]
+ if self.messages != "":
+ conduit.info(2, self.messages[:-1])
+ self.messages = ""
+ if messages != "":
+ conduit.info(2, messages[:-1])
+ else:
+ # We may be downloading drpms still, so queue messages
+ self.lock.acquire()
+ self.messages += messages
+ self.lock.release()