[open-ils-commits] r555 - constrictor/trunk/contrib/evergreen (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jul 1 11:33:21 EDT 2009
Author: erickson
Date: 2009-07-01 11:33:19 -0400 (Wed, 01 Jul 2009)
New Revision: 555
Added:
constrictor/trunk/contrib/evergreen/eg_user_search.py
Modified:
constrictor/trunk/contrib/evergreen/eg_bib_search.py
constrictor/trunk/contrib/evergreen/eg_tasks.py
constrictor/trunk/contrib/evergreen/eg_utils.py
Log:
added really dumb (for now) user search script. made generic random phrase generator in utils
Modified: constrictor/trunk/contrib/evergreen/eg_bib_search.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_bib_search.py 2009-07-01 03:10:26 UTC (rev 554)
+++ constrictor/trunk/contrib/evergreen/eg_bib_search.py 2009-07-01 15:33:19 UTC (rev 555)
@@ -22,13 +22,7 @@
# randomly add many more optional flags
}
- word_count = int( (random.random() * 3) % 3) + 1 # search phrase has 1-4 words
- search_term = ''
-
- for i in range(0, word_count):
- word = words[ int(random.random() * len(words)) ]
- search_term += '%s ' % word[0:len(word)-1]
-
+ search_term = eg_utils.random_phrase(None, 3) # search phrase has 1-3 words
logInfo('Search term="%s" args="%s"' % (search_term, str(search_args)))
res = eg_tasks.TASKS['BibSearchTask'].run(
Modified: constrictor/trunk/contrib/evergreen/eg_tasks.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_tasks.py 2009-07-01 03:10:26 UTC (rev 554)
+++ constrictor/trunk/contrib/evergreen/eg_tasks.py 2009-07-01 15:33:19 UTC (rev 555)
@@ -176,3 +176,15 @@
registerTask(UserTransactionsByType())
+class UserSearchTask(AbstractMethodTask):
+
+ def __init__(self):
+ AbstractMethodTask.__init__(self)
+ self.service = 'open-ils.actor'
+ self.method = 'open-ils.actor.patron.search.advanced'
+
+ def run(self, **kw):
+ return self.runMethod(eg_utils.authtoken(), kw['search_args'], 100)
+
+registerTask(UserSearchTask())
+
Added: constrictor/trunk/contrib/evergreen/eg_user_search.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_user_search.py (rev 0)
+++ constrictor/trunk/contrib/evergreen/eg_user_search.py 2009-07-01 15:33:19 UTC (rev 555)
@@ -0,0 +1,35 @@
+from constrictor.task import Task
+from constrictor.script import Script, ScriptManager, ScriptThread
+from constrictor.log import *
+import eg_utils, eg_data, eg_tasks
+import random
+
+eg_utils.init()
+
+class UserSearchScript(Script):
+
+ def run(self):
+
+ dm = eg_data.DataManager()
+
+ # TODO pull names from the cencus data files we have for generating test users
+ search_args = {
+ 'family_name' : {'value' : eg_utils.random_phrase(1), 'group' : 0},
+ 'first_given_name' : {'value' : eg_utils.random_phrase(1), 'group' : 0}
+ }
+
+ logInfo('Search for patron %s' % str(search_args))
+
+ try:
+ res = eg_tasks.TASKS['UserSearchTask'].run(search_args = search_args)
+
+ logInfo('Search returned %d hits' % len(res))
+ except Exception, e:
+ logErrror(e)
+
+ return True
+
+ScriptManager.go(UserSearchScript())
+
+
+
Modified: constrictor/trunk/contrib/evergreen/eg_utils.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_utils.py 2009-07-01 03:10:26 UTC (rev 554)
+++ constrictor/trunk/contrib/evergreen/eg_utils.py 2009-07-01 15:33:19 UTC (rev 555)
@@ -7,11 +7,13 @@
from oils.utils.utils import md5sum
from oils.event import Event
from oils.const import *
-import os, errno
+import os, errno, random
props = Properties.getProperties()
+words = None
def init():
+ global words
loadIDL()
initOsrf()
@@ -38,6 +40,9 @@
props.setProperty('evergreen.orgIDs', str(user.home_ou()))
+ words_file = open('/usr/share/dict/words') # add config property
+ words = words_file.readlines()
+ words_file.close()
def initOsrf():
@@ -169,3 +174,17 @@
class ILSEventException(Exception):
pass
+
+def random_phrase(num_words, max_num_words=3):
+
+ if num_words is None:
+ num_words = int( (random.random() * max_num_words) % max_num_words) + 1
+
+ phrase = ''
+
+ for i in range(0, num_words):
+ word = words[ int(random.random() * len(words)) ]
+ phrase += '%s ' % word[0:len(word)-1]
+
+ return phrase
+
More information about the open-ils-commits
mailing list