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.

This commit is contained in:
Greg Taylor 2007-06-04 17:33:31 +00:00
parent e6d7c51771
commit 27c0e7a873
2 changed files with 40 additions and 0 deletions

35
scripthandler.py Normal file
View file

@ -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

5
scripts/basicobject.py Normal file
View file

@ -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