added configurable dictionary file option, fixed comment typo
authorerickson <erickson@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 10 Jul 2009 16:07:43 +0000 (16:07 +0000)
committererickson <erickson@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 10 Jul 2009 16:07:43 +0000 (16:07 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/constrictor/trunk@577 6d9bc8c9-1ec2-4278-b937-99fde70a366f

constrictor.properties
constrictor.py
contrib/evergreen/eg_utils.py

index cde8750..4bb1298 100644 (file)
@@ -61,6 +61,7 @@ evergreen.autologin=true
 evergreen.username=demo
 evergreen.password=demo123
 evergreen.workstation=demo
+evergreen.dictionary=/usr/share/dict/words
 #evergreen.titleIDs=
 #evergreen.patronIDs=
 #evergreen.orgIDs=
index d3f3fc0..54b6277 100755 (executable)
@@ -38,7 +38,7 @@ python %s [options]
         -s test script to run (property constrictor.script)
         -t number of threads to launch (property constrictor.numThreads)
         -i number of test iterations per thread (property constrictor.numIterations)
-        -d database file (constrictor.property dbFile)
+        -d database file (property constrictor.dbFile)
         -p port to listen for controller connections on
         -l listen address for incoming controller connections
 ''' % sys.argv[0]
index 25096d2..6097647 100644 (file)
@@ -10,7 +10,8 @@ from oils.const import *
 import os, errno, random
 
 props = Properties.getProperties()
-words = None
+words = []
+default_dictionary = '/usr/share/dict/words'
 
 def init():
     global words
@@ -40,9 +41,15 @@ def init():
             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()
+    dict_file = props.getProperty('evergreen.dictionary') or default_dictionary
+    try:
+        words_file = open(dict_file)
+    except Exception:
+        logError("Unable to open dictionary file '%s'" % dict_file)
+        return
+        
+    words = words_file.readlines()
+    words_file.close()
 
 
 def initOsrf():
@@ -183,7 +190,10 @@ def random_phrase(num_words, max_num_words=3):
     phrase = ''
 
     for i in range(0, num_words):
-        word = words[ int(random.random() * len(words)) ]
+        try:
+            word = words[ int(random.random() * len(words)) ]
+        except IndexError:
+            continue
         phrase += '%s ' % word[0:len(word)-1]
 
     return phrase