From 2347293af57b77a0ce46cf23744b452aafe6269a Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 23 Feb 2010 03:43:33 +0000 Subject: [PATCH] Make this look more like python. (thanks, Perl one-liners) Added a clear cache option to clear the local file cache at startup git-svn-id: svn://svn.open-ils.org/ILS-Contrib/constrictor/trunk@792 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- constrictor.py | 73 ++++++++++++++------------ constrictor/controller.py | 18 +++---- constrictor/data.py | 5 +- constrictor/db.py | 14 ++--- constrictor/log.py | 12 ++--- constrictor/script.py | 84 +++++++++++++++--------------- constrictor/task.py | 8 +-- constrictor/utils.py | 20 +++---- constrictor_gui/control/views.py | 4 +- constrictor_gui/urls.py | 2 +- contrib/evergreen/eg_bib_search.py | 4 +- contrib/evergreen/eg_checkin.py | 4 +- contrib/evergreen/eg_checkout.py | 4 +- contrib/evergreen/eg_checkout_roundtrip.py | 4 +- contrib/evergreen/eg_data.py | 12 ++--- contrib/evergreen/eg_fetch_user_groups.py | 2 +- contrib/evergreen/eg_renew.py | 4 +- contrib/evergreen/eg_title_hold.py | 4 +- contrib/evergreen/eg_user_search.py | 4 +- contrib/evergreen/eg_user_transactions.py | 2 +- contrib/evergreen/eg_utils.py | 56 ++++++++++---------- contrib/evergreen/eg_workflow.py | 28 +++++----- deploy.py | 8 +-- 23 files changed, 192 insertions(+), 184 deletions(-) diff --git a/constrictor.py b/constrictor.py index 1983bb226..39c54f381 100755 --- a/constrictor.py +++ b/constrictor.py @@ -14,12 +14,12 @@ # GNU General Public License for more details. # ----------------------------------------------------------------------- -import sys, getopt, os, errno +import sys, getopt, os, errno, shutil from constrictor.properties import Properties from constrictor.controller import DroneController from constrictor.script import ScriptThread, ScriptManager from constrictor.log import * -from constrictor.utils import loadProps, saveProps, initDirs, initDB, openScript, PROPS_FILENAME +from constrictor.utils import load_props, save_props, init_dirs, init_db, open_script, PROPS_FILENAME import constrictor.data props = None @@ -42,6 +42,8 @@ python %s [options] -d database file (property constrictor.dbFile) -p port to listen for controller connections on -l listen address for incoming controller connections + -x clear the local cache file cache + ''' % sys.argv[0] sys.exit(0) @@ -51,55 +53,60 @@ def read_args_and_props(): global props_filename # see if we have any command-line args that override the properties file - ops, args = getopt.getopt(sys.argv[1:], 's:t:i:d:p:l:f:h') + ops, args = getopt.getopt(sys.argv[1:], 's:t:i:d:p:l:f:hx') options = dict( (k,v) for k,v in ops ) if options.has_key('-f'): props_filename = options['-f'] - loadProps(props_filename) - props = Properties.getProperties() + load_props(props_filename) + props = Properties.get_properties() if options.has_key('-h'): usage() if options.has_key('-s'): - props.setProperty('constrictor.script', options['-s']) + props.set_property('constrictor.script', options['-s']) if options.has_key('-t'): - props.setProperty('constrictor.numThreads', options['-t']) + props.set_property('constrictor.numThreads', options['-t']) if options.has_key('-i'): - props.setProperty('constrictor.numIterations', options['-i']) + props.set_property('constrictor.numIterations', options['-i']) if options.has_key('-d'): - props.setProperty('constrictor.dbFile', options['-d']) + props.set_property('constrictor.dbFile', options['-d']) if options.has_key('-p'): - props.setProperty('constrictor.port', options['-p']) + props.set_property('constrictor.port', options['-p']) if options.has_key('-l'): - props.setProperty('constrictor.listenAddress', options['-l']) + props.set_property('constrictor.listenAddress', options['-l']) + + if options.has_key('-x'): + # delete the cache directory + cacheDir = props.get_property('constrictor.cacheDir') + shutil.rmtree(os.path.join(os.getcwd(), cacheDir)) def onThreadsComplete(scriptManager): global droneController - #summary = ScriptThread.currentScriptThread().dbConnection.createTaskSummary() + #summary = ScriptThread.current_script_thread().dbConnection.createTaskSummary() #droneController.sendResult(type='task_summary', **summary) read_args_and_props() -initDirs() -initLog() -scriptDirs = props.getProperty('constrictor.scriptDirs').split(',') +init_dirs() +init_log() +scriptDirs = props.get_property('constrictor.scriptDirs').split(',') -if props.getProperty('constrictor.listen') == 'true': +if props.get_property('constrictor.listen') == 'true': ''' This is the main controller listen loop. Here, we accept commands from the controller module, perform the action, then go back to listening ''' droneController = DroneController( - props.getProperty('constrictor.address'), - int(props.getProperty('constrictor.port'))) + props.get_property('constrictor.address'), + int(props.get_property('constrictor.port'))) - ScriptManager.setOnThreadsComplete(onThreadsComplete) + ScriptManager.set_on_threads_complete(onThreadsComplete) while True: try: @@ -108,26 +115,26 @@ if props.getProperty('constrictor.listen') == 'true': if command['action'] == 'setprop': prop = str(command['prop']) val = str(command['val']) - logInfo('setting property %s %s' % (prop, val)) - props.setProperty(prop, val) + log_info('setting property %s %s' % (prop, val)) + props.set_property(prop, val) continue if command['action'] == 'saveprops': - logInfo("saving properties back to file") - saveProps() + log_info("saving properties back to file") + save_props() continue if command['action'] == 'run': - ScriptThread.resetThreadSeed() - script = props.getProperty('constrictor.script') - logInfo('running ' + script) - f = openScript(scriptDirs, script) + ScriptThread.reset_thread_seed() + script = props.get_property('constrictor.script') + log_info('running ' + script) + f = open_script(scriptDirs, script) if f: - initDB() + init_db() try: exec(f) except Exception, e: - logError("script execution failed: %s" % str(e)) + log_error("script execution failed: %s" % str(e)) droneController.sendError(text=str(e)) f.close() continue @@ -136,10 +143,10 @@ if props.getProperty('constrictor.listen') == 'true': droneController.shutdown() else: - initDB() - script = props.getProperty('constrictor.script') # execute the requested script - ScriptThread.resetThreadSeed() - f = openScript(scriptDirs, script) + init_db() + script = props.get_property('constrictor.script') # execute the requested script + ScriptThread.reset_thread_seed() + f = open_script(scriptDirs, script) if f: exec(f) f.close() diff --git a/constrictor/controller.py b/constrictor/controller.py index 2263d850e..54fe9a22f 100644 --- a/constrictor/controller.py +++ b/constrictor/controller.py @@ -71,7 +71,7 @@ class Controller(object): def reset(self): ''' Creates a new stream parser and flags this object as not being connected to the remote node ''' - logInfo("Resetting controller connection") + log_info("Resetting controller connection") self.parser = make_parser() self.parser.setContentHandler(CommandParser(self)) self.connected = False @@ -84,7 +84,7 @@ class Controller(object): v = re.compile("'").sub('"', str(v)) # change ' to " to prevent xml attr breaking.. s += " %s='%s'" % (saxutils.escape(k), saxutils.escape(v)) s += '/>' - logDebug('Sending ' + s) + log_debug('Sending ' + s) self.remote.send(s) @@ -99,7 +99,7 @@ class Controller(object): if self.remote is None: # we're acting as a server process, waiting for a connection self.remote = self.socket.accept() - logInfo('Controller connection from %s' % str(self.remote.remoteAddress)) + log_info('Controller connection from %s' % str(self.remote.remoteAddress)) try: data = self.remote.recv() @@ -135,7 +135,7 @@ class Controller(object): if self.remote is None: # we're acting as a server process, waiting for a connection self.remote, address = self.socket.accept() - logInfo('Controller connection from %s' % str(address)) + log_info('Controller connection from %s' % str(address)) try: data = self.remote.recv(READSIZE) @@ -145,7 +145,7 @@ class Controller(object): self.reset() continue - logDebug("Read %s" % data) + log_debug("Read %s" % data) self.parser.feed(data) self.remote.setblocking(0) @@ -216,13 +216,13 @@ class GUIController(Controller): except socket.error, e: err = _("Error connecting to %s:%s %s" % (self.address, self.port, str(e))) self.failed = err - logError(err) + log_error(err) return False except socket.timeout: err = _("Connection to %s:%s timed out" % (self.address, self.port)) self.failed = err - logError(err) + log_error(err) return False def __str__(self): @@ -259,7 +259,7 @@ class GUIControllerSet(object): try: rlist = select.select(rlist, [], [], timeout) except Exception, e: - logError("select() failed with " + str(e)) + log_error("select() failed with " + str(e)) return [] return [ c for c in self.controllers if c.socket in rlist[0] ] return [] @@ -340,7 +340,7 @@ class CommandParser(handler.ContentHandler): return p def startElement(self, name, attrs): - logDebug("Received %s %s" % (name, str([(k,v) for k,v in attrs.items()]))) + log_debug("Received %s %s" % (name, str([(k,v) for k,v in attrs.items()]))) if name == 'controlset': if not self.controller.connected: diff --git a/constrictor/data.py b/constrictor/data.py index 0724218fb..4c0435ef2 100644 --- a/constrictor/data.py +++ b/constrictor/data.py @@ -23,7 +23,7 @@ class Data(object): def __init__(self, db_file): if Data.singleton is None: - log.logInfo("sqlite:////%s" % db_file) + log.log_info("sqlite:////%s" % db_file) self.engine = create_engine('sqlite:////%s' % db_file) self.meta = MetaData() self.meta.bind = self.engine @@ -76,7 +76,7 @@ class Data(object): def store_data(self): - log.logInfo("Inserting data into data store...") + log.log_info("Inserting data into data store...") # close out the task set self.engine.execute( @@ -85,6 +85,7 @@ class Data(object): # insert all of the task data for task in self.runtime_data: + log.log_debug("Storing " + task['name']) self.engine.execute( self.task_table.insert().values( task_name = task['name'], diff --git a/constrictor/db.py b/constrictor/db.py index cb9f3b598..058cb7768 100644 --- a/constrictor/db.py +++ b/constrictor/db.py @@ -102,13 +102,13 @@ class DBConnection(object): if summary['num_task_success'] > 0: summary['amortized_tasks_per_second'] = 1.0 / float(summary['amortized_task_duration']) - props = Properties.getProperties() - summary['thread_count'] = props.getProperty('constrictor.numThreads') - summary['iteration_count'] = props.getProperty('constrictor.numIterations') + props = Properties.get_properties() + summary['thread_count'] = props.get_property('constrictor.numThreads') + summary['iteration_count'] = props.get_property('constrictor.numIterations') self.makeTaskTypeSummary(summary) - logInfo('created summary %s' % summary) + log_info('created summary %s' % summary) return summary def makeTaskTypeSummary(self, summary): @@ -150,7 +150,7 @@ class DBConnection(object): def execute(self, sql, commit=False): - logDebug('SQL ' + sql) + log_debug('SQL ' + sql) from script import ScriptThread cur = None try: @@ -160,7 +160,7 @@ class DBConnection(object): if commit: self.conn.commit() except Exception, e: - sys.stderr.write('DB error: thread = %d : %s\n' % (ScriptThread.getThreadID(), str(e))) + sys.stderr.write('DB error: thread = %d : %s\n' % (ScriptThread.get_thread_id(), str(e))) sys.stderr.flush() dbSema.release() sys.exit(1) @@ -177,7 +177,7 @@ class DBConnection(object): task.name, time.time(), 1, # XXX get me from the task runner ? - ScriptThread.getThreadID(), + ScriptThread.get_thread_id(), DBConnection.taskSetID, task.duration, task.success diff --git a/constrictor/log.py b/constrictor/log.py index edf8c62e0..6d94ef8e3 100644 --- a/constrictor/log.py +++ b/constrictor/log.py @@ -19,20 +19,20 @@ from properties import Properties import sys loglevel = 1 -def initLog(): +def init_log(): global loglevel - props = Properties.getProperties() - loglevel = int(props.getProperty('constrictor.loglevel') or 0) + props = Properties.get_properties() + loglevel = int(props.get_property('constrictor.loglevel') or 0) -def logError(msg=''): +def log_error(msg=''): if loglevel < 1: return sys.stderr.write('Error*: %s\n' % msg) sys.stderr.flush() -def logInfo(msg=''): +def log_info(msg=''): if loglevel < 2: return print 'Info: %s' % msg -def logDebug(msg=''): +def log_debug(msg=''): if loglevel < 3: return print 'Debug: %s' % msg diff --git a/constrictor/script.py b/constrictor/script.py index 0a23a94df..c690d9433 100644 --- a/constrictor/script.py +++ b/constrictor/script.py @@ -26,11 +26,11 @@ class Script(object): def __init__(self, name=''): self.name = name def run(self): - logError('Override Script.run() to run a script!') + log_error('Override Script.run() to run a script!') sys.exit(1) - def onThreadInit(self, scriptThread): + def on_thread_init(self, scriptThread): pass - def onThreadComplete(self, scriptThread): + def on_thread_complete(self, scriptThread): pass @@ -41,49 +41,49 @@ class ScriptThread(Thread): # this is used to determine the thread ID of newly created threads threadSeed = 0 - def __init__(self, script, numItr, onComplete=None ): + def __init__(self, script, numItr, on_complete=None ): Thread.__init__(self) - logDebug("Creating thread with ID %d" % ScriptThread.threadSeed) + log_debug("Creating thread with ID %d" % ScriptThread.threadSeed) self.script = script # our script object self.numItr = numItr # number of times to run our script self.setName(ScriptThread.threadSeed) # use the Thread name as our threadID - self.onComplete = onComplete + self.on_complete = on_complete ScriptThread.threadSeed += 1 self.userData = None - def resetThreadSeed(): + def reset_thread_seed(): ScriptThread.threadSeed = 0 - resetThreadSeed = staticmethod(resetThreadSeed) + reset_thread_seed = staticmethod(reset_thread_seed) def run(self): """ Run our script object up to numItr times.""" - self.initThread() - tid = ScriptThread.getThreadID() - self.script.onThreadInit(self) + self.init_thread() + tid = ScriptThread.get_thread_id() + self.script.on_thread_init(self) for i in range(0, self.numItr): - logInfo('running thread %d, iteration %d' % (tid, i)) + log_info('running thread %d, iteration %d' % (tid, i)) try: self.script.run() except Exception, e: traceback.print_exc() - logError("Script exception: %s" % str(e)) + log_error("Script exception: %s" % str(e)) break - self.script.onThreadComplete(self) + self.script.on_thread_complete(self) - if self.onComplete: - self.onComplete(self) + if self.on_complete: + self.on_complete(self) - def initThread(self): + def init_thread(self): """ Perform any thread-specific house keeping.""" - data = ScriptThread.__threadData() + data = ScriptThread.__thread_data() data.scriptThread = self - props = Properties.getProperties() + props = Properties.get_properties() - def getThreadID(): + def get_thread_id(): """ Returns the ID of the current thread. Returns -1 if this is the main thread """ @@ -93,21 +93,21 @@ class ScriptThread(Thread): except: pass return i - getThreadID = staticmethod(getThreadID) + get_thread_id = staticmethod(get_thread_id) - def currentScriptThread(): - data = ScriptThread.__threadData() + def current_script_thread(): + data = ScriptThread.__thread_data() return data.scriptThread - currentScriptThread = staticmethod(currentScriptThread) + current_script_thread = staticmethod(current_script_thread) - threadDataStore = None - def __threadData(): - if ScriptThread.threadDataStore is None: - ScriptThread.threadDataStore = threading.local() - return ScriptThread.threadDataStore - __threadData = staticmethod(__threadData) + thread_dataStore = None + def __thread_data(): + if ScriptThread.thread_dataStore is None: + ScriptThread.thread_dataStore = threading.local() + return ScriptThread.thread_dataStore + __thread_data = staticmethod(__thread_data) class ScriptManager(object): @@ -126,43 +126,43 @@ class ScriptManager(object): self.numComplete = 0 if self.script is None: - logError('Please register a script to run') + log_error('Please register a script to run') sys.exit(1) - def setOnThreadsComplete(func): + def set_on_threads_complete(func): ScriptManager.onThreadsComplete = staticmethod(func) - setOnThreadsComplete = staticmethod(setOnThreadsComplete) + set_on_threads_complete = staticmethod(set_on_threads_complete) - def runScriptThreads(self): + def run_script_threads(self): - def onComplete(scriptThread): + def on_complete(scriptThread): self.numComplete += 1 if self.numComplete == self.numThreads: # all threads have completed constrictor.data.Data.get_instance().store_data() - logInfo('all threads done.. finishing task set') + log_info('all threads done.. finishing task set') if ScriptManager.onThreadsComplete: ScriptManager.onThreadsComplete(ScriptManager) """ Launches the script threads. """ for i in range(0, self.numThreads): - tt = ScriptThread(self.script, self.numItr, onComplete) + tt = ScriptThread(self.script, self.numItr, on_complete) tt.start() def go(script): """ The main script passes control to the ScriptManager via this function. Here, we parse the config and launch the script threads """ - props = Properties.getProperties() + props = Properties.get_properties() - threads = int(props.getProperty('constrictor.numThreads')) - itrs = int(props.getProperty('constrictor.numIterations')) + threads = int(props.get_property('constrictor.numThreads')) + itrs = int(props.get_property('constrictor.numIterations')) - logDebug('launching %d threads with %d iterations' % (threads, itrs)) + log_debug('launching %d threads with %d iterations' % (threads, itrs)) manager = ScriptManager(script, threads, itrs) - manager.runScriptThreads() + manager.run_script_threads() go = staticmethod(go) diff --git a/constrictor/task.py b/constrictor/task.py index 98dd2cb4e..e7a3276e5 100644 --- a/constrictor/task.py +++ b/constrictor/task.py @@ -41,7 +41,7 @@ class Task(object): def run(self, **kwargs): """Override this method with the work to perform""" - logError('Override me!') + log_error('Override me!') def start(self, **kwargs): @@ -59,8 +59,8 @@ class Task(object): sys.stderr.write(str(E)) # store the error info somewhere? - logDebug('%s: thread = %d : duration = %f' % ( - self.name, ScriptThread.getThreadID(), self.duration)) + log_debug('%s: thread = %d : duration = %f' % ( + self.name, ScriptThread.get_thread_id(), self.duration)) sys.stdout.flush() constrictor.data.Data.get_instance().add_task(self) @@ -72,7 +72,7 @@ class Task(object): 'duration' : self.duration, 'success' : self.success, 'run_time' : self.run_time, - 'thread_id' : ScriptThread.getThreadID() + 'thread_id' : ScriptThread.get_thread_id() } diff --git a/constrictor/utils.py b/constrictor/utils.py index 07f860aa1..54c048d2c 100755 --- a/constrictor/utils.py +++ b/constrictor/utils.py @@ -25,12 +25,12 @@ PROPS_FILENAME = 'constrictor.properties' props = Properties() -def loadProps(file=PROPS_FILENAME): +def load_props(file=PROPS_FILENAME): try: # parse the properties file p = open(file) - Properties.setGlobalProperties(props) + Properties.set_global_properties(props) props.load(p) p.close() except IOError: @@ -39,7 +39,7 @@ def loadProps(file=PROPS_FILENAME): Using command line options only. ''' -def saveProps(): +def save_props(): try: p = open(PROPS_FILENAME, 'w') props.store(p) @@ -48,23 +48,23 @@ def saveProps(): print "WARNING: Unable to store properties to file\n%s" % str(e) -def initDB(): +def init_db(): ''' connect to the db and make sure the tables exist ''' data = constrictor.data.Data( - os.path.join(os.getcwd(), props.getProperty('constrictor.dbFile')) + os.path.join(os.getcwd(), props.get_property('constrictor.dbFile')) ) data.create_schema() data.create_task_set() data.disconnect() -def initDirs(): - cachedir = props.getProperty('constrictor.cacheDir') +def init_dirs(): + cachedir = props.get_property('constrictor.cacheDir') if not os.path.exists(cachedir): - os.mkdir(props.getProperty('constrictor.cacheDir')) + os.mkdir(props.get_property('constrictor.cacheDir')) pathsAdded = [] -def openScript(dirs, script): +def open_script(dirs, script): ''' Finds the script file in the set of script diretories, opens the file and returns the file object ''' f = None @@ -81,7 +81,7 @@ def openScript(dirs, script): return f except IOError: pass - logError("Unable to find script %s in path %s" % (script, str(dirs))) + log_error("Unable to find script %s in path %s" % (script, str(dirs))) return None diff --git a/constrictor_gui/control/views.py b/constrictor_gui/control/views.py index 55d7d7f1d..6b2ee287c 100644 --- a/constrictor_gui/control/views.py +++ b/constrictor_gui/control/views.py @@ -181,12 +181,12 @@ def setProps(request): return render_to_response(SET_PROP_TEMPLATE, makeContext('Set Properties')) setProps = staff_member_required(never_cache(setProps)) -def saveProps(request): +def save_props(request): __init() controllerSet.broadcastCommand(action='saveprops') return render_to_response(SET_PROP_TEMPLATE, makeContext('Set Properties')) -saveProps = staff_member_required(never_cache(saveProps)) +save_props = staff_member_required(never_cache(save_props)) diff --git a/constrictor_gui/urls.py b/constrictor_gui/urls.py index 6f1db140b..88d471096 100644 --- a/constrictor_gui/urls.py +++ b/constrictor_gui/urls.py @@ -12,6 +12,6 @@ urlpatterns = patterns('', # (r'^control/setScript/$', 'constrictor_gui.control.views.setScript'), (r'^control/updateBasicProps/$', 'constrictor_gui.control.views.updateBasicProps'), (r'^control/setProps/$', 'constrictor_gui.control.views.setProps'), - (r'^control/saveProps/$', 'constrictor_gui.control.views.saveProps'), + (r'^control/save_props/$', 'constrictor_gui.control.views.save_props'), (r'^admin/', include('django.contrib.admin.urls')), ) diff --git a/contrib/evergreen/eg_bib_search.py b/contrib/evergreen/eg_bib_search.py index 2ec0e374a..d7e6b0953 100644 --- a/contrib/evergreen/eg_bib_search.py +++ b/contrib/evergreen/eg_bib_search.py @@ -18,14 +18,14 @@ class BibSearchScript(Script): } 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))) + log_info('Search term="%s" args="%s"' % (search_term, str(search_args))) res = eg_tasks.BibSearchTask().start( search_args = search_args, search_term = search_term ) - logInfo('Search returned %d hits' % int(res['count'])) + log_info('Search returned %d hits' % int(res['count'])) return True eg_utils.init() diff --git a/contrib/evergreen/eg_checkin.py b/contrib/evergreen/eg_checkin.py index 95ae5dec3..fc5ff1560 100644 --- a/contrib/evergreen/eg_checkin.py +++ b/contrib/evergreen/eg_checkin.py @@ -7,8 +7,8 @@ eg_utils.init() class CheckinScript(Script): - def onThreadInit(self, scriptThread): - eg_utils.initThread() + def on_thread_init(self, scriptThread): + eg_utils.init_thread() def run(self): diff --git a/contrib/evergreen/eg_checkout.py b/contrib/evergreen/eg_checkout.py index 54363a5dd..0664078a2 100644 --- a/contrib/evergreen/eg_checkout.py +++ b/contrib/evergreen/eg_checkout.py @@ -10,8 +10,8 @@ eg_utils.init() class CheckoutScript(Script): - def onThreadInit(self, scriptThread): - eg_utils.initThread() + def on_thread_init(self, scriptThread): + eg_utils.init_thread() def run(self): diff --git a/contrib/evergreen/eg_checkout_roundtrip.py b/contrib/evergreen/eg_checkout_roundtrip.py index d4dbb4687..3e376c5f6 100644 --- a/contrib/evergreen/eg_checkout_roundtrip.py +++ b/contrib/evergreen/eg_checkout_roundtrip.py @@ -10,8 +10,8 @@ eg_utils.init() class CheckoutRoundtripScript(Script): - def onThreadInit(self, scriptThread): - eg_utils.initThread() + def on_thread_init(self, scriptThread): + eg_utils.init_thread() def run(self): diff --git a/contrib/evergreen/eg_data.py b/contrib/evergreen/eg_data.py index bb7770f25..17dbe977d 100644 --- a/contrib/evergreen/eg_data.py +++ b/contrib/evergreen/eg_data.py @@ -22,9 +22,9 @@ class DataManager(object): def __init__(self): self.data = {} - self.props = Properties.getProperties() + self.props = Properties.get_properties() self.readProps() - logDebug(self) + log_debug(self) def __str__(self): s = 'DataManager() read properties:\n' @@ -52,11 +52,11 @@ class DataManager(object): self.readProp(PROP_ORG_IDS, True) def readProp(self, prop, split=False): - v = self.props.getProperty(prop) + v = self.props.get_property(prop) if split and v: v = unique(v.split(',')) self.data[prop] = v - logDebug("DataManager set property %s => %s" % (prop, str(v))) + log_debug("DataManager set property %s => %s" % (prop, str(v))) def getThreadData(self, prop, noSharing=False): ''' If the caller is requesting array-based data, we want to de-multiplex(?) @@ -72,8 +72,8 @@ class DataManager(object): if not isinstance(data, list): return data - currentThread = ScriptThread.getThreadID() - totalThreads = self.props.getProperty(PROP_CONSTRICTOR_THREADS) + currentThread = ScriptThread.get_thread_id() + totalThreads = self.props.get_property(PROP_CONSTRICTOR_THREADS) if len(data) > currentThread: return data[currentThread] diff --git a/contrib/evergreen/eg_fetch_user_groups.py b/contrib/evergreen/eg_fetch_user_groups.py index 98fd68d30..fc283b482 100644 --- a/contrib/evergreen/eg_fetch_user_groups.py +++ b/contrib/evergreen/eg_fetch_user_groups.py @@ -18,7 +18,7 @@ class FetchUserGroupsTask(Task): class FetchUserGroupsScript(Script): def run(self): res = FetchUserGroupsTask().start() - logInfo('Fetched group tree with root "%s"' % res.name()) + log_info('Fetched group tree with root "%s"' % res.name()) return True eg_utils.init() diff --git a/contrib/evergreen/eg_renew.py b/contrib/evergreen/eg_renew.py index ce3c3d929..b96a20455 100644 --- a/contrib/evergreen/eg_renew.py +++ b/contrib/evergreen/eg_renew.py @@ -10,8 +10,8 @@ eg_utils.init() class RenewScript(Script): - def onThreadInit(self, scriptThread): - eg_utils.initThread() + def on_thread_init(self, scriptThread): + eg_utils.init_thread() def run(self): diff --git a/contrib/evergreen/eg_title_hold.py b/contrib/evergreen/eg_title_hold.py index 5ac5e1f44..e11fc88cc 100644 --- a/contrib/evergreen/eg_title_hold.py +++ b/contrib/evergreen/eg_title_hold.py @@ -8,10 +8,10 @@ eg_utils.init() class CreateTitleHoldScript(Script): - def onThreadInit(self, scriptThread): + def on_thread_init(self, scriptThread): # collect all of the holds the current thread user already has # so any new holds can be cancelled after the thread is complete - eg_utils.initThread() + eg_utils.init_thread() dm = DataManager() patronID = dm.getThreadData(PROP_PATRON_IDS) diff --git a/contrib/evergreen/eg_user_search.py b/contrib/evergreen/eg_user_search.py index 3c91afe02..ad946e22d 100644 --- a/contrib/evergreen/eg_user_search.py +++ b/contrib/evergreen/eg_user_search.py @@ -17,12 +17,12 @@ class UserSearchScript(Script): 'first_given_name' : {'value' : eg_utils.random_phrase(1), 'group' : 0} } - logInfo('Search for patron %s' % str(search_args)) + log_info('Search for patron %s' % str(search_args)) try: res = eg_tasks.UserSearchTask().start(search_args = search_args) - logInfo('Search returned %d hits' % len(res)) + log_info('Search returned %d hits' % len(res)) except Exception, e: logErrror(e) diff --git a/contrib/evergreen/eg_user_transactions.py b/contrib/evergreen/eg_user_transactions.py index 889571e91..5a7011f57 100644 --- a/contrib/evergreen/eg_user_transactions.py +++ b/contrib/evergreen/eg_user_transactions.py @@ -28,7 +28,7 @@ class BibSearchScript(Script): user_id = dm.getThreadData(eg_data.PROP_PATRON_IDS) for type in types: - logInfo('Loading patron(%s) transactions with %s' % (int(user_id), type)) + log_info('Loading patron(%s) transactions with %s' % (int(user_id), type)) res = eg_tasks.UserTransactionsByType().start( method = type, user_id = user_id diff --git a/contrib/evergreen/eg_utils.py b/contrib/evergreen/eg_utils.py index 6097647e4..fb97659a9 100644 --- a/contrib/evergreen/eg_utils.py +++ b/contrib/evergreen/eg_utils.py @@ -9,7 +9,7 @@ from oils.event import Event from oils.const import * import os, errno, random -props = Properties.getProperties() +props = Properties.get_properties() words = [] default_dictionary = '/usr/share/dict/words' @@ -19,33 +19,33 @@ def init(): loadIDL() initOsrf() - if props.getProperty('evergreen.autologin') == 'true': + if props.get_property('evergreen.autologin') == 'true': login( - props.getProperty('evergreen.username'), - props.getProperty('evergreen.password'), - props.getProperty('evergreen.workstation')) + props.get_property('evergreen.username'), + props.get_property('evergreen.password'), + props.get_property('evergreen.workstation')) user = None - if not props.getProperty('evergreen.patronIDs'): + if not props.get_property('evergreen.patronIDs'): # if there are not configured patron IDs, go ahead # and use the ID of the logged in user user = fetchSessionUser() - logInfo("Setting evergreen.patronIDs to logged in user %s" % str(user.id())) - props.setProperty('evergreen.patronIDs', str(user.id())) + log_info("Setting evergreen.patronIDs to logged in user %s" % str(user.id())) + props.set_property('evergreen.patronIDs', str(user.id())) - if not props.getProperty('evergreen.orgIDs'): + if not props.get_property('evergreen.orgIDs'): # simlilarly, if no org is provided, use the home org of the logged in user if not user: user = fetchSessionUser() - logInfo("Setting evergreen.orgIDs to logged in user's home_ou %s" % str(user.home_ou())) - props.setProperty('evergreen.orgIDs', str(user.home_ou())) + log_info("Setting evergreen.orgIDs to logged in user's home_ou %s" % str(user.home_ou())) + props.set_property('evergreen.orgIDs', str(user.home_ou())) - dict_file = props.getProperty('evergreen.dictionary') or default_dictionary + dict_file = props.get_property('evergreen.dictionary') or default_dictionary try: words_file = open(dict_file) except Exception: - logError("Unable to open dictionary file '%s'" % dict_file) + log_error("Unable to open dictionary file '%s'" % dict_file) return words = words_file.readlines() @@ -54,16 +54,16 @@ def init(): def initOsrf(): # if necessary, create a connection to the opensrf network for this thread - if str(props.getProperty('evergreen.netProtocol')).lower() == 'jabber': - if props.getProperty('evergreen.osrfConfig'): - logInfo("Connecting to the opensrf network") + if str(props.get_property('evergreen.netProtocol')).lower() == 'jabber': + if props.get_property('evergreen.osrfConfig'): + log_info("Connecting to the opensrf network") from osrf.system import osrfConnect osrfConnect( - props.getProperty('evergreen.osrfConfig'), - props.getProperty('evergreen.osrfConfigContext')) + props.get_property('evergreen.osrfConfig'), + props.get_property('evergreen.osrfConfigContext')) -def initThread(): +def init_thread(): ''' Performs thread-specific initialization ''' initOsrf() @@ -71,15 +71,15 @@ def fetchSessionUser(): user = request('open-ils.auth', 'open-ils.auth.session.retrieve', authtoken()).send() if Event.parse_event(user): raise ILSEventException(osrf.json.to_json(user)) - logInfo("fetched user %s" % user.usrname()) + log_info("fetched user %s" % user.usrname()) return user def loadIDL(): # XX add logic to allow IDL fetching via jabber - server = props.getProperty('evergreen.server') - cacheDir = props.getProperty('constrictor.cacheDir') + server = props.get_property('evergreen.server') + cacheDir = props.get_property('constrictor.cacheDir') GatewayRequest.setDefaultHost(server) import urllib2 @@ -92,8 +92,8 @@ def loadIDL(): file = open(filePath, 'r') except IOError: - logInfo('fetching: http://%s/%s' % (server, props.getProperty('evergreen.IDLPath'))) - f = urllib2.urlopen('http://%s/%s' % (server, props.getProperty('evergreen.IDLPath'))) + log_info('fetching: http://%s/%s' % (server, props.get_property('evergreen.IDLPath'))) + f = urllib2.urlopen('http://%s/%s' % (server, props.get_property('evergreen.IDLPath'))) if not os.path.exists('%s/evergreen' % cacheDir): os.mkdir('%s/evergreen' % cacheDir) @@ -102,7 +102,7 @@ def loadIDL(): file.write(f.read()) file.close() - logInfo("parsing Evergreen IDL file...") + log_info("parsing Evergreen IDL file...") parser.set_IDL(filePath) parser.parse_IDL() @@ -124,7 +124,7 @@ class AtomicReqWrapper(object): def request(service, method, *args): global props - proto = props.getProperty('evergreen.netProtocol') + proto = props.get_property('evergreen.netProtocol') if str(proto).lower() == 'jabber': req = AtomicReqWrapper(service, method, *args) else: @@ -132,7 +132,7 @@ def request(service, method, *args): req = JSONGatewayRequest(service, method, *args) else: req = XMLGatewayRequest(service, method, *args) - req.setPath(props.getProperty('evergreen.gatewayPath')) + req.setPath(props.get_property('evergreen.gatewayPath')) return req @@ -146,7 +146,7 @@ def login(username, password, workstation=None): ''' Login to the server and get back an authtoken''' global __authtoken - logInfo("attempting login with user " + username) + log_info("attempting login with user " + username) seed = request( 'open-ils.auth', diff --git a/contrib/evergreen/eg_workflow.py b/contrib/evergreen/eg_workflow.py index 805bd5dd8..c79519778 100644 --- a/contrib/evergreen/eg_workflow.py +++ b/contrib/evergreen/eg_workflow.py @@ -14,7 +14,7 @@ def doCheckout(copyBarcode, patronID, recurse=False): evt = eg_tasks.CheckoutTask().start( copy_barcode=copyBarcode, patron_id=patronID) evt_txt = Event.parse_event(evt).text_code - logInfo("Checkout(%s,%s) -> %s" % (copyBarcode, patronID, evt_txt)) + log_info("Checkout(%s,%s) -> %s" % (copyBarcode, patronID, evt_txt)) if evt_txt == OILS_EVENT_SUCCESS: return evt @@ -25,7 +25,7 @@ def doCheckout(copyBarcode, patronID, recurse=False): evt = doCheckin(copyBarcode) if evt_txt == OILS_EVENT_SUCCESS: return doCheckout(copyBarcode, patronID, True) - logInfo("* Unable to checkin open circ: %s" % copyBarcode) + log_info("* Unable to checkin open circ: %s" % copyBarcode) return None @@ -34,7 +34,7 @@ def doRenew(copyBarcode): evt = eg_tasks.RenewTask().start(copy_barcode=copyBarcode) evt_txt = Event.parse_event(evt).text_code - logInfo("Renew(%s) -> %s" % (copyBarcode, evt_txt)) + log_info("Renew(%s) -> %s" % (copyBarcode, evt_txt)) if evt_txt == OILS_EVENT_SUCCESS: return evt @@ -47,18 +47,18 @@ def doCheckin(copyBarcode): evt = eg_tasks.CheckinTask().start(copy_barcode=copyBarcode) evt_txt = Event.parse_event(evt).text_code - logInfo("Checkin(%s) -> %s" % (copyBarcode, evt_txt)) + log_info("Checkin(%s) -> %s" % (copyBarcode, evt_txt)) if evt_txt == OILS_EVENT_SUCCESS or evt_txt == 'NO_CHANGE': return SUCCESS if evt_txt == 'ROUTE_ITEM': - logInfo("Cancelling post-checkin transit...") + log_info("Cancelling post-checkin transit...") res = eg_tasks.AbortTransitTask().start(copy_barcode=copyBarcode) if Event.parse_event(res): # transit returns "1" on success - logError("Unable to abort transit for %s : %s" % (copyBarcode, osrf.json.to_json(evt))) + log_error("Unable to abort transit for %s : %s" % (copyBarcode, osrf.json.to_json(evt))) return None return SUCCESS @@ -78,11 +78,11 @@ def doTitleHoldPermit(titleID, patronID, pickupLib): titleID, patronID, pickupLib, osrf.json.to_json(evt))) if str(evt['success']) != '1': - logInfo("TitleHoldPermit(%s, %s, %s) not allowed -> %s" % ( + log_info("TitleHoldPermit(%s, %s, %s) not allowed -> %s" % ( titleID, patronID, pickupLib, evt)) return None - logInfo('TitleHoldPermit(%s, %s, %s) -> SUCCESS' % (titleID, patronID, pickupLib)) + log_info('TitleHoldPermit(%s, %s, %s) -> SUCCESS' % (titleID, patronID, pickupLib)) return True @@ -93,25 +93,25 @@ def doTitleHold(titleID, patronID, pickupLib): evt = et_tasks.TitleHoldTask().start(title_id=titleID, patron_id=patronID, pickup_lib=pickupLib) - logInfo("title task returned %s" % str(evt)) + log_info("title task returned %s" % str(evt)) if isinstance(evt, list): evts = [] for e in evt: evts.append(e['text_code']) - logInfo("TitleHold(%s, %s, %s) -> %s" % (titleID, patronID, pickupLib, str(evts))) + log_info("TitleHold(%s, %s, %s) -> %s" % (titleID, patronID, pickupLib, str(evts))) return None if Event.parse_event(evt): - logInfo("TitleHold(%s, %s, %s) -> %s" % (titleID, patronID, pickupLib, Event.parse_event(evt).code)) + log_info("TitleHold(%s, %s, %s) -> %s" % (titleID, patronID, pickupLib, Event.parse_event(evt).code)) return None if str(evt) == '-1': - logInfo("TitleHold(%s, %s, %s) placement failed: %s" % ( + log_info("TitleHold(%s, %s, %s) placement failed: %s" % ( titleID, patronID, pickupLib, str(evt))) return None - logInfo('TitleHold(%s, %s, %s) -> SUCCESS' % (titleID, patronID, pickupLib)) + log_info('TitleHold(%s, %s, %s) -> SUCCESS' % (titleID, patronID, pickupLib)) return int(evt) # new hold ID def doTitleHoldCancel(holdID): @@ -125,7 +125,7 @@ def doTitleHoldCancel(holdID): raise ILSEventException( "TitleHoldCancel(%s) failed -> %s" % (holdID, str(evt))) - logInfo('TitleHoldCancel(%s) -> SUCCESS' % holdID) + log_info('TitleHoldCancel(%s) -> SUCCESS' % holdID) return True def doTitleHoldFetchAll(patronID): diff --git a/deploy.py b/deploy.py index e1476142e..0682a2cac 100755 --- a/deploy.py +++ b/deploy.py @@ -21,7 +21,7 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'constrictor_gui.settings' from django.contrib.auth.models import User from constrictor_gui.control.models import Drone, Script, Plugin, Property -from constrictor.utils import loadProps +from constrictor.utils import load_props import constrictor_gui.settings as settings from constrictor.log import * import xml.dom.minidom @@ -73,8 +73,8 @@ def getXMLAttr(node, name, ns=None): def loadModuleConfigs(): ''' Returns the DOM nodes for the XML configs if a config is found ''' - props = constrictor.properties.Properties.getProperties() - scriptDirs = props.getProperty('constrictor.scriptDirs').split(',') + props = constrictor.properties.Properties.get_properties() + scriptDirs = props.get_property('constrictor.scriptDirs').split(',') configs = [] for d in scriptDirs: conf = None @@ -149,7 +149,7 @@ def updateDjangoProperties(plugin, conf): -loadProps('consctrictor.properties') +load_props('consctrictor.properties') basedir = os.getcwd() os.chdir('constrictor_gui') os.environ['PYTHONPATH'] = os.path.join(os.path.abspath(''), '..') -- 2.11.0