diff --git a/apps/objects/models.py b/apps/objects/models.py index 1fc332b30..416120c2d 100755 --- a/apps/objects/models.py +++ b/apps/objects/models.py @@ -646,7 +646,7 @@ class Object(models.Model): """ if not self.scriptlink: if self.is_player(): - script_to_load = 'player/basicplayer' + script_to_load = 'player.basicplayer' else: script_to_load = 'basicobject' self.scriptlink = scripthandler.scriptlink(self, self.get_attribute_value('__parent', script_to_load)) diff --git a/src/scripthandler.py b/src/scripthandler.py index 04647f77b..0eeeb60fd 100644 --- a/src/scripthandler.py +++ b/src/scripthandler.py @@ -40,19 +40,13 @@ def scriptlink(source_obj, scriptname): # to change to. I really wish we didn't have to do this, but there's some # strange issue with __import__ and more than two directories worth of # nesting. - #path_split = scriptname.split('.') - #newpath_str = '/'.join(path_split[:-1]) - # Lop the module name off the end. - #modname = path_split[-1] - path_split = scriptname.split('/') - script_name = path_split[-1] - script_path = '/'.join(path_split[:-1]) + full_script = "src.scripts.%s" % (scriptname,) + script_name = full_script.split('.')[-1] try: # Change the working directory to the location of the script and import. - os.chdir('%s/%s/' % (settings.SCRIPT_ROOT, script_path)) - logger.log_infomsg("SCRIPT: Caching and importing %s." % (script_name)) - modreference = __import__(script_name) + logger.log_infomsg("SCRIPT: Caching and importing %s." % (scriptname)) + modreference = __import__(full_script, fromlist=[script_name]) # Store the module reference for later fast retrieval. cached_scripts[scriptname] = modreference except ImportError: @@ -64,8 +58,5 @@ def scriptlink(source_obj, scriptname): os.chdir(settings.BASE_PATH) return - # Change back to the original working directory. - os.chdir(settings.BASE_PATH) - # The new script module has been cached, return the reference. return modreference.class_factory(source_obj)