Permalink
Browse files

Enable parrallelization of .get_history operations

  • Loading branch information...
1 parent 5b55211 commit 24510ab64b08200de7885316adb4609ed4b8092c Knud Poulsen committed Mar 9, 2011
Showing with 38 additions and 5 deletions.
  1. +37 −4 SynergyUtils.py
  2. +1 −1 TaskObject.py
View
@@ -8,6 +8,7 @@
"""
import SynergySession
+import SynergySessions
import FileObject
import TaskObject
from datetime import datetime
@@ -16,6 +17,8 @@
from itertools import product
import os.path
import os
+from threading import Thread
+from Queue import Queue
class CCMFilePath(object):
"""Get the file path of an object from Synergy"""
@@ -190,10 +193,24 @@ def find_status_time(self, status, status_log):
time = datetime.strptime(line.partition(': Status')[0], "%a %b %d %H:%M:%S %Y")
if time < earliest:
earliest = time
-
return earliest
+class ObjectHistoryPool(object):
+ """ Wrap a bunch of ObjectHistory objects in one indexable pool object, """
+ def __init__(self, ccmpool, current_release, old_release = None):
+ self.ccmpool = ccmpool
+ self.objectHistoryArray = {}
+ for i in range (self.ccmpool.nr_sessions):
+ self.objectHistoryArray[i] = ObjectHistory(ccmpool[i], current_release, old_release)
+
+ def __getitem__(self, index):
+ if ((index > self.ccmpool.max_session_index) or (index < 0)):
+ raise IndexError("ObjectHistoryPool, __getitem__, index " + str(index) + "is not between 0 and " + str(self.ccmpool.max_session_index))
+ historyobject = self.objectHistoryArray[index]
+ return historyobject
+
+
class ObjectHistory(object):
""" Get the history of one object backwards in time """
@@ -216,7 +233,24 @@ def __init__(self, ccm, current_release, old_release = None):
sub = self.ccm.query("recursive_is_member_of('{0}', 'none') and type='project'".format(current_release)).format('%objectname').run()
self.current_subproject_list = [s['objectname'] for s in sub]
self.current_subproject_list.append(current_release)
+ self.q = Queue()
+ def start_get_history(self, objectholder):
+ self.t = Thread(target=self.pget_history, args=(self.q, objectholder,))
+ self.t.start()
+
+ def join_get_history(self):
+ retval = self.q.get()
+ self.q.task_done()
+ self.q.join()
+ self.t.join()
+ return retval
+
+ def pget_history(self, q, objectholder):
+ self.q = q
+ retval = self.get_history(objectholder)
+ self.q.put(retval)
+ return retval
def get_history(self, fileobject):
#print ""
@@ -253,8 +287,7 @@ def get_history(self, fileobject):
print "Filepath:", path
print ""
self.history[fileobject.get_object_name()] = fileobject
-
-
+
return self.history
def add_to_history(self, fileobject):
@@ -311,7 +344,7 @@ def recursive_get_history(self, fileobject):
- # Check if predecessor is already added to history - if so add this as successor to fileobject, else add new predecessor to history
+ # Check if predecessor is already added to history - if so add this as successor to fileobject, else add new predecessor to history
if self.history.has_key(predecessor.get_object_name()):
print "Updating", predecessor.get_object_name(), predecessor.get_status(), "in history. Path:", path
predecessor = self.history[predecessor.get_object_name()]
View
@@ -69,7 +69,7 @@ def set_complete_time(self, complete_time):
def set_attributes(self, attributes):
self.attributes = attributes
- self.complete_time = self.find_status_time('complete', self.attributes['status_log'])
+ self.complete_time = self.find_status_time('complete', self.attributes['status_log'], self.instance)
if 'task_description' in self.attributes.keys():
self.description = self.attributes['task_description']
if 'task_number' in self.attributes.keys():

0 comments on commit 24510ab

Please sign in to comment.