only load dynamic test objects when they are not already defined in the properties...
authorerickson <erickson@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 18 May 2010 21:30:37 +0000 (21:30 +0000)
committererickson <erickson@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 18 May 2010 21:30:37 +0000 (21:30 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/constrictor/trunk@887 6d9bc8c9-1ec2-4278-b937-99fde70a366f

contrib/evergreen/eg_batch.py
contrib/evergreen/eg_data.py

index 32ec881..0dcc301 100755 (executable)
@@ -25,41 +25,7 @@ class BatchScript(Script):
     def __init__(self):
         Script.__init__(self)
         self.calls = []
-        self.loaded = False
         self.data_mgr = None
-        self.bibs = []
-        self.copies = []
-        self.call_numbers = []
-        self.org_unis = []
-
-
-    '''
-    def _fetch_dynamic_data(self):
-        pcrud = 'open-ils.pcrud'
-        method = 'open-ils.pcrud.search.%s.atomic'
-        
-        auth = eg_utils.authtoken()
-        thread_count = props.get_property('constrictor.numThreads')
-
-        self.bibs = BatchMethodTask(pcrud, method % 'bre').start(
-            params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
-
-        self.copies = BatchMethodTask(pcrud, method % 'acp').start(
-            params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
-
-        self.call_numbers = BatchMethodTask(pcrud, method % 'acn').start(
-            params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
-
-        self.org_units = BatchMethodTask(pcrud, method % 'aou').start(
-            params = [auth, {'id' : {'>' : 0}}, {'limit' : thread_count}])
-
-        self.data_mgr.insert_prop_data(eg_data.PROP_TITLE_ID, [obj.id() for obj in self.bibs])
-        self.data_mgr.insert_prop_data(eg_data.PROP_COPY_ID, [obj.id() for obj in self.copies])
-        self.data_mgr.insert_prop_data(eg_data.PROP_COPY_BARCODE, [obj.barcode() for obj in self.copies])
-        self.data_mgr.insert_prop_data(eg_data.PROP_CALLNUMBER_ID, [obj.id() for obj in self.call_numbers])
-        self.data_mgr.insert_prop_data(eg_data.PROP_ORG_ID, [obj.id() for obj in self.org_units])
-        self.data_mgr.insert_prop_data(eg_data.PROP_ORG_SHORTNAME, [obj.shortname() for obj in self.org_units])
-    '''
 
     def load_file(self):
         
@@ -147,9 +113,6 @@ class BatchScript(Script):
 
     def run(self):
 
-        if not self.loaded:
-            self.load_file()
-
         for idx in range(0, len(self.calls)):
             call = self.calls[int(random.random() * len(self.calls))]
             try:
@@ -164,4 +127,6 @@ class BatchScript(Script):
 
 
 
-ScriptManager.go(BatchScript())
+script = BatchScript()
+script.load_file() # load the batch API file
+ScriptManager.go(script)
index e81c1bd..1f9df69 100644 (file)
@@ -48,24 +48,42 @@ class DataManager(object):
         auth = eg_utils.authtoken()
         thread_count = self.props.get_property('constrictor.numThreads')
 
-        bibs = DataMethodTask(pcrud, method % 'bre').start(
-            params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
+        if not self.data.get(PROP_TITLE_ID):
 
-        copies = DataMethodTask(pcrud, method % 'acp').start(
-            params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
+            bibs = DataMethodTask(pcrud, method % 'bre').start(
+                params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
 
-        call_numbers = DataMethodTask(pcrud, method % 'acn').start(
-            params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
+            self.insert_prop_data(PROP_TITLE_ID, [obj.id() for obj in bibs])
 
-        org_units = DataMethodTask(pcrud, method % 'aou').start(
-            params = [auth, {'id' : {'>' : 0}}, {'limit' : thread_count}])
+        if not self.data.get(PROP_COPY_ID) or not self.data.get(PROP_COPY_BARCODE):
 
-        self.insert_prop_data(PROP_TITLE_ID, [obj.id() for obj in bibs])
-        self.insert_prop_data(PROP_COPY_ID, [obj.id() for obj in copies])
-        self.insert_prop_data(PROP_COPY_BARCODE, [obj.barcode() for obj in copies])
-        self.insert_prop_data(PROP_CALLNUMBER_ID, [obj.id() for obj in call_numbers])
-        self.insert_prop_data(PROP_ORG_ID, [obj.id() for obj in org_units])
-        self.insert_prop_data(PROP_ORG_SHORTNAME, [obj.shortname() for obj in org_units])
+            copies = DataMethodTask(pcrud, method % 'acp').start(
+                params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
+
+            if not self.data.get(PROP_COPY_ID):
+                self.insert_prop_data(PROP_COPY_ID, [obj.id() for obj in copies])
+
+            if not self.data.get(PROP_COPY_BARCODE):
+                self.insert_prop_data(PROP_COPY_BARCODE, [obj.barcode() for obj in copies])
+
+        if not self.data.get(PROP_CALLNUMBER_ID):
+
+            call_numbers = DataMethodTask(pcrud, method % 'acn').start(
+                params = [auth, {'deleted' : 'f', 'id' : {'>' : 0}}, {'limit' : thread_count}])
+
+            self.insert_prop_data(PROP_CALLNUMBER_ID, [obj.id() for obj in call_numbers])
+
+        if not self.data.get(PROP_ORG_ID) or not self.data.get(PROP_ORG_SHORTNAME):
+
+            org_units = DataMethodTask(pcrud, method % 'aou').start(
+                params = [auth, {'id' : {'>' : 0}}, {'limit' : thread_count}])
+
+            if not self.data.get(PROP_ORG_ID):
+                self.insert_prop_data(PROP_ORG_ID, [obj.id() for obj in org_units])
+
+            if not self.data.get(PROP_ORG_SHORTNAME):
+
+                self.insert_prop_data(PROP_ORG_SHORTNAME, [obj.shortname() for obj in org_units])
 
 
     def __str__(self):