1 from constrictor.properties import Properties
2 from constrictor.script import ScriptThread
3 from constrictor.log import *
4 from oils.utils.utils import unique
6 PROP_USERNAME = 'evergreen.username'
7 PROP_PASSWORD = 'evergreen.password'
8 PROP_WORKSTATION = 'evergreen.workstation'
9 PROP_COPY_BARCODE = 'evergreen.copyBarcodes'
10 PROP_TITLE_ID = 'evergreen.titleIDs'
11 PROP_PATRON_BARCODE = 'evergreen.patronBarcodes'
12 PROP_ORG_ID = 'evergreen.orgIDs'
13 PROP_PATRON_ID = 'evergreen.patronIDs'
15 PROP_CONSTRICTOR_THREADS = 'constrictor.numThreads'
17 class DataManagerException(Exception):
20 class DataManager(object):
21 ''' This module manages a global cache of test data '''
25 self.props = Properties.get_properties()
30 s = 'DataManager() read properties:\n'
40 s += "\t%s=%s\n" % (p, str(self.data[p]))
45 self.readProp(PROP_USERNAME)
46 self.readProp(PROP_PASSWORD)
47 self.readProp(PROP_WORKSTATION)
48 self.readProp(PROP_COPY_BARCODE, True)
49 self.readProp(PROP_TITLE_ID, True)
50 self.readProp(PROP_PATRON_BARCODE, True)
51 self.readProp(PROP_PATRON_ID, True)
52 self.readProp(PROP_ORG_ID, True)
54 def readProp(self, prop, split=False):
55 v = self.props.get_property(prop)
57 v = unique(v.split(','))
59 log_debug("DataManager set property %s => %s" % (prop, str(v)))
61 def get_thread_data(self, prop, noSharing=False):
62 ''' If the caller is requesting array-based data, we want to de-multiplex(?)
63 the requested data based on the currently running thread. In other
64 words, each thread should have its own view into the array of data
65 so that different threads are not sharing data. If there are more
66 running threads than unique points of data, then sharing is inevitable,
67 and it's assumed that's OK unless noSharing is set to true, in which
68 case an exception is raised. For atomic data, the value is returned
69 and no thread data is checked '''
71 data = self.data.get(prop)
72 if not isinstance(data, list):
75 currentThread = ScriptThread.get_thread_id()
76 totalThreads = self.props.get_property(PROP_CONSTRICTOR_THREADS)
78 if len(data) > currentThread:
79 return data[currentThread]
82 raise DataManagerException(
83 "Too many threads for unique data. Thread index is %d, size of dataset is %d" % (
84 currentThread, len(data)))
87 return data[currentThread % len(data)]