Fixed a bunch of small issues. The RedButton example hasn't been working for a while, should be ok again now - also cleaned it up a bit.

This commit is contained in:
Griatch 2011-06-24 20:12:59 +00:00
parent 1d93d8295f
commit 334c0b1d08
10 changed files with 87 additions and 94 deletions

View file

@ -278,13 +278,11 @@ class CmdSetHandler(object):
def add_default(self, cmdset, emit_to_obj=None, permanent=True):
"""
Add a new default cmdset. If an old default existed,
it is replaced. If permanent is set, a script will be created to
add the cmdset to the object.
it is replaced. If permanent is set, the set will survive a reboot.
cmdset - can be a cmdset object or the python path to
an instance of such an object.
emit_to_obj - an object to receive error messages.
permanent - create a script that assigns this script every
startup/login.
permanent - save cmdset across reboots
See also the notes for self.add(), which applies here too.
"""
if callable(cmdset):

View file

@ -181,7 +181,7 @@ class CmdBatchCommands(MuxCommand):
Build from batch-command file
Usage:
@batchcommands[/interactive] <python path to file>
@batchcommands[/interactive] <python.path.to.file>
Switch:
interactive - this mode will offer more control when

View file

@ -361,7 +361,8 @@ def holds(accessing_obj, accessed_obj, objid, *args, **kwargs):
if dbref and any((True for obj in contains if obj.id == dbref)):
return True
objid = objid.lower()
return any((True for obj in contains if obj.name.lower() == objid))
return any((True for obj in contains
if obj.name.lower() == objid or objid in [al.lower() for al in obj.aliases]))
def carried(accessing_obj, accessed_obj):
"""
@ -379,8 +380,8 @@ def objcarried(accessing_obj, accessed_obj):
objcarried()
Like carried, except this lock looks for a property "obj" on the accessed_obj
and tries to determing if *this* is carried by accessing_obj. This works well
for commands and scripts.
and tries to determine if *this* is carried by accessing_obj. This works well
for accessing commands and scripts.
"""
return hasattr(accessed_obj, "obj") and accessed_obj.obj and \
hasattr(accessed_obj.obj, "location") and accessed_obj.obj.location == accessing_obj

View file

@ -175,9 +175,9 @@ CMDSET_OOC = "game.gamesrc.commands.basecmdset.OOCCmdSet"
# Base paths for typeclassed object classes. These paths must be
# defined relative evennia's root directory. They will be searched in
# order to find relative typeclass paths.
OBJECT_TYPECLASS_PATHS = ["game.gamesrc.objects", "game.gamesrc.objects.examples"]
SCRIPT_TYPECLASS_PATHS = ["game.gamesrc.scripts", "game.gamesrc.scripts.examples"]
PLAYER_TYPECLASS_PATHS = ["game.gamesrc.objects"]
OBJECT_TYPECLASS_PATHS = ["game.gamesrc.objects", "game.gamesrc.objects.examples", "contrib"]
SCRIPT_TYPECLASS_PATHS = ["game.gamesrc.scripts", "game.gamesrc.scripts.examples", "contrib"]
PLAYER_TYPECLASS_PATHS = ["game.gamesrc.objects", "contrib"]
# Typeclass for player objects (linked to a character) (fallback)
BASE_PLAYER_TYPECLASS = "game.gamesrc.objects.baseobjects.Player"
@ -196,7 +196,7 @@ BASE_EXIT_TYPECLASS = "game.gamesrc.objects.baseobjects.Exit"
# Python path to a directory to be searched for batch scripts
# for the batch processors (.ev and/or .py files).
BASE_BATCHPROCESS_PATH = 'game.gamesrc.world'
BASE_BATCHPROCESS_PATHS = ['game.gamesrc.world', 'contrib']
###################################################
# Game Time setup

View file

@ -22,6 +22,7 @@ these to create custom managers.
"""
import sys
try:
import cPickle as pickle
except ImportError:
@ -664,6 +665,7 @@ class TypedObject(SharedMemoryModel):
typeclass = object.__getattribute__(self, "_path_import")(tpath)
if callable(typeclass):
# don't return yet, we must cache this further down.
errstring = ""
break
elif hasattr(typeclass, '__file__'):
errstring += "\n%s seems to be just the path to a module. You need" % tpath
@ -674,7 +676,7 @@ class TypedObject(SharedMemoryModel):
if not callable(typeclass):
# Still not a valid import. Fallback to default.
defpath = object.__getattribute__(self, "default_typeclass_path")
errstring += " Using Default class '%s'." % defpath
errstring += "\n\nUsing Default class '%s'." % defpath
self.db_typeclass_path = defpath
self.save()
logger.log_errmsg(errstring)
@ -716,16 +718,22 @@ class TypedObject(SharedMemoryModel):
try:
modpath, class_name = path.rsplit('.', 1)
module = __import__(modpath, fromlist=[class_name])
return module.__dict__[class_name]
except ImportError:
trc = traceback.format_exc()
errstring = "\n%s\nError importing '%s'." % (trc, path)
return module.__dict__[class_name]
except ImportError:
trc = sys.exc_traceback
if not trc.tb_next:
# we separate between not finding the module, and finding a buggy one.
errstring += "(Tried path '%s')." % path
else:
# a bug in the module is reported normally.
trc = traceback.format_exc()
errstring += "\n%sError importing '%s'." % (trc, path)
except KeyError:
errstring = "No class '%s' was found in module '%s'."
errstring = errstring % (class_name, modpath)
except Exception:
trc = traceback.format_exc()
errstring = "\n%s\nImporting '%s' failed." % (trc, path)
errstring = "\n%sException importing '%s'." % (trc, path)
# return the error.
return errstring

View file

@ -163,29 +163,30 @@ def read_batchfile(pythonpath, file_ending='.py'):
"""
# open the file
if pythonpath and not (pythonpath.startswith('src.') or
pythonpath.startswith('game.')):
pythonpath = "%s.%s" % (settings.BASE_BATCHPROCESS_PATH,
pythonpath)
abspath = utils.pypath_to_realpath(pythonpath, file_ending)
if pythonpath and not (pythonpath.startswith('src.') or pythonpath.startswith('game.')):
abspaths = []
for basepath in settings.BASE_BATCHPROCESS_PATHS:
abspaths.append(utils.pypath_to_realpath("%s.%s" % (basepath, pythonpath), file_ending))
else:
abspaths = [pythonpath]
fobj = None
for file_encoding in ENCODINGS:
# try different encodings, in order
err = None
try:
# we read the file directly into unicode.
fobj = codecs.open(abspath, 'r', encoding=file_encoding)
except IOError:
# try again without the appended file ending
abspath2 = utils.pypath_to_realpath(pythonpath, None)
try:
load_errors = []
for abspath in abspaths:
# try different paths, until we get a match
try:
# we read the file directly into unicode.
fobj = codecs.open(abspath, 'r', encoding=file_encoding)
except IOError:
string = "Could not open batchfile '%s', nor '%s'."
logger.log_errmsg(string % (abspath2, abspath))
return None
except IOError:
load_errors.append("Could not open batchfile '%s'." % abspath)
continue
break
if not fobj:
continue
load_errors = []
err =None
# We have successfully found and opened the file. Now actually
# try to decode it using the given protocol.
try:
@ -208,6 +209,8 @@ def read_batchfile(pythonpath, file_ending='.py'):
continue
# if we get here, the encoding worked. Stop iteration.
break
if load_errors:
logger.log_errmsg("\n".join(load_errors))
if err:
return err
else:

View file

@ -104,8 +104,8 @@ def reload_modules():
if unsafe_dir_modified or unsafe_mod_modified:
if unsafe_mod_modified:
string += "\n {rModules containing Script classes with a timer component"
string += "\n and which has already spawned instances cannot be reloaded safely.{n"
string += "\n {rModules containing Script classes with a timer component{n"
string += "\n {rand which has already spawned instances cannot be reloaded safely.{n"
string += "\n {rThese module(s) can only be reloaded by server reboot:{n\n %s\n"
string = string % ", ".join(unsafe_dir_modified + unsafe_mod_modified)