From 27c0e7a8731ca390a9c2d1d5127deb3ff26bd23b Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Mon, 4 Jun 2007 17:33:31 +0000 Subject: [PATCH] Really basic proof-of-concept scripthandler.py for review and discussion. This should illustrate my basic idea about script support. I think this will be a very elegant solution to the scripting situation. This will be filled out in the coming days and will hopefully make more and more sense as I tie it in. Database changes are likely, make sure to keep an eye on the commit logs. Also edited some svn:ignore props and added a placeholder for the basicobject script. --- scripthandler.py | 35 +++++++++++++++++++++++++++++++++++ scripts/basicobject.py | 5 +++++ 2 files changed, 40 insertions(+) create mode 100644 scripthandler.py create mode 100644 scripts/basicobject.py diff --git a/scripthandler.py b/scripthandler.py new file mode 100644 index 0000000000..59c93420f2 --- /dev/null +++ b/scripthandler.py @@ -0,0 +1,35 @@ +""" +This module is responsible for managing scripts and their connection to the +Object class model. It is important to keep this as independent from the +codebase as possible in order to allow for drop-in replacements. All +interaction with actual script methods should happen via calls to Objects. +""" + +# A dictionary with keys equivalent to the script's name and values that +# contain references to the associated module for each key. +cached_scripts = {} + +def scriptlink(scriptname): + """ + Each Object will refer to this function when trying to execute a function + contained within a scripted module. For the sake of ease of management, + modules are cached and compiled as they are requested and stored in + the cached_scripts dictionary. + """ + # The module is already cached, just return it rather than re-load. + retval = cached_scripts.get('scripts.%s' % (scriptname), False) + if retval: + return retval + + modname = 'scripts.%s' % (scriptname) + print 'Caching script module %s.' % (modname) + + try: + modreference = __import__(modname) + cached_scripts[modname] = modreference + except ImportError: + print 'Error importing %s.' % (modname) + return + + # The new script module has been cached, return the reference. + return modreference \ No newline at end of file diff --git a/scripts/basicobject.py b/scripts/basicobject.py new file mode 100644 index 0000000000..2d0a4632fc --- /dev/null +++ b/scripts/basicobject.py @@ -0,0 +1,5 @@ +""" +This will be the base object type/interface that all scripts are derived from by +default. It will have the necessary outline for developers to sub-class and override. +""" +test = 123