From 044b1566a7b41b4d555e00901c2479a96c72ec87 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 10 Jul 2009 16:07:43 +0000 Subject: [PATCH] added configurable dictionary file option, fixed comment typo git-svn-id: svn://svn.open-ils.org/ILS-Contrib/constrictor/trunk@577 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- constrictor.properties | 1 + constrictor.py | 2 +- contrib/evergreen/eg_utils.py | 20 +++++++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/constrictor.properties b/constrictor.properties index cde875068..4bb1298be 100644 --- a/constrictor.properties +++ b/constrictor.properties @@ -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= diff --git a/constrictor.py b/constrictor.py index d3f3fc0d4..54b6277d2 100755 --- a/constrictor.py +++ b/constrictor.py @@ -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] diff --git a/contrib/evergreen/eg_utils.py b/contrib/evergreen/eg_utils.py index 25096d251..6097647e4 100644 --- a/contrib/evergreen/eg_utils.py +++ b/contrib/evergreen/eg_utils.py @@ -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 -- 2.43.2